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

            if (paError != 0)
            {
                throw new ApplicationException(paError.ToString());
            }
            this._gcHandle = GCHandle.Alloc(this);
            paError        = PortAudioAPI.Pa_OpenStream(out this._streamHandle, IntPtr.Zero, 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 WavePlayer(int deviceIndex, double sampleRate, int framesPerBuffer, AudioBufferNeededDelegate bufferNeededDelegate)
 {
     this._bufferNeeded = bufferNeededDelegate;
       PaStreamParameters outputParameters = new PaStreamParameters();
       outputParameters.device = deviceIndex;
       outputParameters.channelCount = 2;
       outputParameters.suggestedLatency = 0.0;
       outputParameters.sampleFormat = PaSampleFormat.PaFloat32;
       PaError paError1 = PortAudioAPI.Pa_IsFormatSupported(IntPtr.Zero, ref outputParameters, sampleRate);
       if (paError1 != PaError.paNoError)
     throw new ApplicationException(paError1.ToString());
       this._gcHandle = GCHandle.Alloc((object) this);
       PaError paError2 = PortAudioAPI.Pa_OpenStream(out this._streamHandle, IntPtr.Zero, ref outputParameters, 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());
       }
 }
Exemplo n.º 3
0
        public WavePlayer(int deviceIndex, double sampleRate, int framesPerBuffer, AudioBufferNeededDelegate bufferNeededDelegate)
        {
            _bufferNeeded = bufferNeededDelegate;

            var ouputParams = new PaStreamParameters();

            ouputParams.device           = deviceIndex;
            ouputParams.channelCount     = 2;
            ouputParams.suggestedLatency = 0;
            ouputParams.sampleFormat     = PaSampleFormat.PaFloat32;

            var pe = PortAudioAPI.Pa_IsFormatSupported(IntPtr.Zero, ref ouputParams, sampleRate);

            if (pe != PaError.paNoError)
            {
                throw new ApplicationException(pe.ToString());
            }

            _gcHandle = GCHandle.Alloc(this);

            pe = PortAudioAPI.Pa_OpenStream(
                out _streamHandle,
                IntPtr.Zero,
                ref ouputParams,
                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());
            }
        }
Exemplo n.º 4
0
        public WavePlayer(int deviceIndex, double sampleRate, int framesPerBuffer, AudioBufferNeededDelegate bufferNeededDelegate)
        {
            _bufferNeeded = bufferNeededDelegate;

            var ouputParams = new PaStreamParameters();
            ouputParams.device = deviceIndex;
            ouputParams.channelCount = 2;
            ouputParams.suggestedLatency = 0;
            ouputParams.sampleFormat = PaSampleFormat.PaFloat32;

            var pe = PortAudioAPI.Pa_IsFormatSupported(IntPtr.Zero, ref ouputParams, sampleRate);
            if (pe != PaError.paNoError)
            {
                throw new ApplicationException(pe.ToString());
            }

            _gcHandle = GCHandle.Alloc(this);

            pe = PortAudioAPI.Pa_OpenStream(
                out _streamHandle,
                IntPtr.Zero,
                ref ouputParams,
                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());
            }
        }