public WaveRecorder(int deviceIndex, double sampleRate, int framesPerBuffer, AudioBufferAvailableDelegate bufferAvailable) { this._bufferAvailable = bufferAvailable; PaStreamParameters inputParameters = new PaStreamParameters(); inputParameters.device = deviceIndex; inputParameters.channelCount = 2; inputParameters.suggestedLatency = 0.0; inputParameters.sampleFormat = PaSampleFormat.PaFloat32; PaError paError1 = PortAudioAPI.Pa_IsFormatSupported(ref inputParameters, IntPtr.Zero, sampleRate); if (paError1 != PaError.paNoError) throw new ApplicationException(paError1.ToString()); this._gcHandle = GCHandle.Alloc((object) this); PaError paError2 = PortAudioAPI.Pa_OpenStream(out this._streamHandle, ref inputParameters, IntPtr.Zero, sampleRate, (uint) framesPerBuffer, PaStreamFlags.PaNoFlag, this._paCallback, (IntPtr) this._gcHandle); if (paError2 != PaError.paNoError) { this._gcHandle.Free(); throw new ApplicationException(paError2.ToString()); } PaError paError3 = PortAudioAPI.Pa_StartStream(this._streamHandle); if (paError3 != PaError.paNoError) { int num = (int) PortAudioAPI.Pa_CloseStream(this._streamHandle); this._gcHandle.Free(); throw new ApplicationException(paError3.ToString()); } }
public static extern PaError Pa_OpenStream( out IntPtr stream, IntPtr inputParameters, ref PaStreamParameters outputParameters, double sampleRate, uint framesPerBuffer, PaStreamFlags streamFlags, PaStreamCallbackDelegate streamCallback, IntPtr userData);
public WaveRecorder(int deviceIndex, double sampleRate, int framesPerBuffer, AudioBufferAvailableDelegate bufferAvailable) { _bufferAvailable = bufferAvailable; var inputParams = new PaStreamParameters(); inputParams.device = deviceIndex; inputParams.channelCount = 2; inputParams.suggestedLatency = 0; inputParams.sampleFormat = PaSampleFormat.PaFloat32; var pe = PortAudioAPI.Pa_IsFormatSupported(ref inputParams, IntPtr.Zero, sampleRate); if (pe != PaError.paNoError) { throw new ApplicationException(pe.ToString()); } _gcHandle = GCHandle.Alloc(this); pe = PortAudioAPI.Pa_OpenStream( out _streamHandle, ref inputParams, IntPtr.Zero, sampleRate, (uint) framesPerBuffer, PaStreamFlags.PaNoFlag, _paCallback, (IntPtr) _gcHandle); if (pe != PaError.paNoError) { _gcHandle.Free(); throw new ApplicationException(pe.ToString()); } pe = PortAudioAPI.Pa_StartStream(_streamHandle); if (pe != PaError.paNoError) { PortAudioAPI.Pa_CloseStream(_streamHandle); _gcHandle.Free(); throw new ApplicationException(pe.ToString()); } }
public static extern PaError Pa_IsFormatSupported( ref PaStreamParameters inputParameters, ref PaStreamParameters outputParameters, double sampleRate);
public static PaError Pa_OpenStream( out IntPtr stream, ref PaStreamParameters? inputParameters, ref PaStreamParameters? outputParameters, double sampleRate, uint framesPerBuffer, PaStreamFlags streamFlags, PaStreamCallbackDelegate streamCallback, IntPtr userData) { IntPtr inputParametersPtr; if (inputParameters != null) { inputParametersPtr = Marshal.AllocHGlobal(Marshal.SizeOf(inputParameters.Value)); Marshal.StructureToPtr(inputParameters.Value, inputParametersPtr, true); } else { inputParametersPtr = IntPtr.Zero; } IntPtr outputParametersPtr; if (outputParameters != null) { outputParametersPtr = Marshal.AllocHGlobal(Marshal.SizeOf(outputParameters.Value)); Marshal.StructureToPtr(outputParameters.Value, outputParametersPtr, true); } else { outputParametersPtr = IntPtr.Zero; } return Pa_OpenStream(out stream, inputParametersPtr, outputParametersPtr, sampleRate, framesPerBuffer, streamFlags, streamCallback, userData); }