public OutBuffer(IntPtr WaveOut, WAVEFORMATEX Format, int Count) : base(Format, Count) { waveOut = WaveOut; MmException.CheckThrow(Winmm.waveOutPrepareHeader(WaveOut, header, Marshal.SizeOf(header))); header.dwFlags |= WaveHdrFlags.WHDR_DONE; }
private static int BlockAlignedSize(WAVEFORMATEX Format, int Count) { int align = Format.nBlockAlign; int size = Count * Format.wBitsPerSample / 8; return(size + (align - (size % align)) % align); }
public OutBuffer(IntPtr WaveOut, WAVEFORMATEX Format, int Count) : base(Format, Count) { waveOut = WaveOut; MmException.CheckThrow(Winmm.waveOutPrepareHeader(WaveOut, ref header, Marshal.SizeOf(header))); header.dwFlags |= WaveHdrFlags.WHDR_DONE; }
private static void ConvertSamples(IntPtr In, IntPtr Out, WAVEFORMATEX Format, int Count) { switch (Format.wBitsPerSample) { case 16: Audio.Util.LEf64ToLEi16(In, Out, Count); break; case 32: Audio.Util.LEf64ToLEi32(In, Out, Count); break; default: throw new NotImplementedException("Unsupported sample type."); } }
public WaveOut(int Device, WAVEFORMATEX Format, int BufferSize) { Log.Global.WriteLine(MessageType.Info, "Opening wave out device '{0}'.", Device); // Construct waveOut MmException.CheckThrow(Winmm.waveOutOpen(out waveOut, Device, ref Format, callback.SafeWaitHandle.DangerousGetHandle(), IntPtr.Zero, WaveOutOpenFlags.CALLBACK_NULL)); // Create buffers. buffers = new List<OutBuffer>(); for (int i = 0; i < 4; ++i) buffers.Add(new OutBuffer(waveOut, Format, BufferSize)); }
public WaveOut(int Device, WAVEFORMATEX Format, int BufferSize) { Log.Global.WriteLine(MessageType.Info, "Opening wave out device '{0}'.", Device); // Construct waveOut MmException.CheckThrow(Winmm.waveOutOpen(out waveOut, Device, ref Format, callback.SafeWaitHandle.DangerousGetHandle(), IntPtr.Zero, WaveOutOpenFlags.CALLBACK_NULL)); // Create buffers. buffers = new List <OutBuffer>(); for (int i = 0; i < 4; ++i) { buffers.Add(new OutBuffer(waveOut, Format, BufferSize)); } }
public Buffer(WAVEFORMATEX Format, int Count) { handle = GCHandle.Alloc(this); size = BlockAlignedSize(Format, Count); samples = new Audio.SampleBuffer(Count) { Tag = this }; header = new WAVEHDR(); header.lpData = Marshal.AllocHGlobal(size); header.dwUser = (IntPtr)handle; header.dwBufferLength = (uint)size; header.dwFlags = 0; pin = GCHandle.Alloc(header, GCHandleType.Pinned); }
public Stream(SampleHandler SampleCallback, Channel[] Input, Channel[] Output, double Latency) : base(Input, Output) { callback = SampleCallback; int Rate = 48000; int Bits = 16; int Channels = 1; format = new WAVEFORMATEX(Rate, Bits, Channels); buffer = (int)Math.Ceiling(Latency / 2 * Rate * Channels); waveIn = Input.Select(i => new WaveIn(i.Device, format, buffer)).ToArray(); waveOut = Output.Select(i => new WaveOut(i.Device, format, buffer)).ToArray(); proc = new Thread(new ThreadStart(Proc)); proc.Start(); }
public Buffer(WAVEFORMATEX Format, int Count) { samples = new Audio.SampleBuffer(Count) { Tag = this }; int size = BlockAlignedSize(Format, Count); data = new byte[size]; dataPin = GCHandle.Alloc(data, GCHandleType.Pinned); header = new WAVEHDR(); headerPin = GCHandle.Alloc(header, GCHandleType.Pinned); header.lpData = dataPin.AddrOfPinnedObject(); header.dwBufferLength = (uint)size; header.dwFlags = 0; }
public WaveIn(int Device, WAVEFORMATEX Format, int BufferSize) { Log.Global.WriteLine(MessageType.Info, "Opening wave in device '{0}'.", Device); // Construct waveIn MmException.CheckThrow(Winmm.waveInOpen(out waveIn, Device, ref Format, IntPtr.Zero, IntPtr.Zero, WaveInOpenFlags.CALLBACK_NULL)); // Create buffers. buffers = new List <InBuffer>(); for (int i = 0; i < 4; ++i) { InBuffer b = new InBuffer(waveIn, Format, BufferSize); b.Record(); buffers.Add(b); } MmException.CheckThrow(Winmm.waveInStart(waveIn)); }
public WaveIn(int Device, WAVEFORMATEX Format, int BufferSize) { Log.Global.WriteLine(MessageType.Info, "Opening wave in device '{0}'.", Device); // Construct waveIn MmException.CheckThrow(Winmm.waveInOpen(out waveIn, Device, ref Format, callback.SafeWaitHandle.DangerousGetHandle(), IntPtr.Zero, WaveInOpenFlags.CALLBACK_EVENT)); // Create buffers. buffers = new List<InBuffer>(); for (int i = 0; i < 4; ++i) { InBuffer b = new InBuffer(waveIn, Format, BufferSize); b.Record(); buffers.Add(b); } MmException.CheckThrow(Winmm.waveInStart(waveIn)); }
public static extern MMRESULT waveOutOpen(out IntPtr hWaveOut, int uDeviceID, ref WAVEFORMATEX lpFormat, IntPtr dwCallback, IntPtr dwInstance, WaveOutOpenFlags dwFlags);
public InBuffer(IntPtr WaveIn, WAVEFORMATEX Format, int Count) : base(Format, Count) { waveIn = WaveIn; MmException.CheckThrow(Winmm.waveInPrepareHeader(waveIn, ref header, Marshal.SizeOf(header))); }
public static extern MMRESULT waveInOpen(out IntPtr phwi, int uDeviceID, ref WAVEFORMATEX lpFormat, IntPtr dwCallback, IntPtr dwInstance, WaveInOpenFlags dwFlags);
private static int BlockAlignedSize(WAVEFORMATEX Format, int Count) { int align = Format.nBlockAlign; int size = Count * Format.wBitsPerSample / 8; return size + (align - (size % align)) % align; }