public static AudioEvent CreateInstance(IntPtr data, int dataLength, double timeStamp, WAVEFORMATEX wfx) { if (data == IntPtr.Zero || dataLength < 1) throw new ArgumentException("data is null or empty"); AudioEvent anEvent = new AudioEvent(data, dataLength, timeStamp, wfx); return anEvent; }
private AudioEvent(IntPtr data, int dataLength, double timeStamp, WAVEFORMATEX wfx) { DataBuffer = new byte[dataLength]; DataLength = dataLength; SampleTime = timeStamp; WaveFormat = wfx; //copy the data to the byte buffer Marshal.Copy(data, DataBuffer, 0, dataLength); }
public WaveOutputPort(int deviceID, WAVEFORMATEX wf) { fCallbackMethod = new WaveCallback(this.DefaultAudioCallback); DeviceHandle = null; DeviceID = deviceID; WaveFormat = wf; PCMFormat = PCMAudioFormat.CreateFromWaveFormat(wf); Open(); }
public static double GetAmplitudeRange(WAVEFORMATEX wfx) { double maxRange = 0; if (16 == wfx.wBitsPerSample) maxRange = short.MaxValue/2; if (8 == wfx.wBitsPerSample) maxRange = byte.MaxValue/2; return maxRange; }
public WinMMAudioDevice(int deviceID, WAVEFORMATEX wf) { fCallbackMethod = new WaveCallback(this.DefaultAudioCallback); fDeviceHandle = IntPtr.Zero; fDeviceID = deviceID; fWaveFormat = wf; fPCMFormat = PCMAudioFormat.CreateFromWaveFormat(wf); //if (callbackProc != null) // fCallbackProcedure = callbackProc; //else // fCallbackProcedure = DefaultAudioCallback; }
public static WAVEFORMATEX CreatePCMFormat(int channels, int sampleRate, int bitsPerSample) { int bytesPerSample = bitsPerSample / 8; WAVEFORMATEX wfx = new WAVEFORMATEX(); wfx.wFormatTag = WAVEFORMAT.WAVE_FORMAT_PCM; wfx.nChannels = (short)channels; wfx.wBitsPerSample = (ushort)bitsPerSample; // 8 or 16 wfx.nSamplesPerSec = (ushort)sampleRate; wfx.nAvgBytesPerSec = (int)(sampleRate * channels * bytesPerSample); wfx.nBlockAlign = (short)(channels * bytesPerSample); wfx.cbSize = 0; return wfx; }
public WaveInputPort(int deviceID, WAVEFORMATEX wf, double latency) :this(deviceID, wf.nChannels, wf.nSamplesPerSec, wf.wBitsPerSample, latency) { }
public static PCMAudioFormat CreateFromWaveFormat(WAVEFORMATEX wfx) { PCMAudioFormat af = new PCMAudioFormat(wfx.nChannels, wfx.wBitsPerSample, (int)wfx.nSamplesPerSec); return af; }
public static extern int SendMessageW([In] IntPtr hWnd, int Msg, uint wParam, ref WAVEFORMATEX waveFormat);
public int capGetAudioFormat(ref WAVEFORMATEX s, int wSize) { int retValue = SendMessageW(fWindowHandle, Vfw.WM_CAP_GET_AUDIOFORMAT, (uint)wSize, ref s); return retValue; }
public bool capSetAudioFormat(ref WAVEFORMATEX s, int wSize) { return 1 == SendMessageW(fWindowHandle, Vfw.WM_CAP_SET_AUDIOFORMAT, (uint)wSize, ref s); }