Esempio n. 1
0
        private unsafe static PaStreamCallbackResult PaStreamCallback(float *input, float *output, uint frameCount, ref PaStreamCallbackTimeInfo timeInfo, PaStreamCallbackFlags statusFlags, IntPtr userData)
        {
            GCHandle gCHandle = GCHandle.FromIntPtr(userData);

            if (!gCHandle.IsAllocated)
            {
                return(PaStreamCallbackResult.PaAbort);
            }
            WaveDuplex waveDuplex = (WaveDuplex)gCHandle.Target;

            try
            {
                Utils.Memcpy(output, input, (int)(frameCount * 2 * 4));
                if (waveDuplex._bufferAvailable != null)
                {
                    waveDuplex._bufferAvailable(output, (int)frameCount);
                }
            }
            catch
            {
                return(PaStreamCallbackResult.PaAbort);
            }
            return(PaStreamCallbackResult.PaContinue);
        }
Esempio n. 2
0
 public void Stop()
 {
     if (this._inputType == StreamControl.InputType.Plugin && this._frontend != null)
       {
     this._frontend.Stop();
     this._frontend = (IFrontendController) null;
       }
       if (this._wavePlayer != null)
       {
     this._wavePlayer.Dispose();
     this._wavePlayer = (WavePlayer) null;
       }
       if (this._waveRecorder != null)
       {
     this._waveRecorder.Dispose();
     this._waveRecorder = (WaveRecorder) null;
       }
       if (this._waveDuplex != null)
       {
     this._waveDuplex.Dispose();
     this._waveDuplex = (WaveDuplex) null;
       }
       this._inputSampleRate = 0.0;
       if (this._iqStream != null)
     this._iqStream.Close();
       if (this._waveReadThread != null)
       {
     this._waveReadThread.Join();
     this._waveReadThread = (Thread) null;
       }
       if (this._audioStream != null)
     this._audioStream.Close();
       if (this._dspThread != null)
       {
     this._dspThread.Join();
     this._dspThread = (Thread) null;
       }
       if (this._waveFile != null)
       {
     this._waveFile.Dispose();
     this._waveFile = (WaveFile) null;
       }
       if (this._iqStream != null)
       {
     this._iqStream.Dispose();
     this._iqStream = (ComplexFifoStream) null;
       }
       this._audioStream = (FloatFifoStream) null;
       this._dspOutBuffer = (UnsafeBuffer) null;
       this._iqInBuffer = (UnsafeBuffer) null;
 }
Esempio n. 3
0
 public void Play()
 {
     if (this._wavePlayer != null || this._waveDuplex != null)
     return;
       switch (this._inputType)
       {
     case StreamControl.InputType.SoundCard:
       if (this._inputDevice == this._outputDevice)
       {
     this._waveDuplex = new WaveDuplex(this._inputDevice, this._inputSampleRate, this._inputBufferSize, new AudioBufferAvailableDelegate(this.DuplexFiller));
     break;
       }
       this._iqStream = new ComplexFifoStream(BlockMode.BlockingRead);
       this._audioStream = new FloatFifoStream(BlockMode.BlockingWrite, this._outputBufferSize);
       this._waveRecorder = new WaveRecorder(this._inputDevice, this._inputSampleRate, this._inputBufferSize, new AudioBufferAvailableDelegate(this.RecorderFiller));
       this._wavePlayer = new WavePlayer(this._outputDevice, this._outputSampleRate, this._outputBufferSize / 2, new AudioBufferNeededDelegate(this.PlayerFiller));
       this._dspThread = new Thread(new ThreadStart(this.DSPProc));
       this._dspThread.Start();
       break;
     case StreamControl.InputType.Plugin:
       this._iqStream = new ComplexFifoStream(BlockMode.BlockingReadWrite, this._inputBufferSize * 4);
       this._audioStream = new FloatFifoStream(BlockMode.BlockingWrite, this._outputBufferSize);
       this._wavePlayer = new WavePlayer(this._outputDevice, this._outputSampleRate, this._outputBufferSize / 2, new AudioBufferNeededDelegate(this.PlayerFiller));
       this._frontend.Start(new SamplesAvailableDelegate(this.FrontendFiller));
       this._dspThread = new Thread(new ThreadStart(this.DSPProc));
       this._dspThread.Start();
       break;
     case StreamControl.InputType.WaveFile:
       this._iqStream = new ComplexFifoStream(BlockMode.BlockingReadWrite, this._inputBufferSize * 4);
       this._audioStream = new FloatFifoStream(BlockMode.BlockingWrite, this._outputBufferSize);
       this._wavePlayer = new WavePlayer(this._outputDevice, this._outputSampleRate, this._outputBufferSize / 2, new AudioBufferNeededDelegate(this.PlayerFiller));
       this._waveReadThread = new Thread(new ThreadStart(this.WaveFileFiller));
       this._waveReadThread.Start();
       this._dspThread = new Thread(new ThreadStart(this.DSPProc));
       this._dspThread.Start();
       break;
       }
 }
