Exemplo n.º 1
0
        public unsafe WaveDuplex(int deviceIndex, double sampleRate, int framesPerBuffer, AudioBufferAvailableDelegate bufferNeededDelegate)
        {
            this._bufferAvailable = bufferNeededDelegate;
            PaStreamParameters paStreamParameters = new PaStreamParameters
            {
                device           = deviceIndex,
                channelCount     = 2,
                suggestedLatency = 0.0,
                sampleFormat     = PaSampleFormat.PaFloat32
            };
            PaError paError = PortAudioAPI.Pa_IsFormatSupported(ref paStreamParameters, ref paStreamParameters, sampleRate);

            if (paError != 0)
            {
                throw new ApplicationException(paError.ToString());
            }
            this._gcHandle = GCHandle.Alloc(this);
            paError        = PortAudioAPI.Pa_OpenStream(out this._streamHandle, ref paStreamParameters, ref paStreamParameters, sampleRate, (uint)framesPerBuffer, PaStreamFlags.PaNoFlag, this._paCallback, (IntPtr)this._gcHandle);
            if (paError != 0)
            {
                this._gcHandle.Free();
                throw new ApplicationException(paError.ToString());
            }
            paError = PortAudioAPI.Pa_StartStream(this._streamHandle);
            if (paError == PaError.paNoError)
            {
                return;
            }
            PortAudioAPI.Pa_CloseStream(this._streamHandle);
            this._gcHandle.Free();
            throw new ApplicationException(paError.ToString());
        }
Exemplo n.º 2
0
 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 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 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());
            }
        }