Esempio n. 4
0
        public void Play()
        {
            if (_wavePlayer != null || _waveDuplex != null)
            {
                return;
            }

            #region Stream Hooks 
            
            if (_streamHookManager != null)
            {               
                _streamHookManager.InitStreams(_inputBufferSize, _outputBufferSize);
                                
                if (_streamHookManager.HaveIqObservers)
                {
                    _streamHookManager.StartIQObserverThread(_inputBufferSize);
                }

                _streamHookManager.OutputSampleRate = _outputSampleRate;
                _streamHookManager.InputSampleRate = _inputSampleRate;
            }

            #endregion

            switch (_inputType)
            {
                case InputType.SoundCard:
                    if (_inputDevice == _outputDevice)
                    {
                        _waveDuplex = new WaveDuplex(_inputDevice, _inputSampleRate, _inputBufferSize, DuplexFiller);
                    }
                    else
                    {
                        _iqStream = new ComplexFifoStream(BlockMode.BlockingRead);
                        _audioStream = _streamHookManager == null ? new FloatFifoStream(BlockMode.BlockingWrite, _outputBufferSize) : _streamHookManager.FirstAudioStream;
                        _waveRecorder = new WaveRecorder(_inputDevice, _inputSampleRate, _inputBufferSize, RecorderFiller);
                        _wavePlayer = new WavePlayer(_outputDevice, _outputSampleRate, _outputBufferSize / 2, PlayerFiller);
                        _dspThread = new Thread(DSPProc);
                        _dspThread.Start();
                    }
                    break;

                case InputType.WaveFile:
                    _iqStream = new ComplexFifoStream(BlockMode.BlockingRead);
                    _audioStream = _streamHookManager == null ? new FloatFifoStream(BlockMode.BlockingWrite, _outputBufferSize) : _streamHookManager.FirstAudioStream;
                    _wavePlayer = new WavePlayer(_outputDevice, _outputSampleRate, _outputBufferSize / 2, PlayerFiller);
                    _waveReadThread = new Thread(WaveFileFiller);
                    _waveReadThread.Start();
                    _dspThread = new Thread(DSPProc);
                    _dspThread.Start();
                    break;

                case InputType.Plugin:
                    _iqStream = new ComplexFifoStream(BlockMode.BlockingRead);
                    _audioStream = _streamHookManager == null ? new FloatFifoStream(BlockMode.BlockingWrite, _outputBufferSize) : _streamHookManager.FirstAudioStream;
                    _wavePlayer = new WavePlayer(_outputDevice, _outputSampleRate, _outputBufferSize / 2, PlayerFiller);
                    _frontend.Start(FrontendFiller);
                    _dspThread = new Thread(DSPProc);
                    _dspThread.Start();
                    break;
            }

            if (_streamHookManager != null)
            {
                _streamHookManager.Start();
            }
        }
Esempio n. 5
0
 public void Stop()
 {
     if (_inputType == InputType.Plugin && _frontend != null)
     {
         _frontend.Stop();
         _frontend = null;
     }
     if (_wavePlayer != null)
     {
         _wavePlayer.Dispose();
         _wavePlayer = null;
     }
     if (_waveRecorder != null)
     {
         _waveRecorder.Dispose();
         _waveRecorder = null;
     }
     if (_waveDuplex != null)
     {
         _waveDuplex.Dispose();
         _waveDuplex = null;
     }
     _inputSampleRate = 0;
     if (_waveReadThread != null)
     {
         _waveReadThread.Join();
         _waveReadThread = null;
     }
     if (_iqStream != null)
     {
         _iqStream.Close();
     }
     if (_audioStream != null)
     {
         _audioStream.Close();
     }
     if (_streamHookManager != null)
     {
         _streamHookManager.CloseStreams();
         _streamHookManager.Stop();                
     }
     if (_dspThread != null)
     {
         _dspThread.Join();
         _dspThread = null;
     }
     if (_streamHookManager != null)
     {
         _streamHookManager.StopIQObserverThread();
     }
     if (_waveFile != null)
     {
         _waveFile.Dispose();
         _waveFile = null;
     }
     if (_iqStream != null)
     {
         _iqStream.Dispose();
         _iqStream = null;
     }           
     if (_streamHookManager != null)
     {
         _streamHookManager.DisposeStreams();                
     }
     _audioStream = null;
     _dspOutBuffer = null;
     _iqInBuffer = null;
 }
        public void Play()
        {
            if (_wavePlayer != null || _waveDuplex != null)
            {
                return;
            }

            switch (_inputType)
            {
                case InputType.SoundCard:
                    if (_inputDevice == _outputDevice)
                    {
                        _waveDuplex = new WaveDuplex(_inputDevice, _inputSampleRate, _inputBufferSize, DuplexFiller);
                    }
                    else
                    {
                        _iqStream = new ComplexFifoStream(BlockMode.BlockingRead);
                        _audioStream = new FloatFifoStream(BlockMode.BlockingWrite, _outputBufferSize);
                        _waveRecorder = new WaveRecorder(_inputDevice, _inputSampleRate, _inputBufferSize, RecorderFiller);
                        _wavePlayer = new WavePlayer(_outputDevice, _outputSampleRate, _outputBufferSize / 2, PlayerFiller);
                        _dspThread = new Thread(DSPProc);
                        _dspThread.Start();
                    }
                    break;

                case InputType.WaveFile:
                    _iqStream = new ComplexFifoStream(BlockMode.BlockingRead);
                    _audioStream = new FloatFifoStream(BlockMode.BlockingWrite, _outputBufferSize);
                    _wavePlayer = new WavePlayer(_outputDevice, _outputSampleRate, _outputBufferSize / 2, PlayerFiller);
                    _waveReadThread = new Thread(WaveFileFiller);
                    _waveReadThread.Start();
                    _dspThread = new Thread(DSPProc);
                    _dspThread.Start();
                    break;

                case InputType.Plugin:
                    _iqStream = new ComplexFifoStream(BlockMode.BlockingRead);
                    _audioStream = new FloatFifoStream(BlockMode.BlockingWrite, _outputBufferSize);
                    _wavePlayer = new WavePlayer(_outputDevice, _outputSampleRate, _outputBufferSize / 2, PlayerFiller);
                    _frontend.Start(FrontendFiller);
                    _dspThread = new Thread(DSPProc);
                    _dspThread.Start();
                    break;
            }
        }