Esempio n. 1
0
        private void InitAudioInterceptorStreams(int size)
        {
            var chainHead = new FloatFifoStream(BlockMode.BlockingWrite, size);

            lock (_audioInterceptors)
            {
                if (_audioInterceptors.Count == 0)
                {
                    _firstAudioStream = chainHead;
                    _lastAudioStream  = chainHead;
                }
                else
                {
                    var nextInputFifo = chainHead;
                    foreach (IAudioInterceptor interceptor in _audioInterceptors)
                    {
                        interceptor.Input  = nextInputFifo;
                        interceptor.Output = new FloatFifoStream(BlockMode.BlockingWrite, size);

                        interceptor.OutputBufferSize = size;

                        nextInputFifo = interceptor.Output;
                    }

                    _firstAudioStream = _audioInterceptors.First.Value.Input;
                    _lastAudioStream  = _audioInterceptors.Last.Value.Output;
                }
            }
        }
Esempio n. 2
0
 public void Stop()
 {
     if (this._inputType == InputType.Plugin && this._frontend != null)
     {
         this._frontend.Stop();
         this._frontend = null;
     }
     if (this._wavePlayer != null)
     {
         this._wavePlayer.Dispose();
         this._wavePlayer = null;
     }
     if (this._waveRecorder != null)
     {
         this._waveRecorder.Dispose();
         this._waveRecorder = null;
     }
     if (this._waveDuplex != null)
     {
         this._waveDuplex.Dispose();
         this._waveDuplex = null;
     }
     this._inputSampleRate = 0.0;
     if (this._waveReadThread != null)
     {
         this._waveReadThread.Join();
         this._waveReadThread = null;
     }
     if (this._iqStream != null)
     {
         this._iqStream.Close();
     }
     if (this._audioStream != null)
     {
         this._audioStream.Close();
     }
     if (this._dspThread != null)
     {
         this._dspThread.Join();
         this._dspThread = null;
     }
     if (this._waveFile != null)
     {
         this._waveFile.Dispose();
         this._waveFile = null;
     }
     if (this._iqStream != null)
     {
         this._iqStream.Dispose();
         this._iqStream = null;
     }
     this._audioStream  = null;
     this._dspOutBuffer = null;
     this._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;
            }
        }
Esempio n. 4
0
        private void DisposeInterceptorStreams()
        {
            if (_firstAudioStream != null)
            {
                _firstAudioStream.Dispose();
                _firstAudioStream = null;
            }

            lock (_audioInterceptors)
            {
                foreach (IAudioInterceptor interceptor in _audioInterceptors)
                {
                    if (interceptor.Output != null)
                    {
                        interceptor.Output.Dispose();
                        interceptor.Output = null;
                    }
                }
            }
        }
Esempio n. 5
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

            Utils.Log($"play() input type: {_inputType}");
            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;
            }

            Utils.Log($"_dspThread: {_dspThread.ManagedThreadId}");


            if (_streamHookManager != null)
            {
                _streamHookManager.Start();
            }
        }
Esempio n. 6
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;
 }
Esempio n. 7
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. 8
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. 9
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. 10
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;
            }
        }
Esempio n. 12
0
        private void DisposeInterceptorStreams()
        {
            if (_firstAudioStream != null)
            {
                _firstAudioStream.Dispose();
                _firstAudioStream = null;
            }

            lock (_audioInterceptors)
            {
                foreach (IAudioInterceptor interceptor in _audioInterceptors)
                {
                    if (interceptor.Output != null)
                    {
                        interceptor.Output.Dispose();
                        interceptor.Output = null;
                    }
                }
            }
        }
Esempio n. 13
0
        private void InitAudioInterceptorStreams(int size)
        {
            var chainHead = new FloatFifoStream(BlockMode.BlockingWrite, size);
            lock (_audioInterceptors)
            {
                if (_audioInterceptors.Count == 0)
                {
                    _firstAudioStream = chainHead;
                    _lastAudioStream = chainHead;                   
                }
                else
                {
                    var nextInputFifo = chainHead;
                    foreach (IAudioInterceptor interceptor in _audioInterceptors)
                    {
                        interceptor.Input = nextInputFifo;
                        interceptor.Output = new FloatFifoStream(BlockMode.BlockingWrite, size);

                        interceptor.OutputBufferSize = size;
                        
                        nextInputFifo = interceptor.Output;
                    }

                    _firstAudioStream = _audioInterceptors.First.Value.Input;
                    _lastAudioStream = _audioInterceptors.Last.Value.Output;
                }
            }
        }
Esempio n. 14
0
        public unsafe void Play()
        {
            if (this._wavePlayer == null && this._waveDuplex == null)
            {
                if (this._inputType != InputType.WaveFile)
                {
                    this._waveStart = DateTime.Now.AddYears(1);
                }
                double sampleRate      = this._outputSampleRate;
                int    framesPerBuffer = this._outputBufferSize / 2;
                if (this._soundCardRatio > 1.0)
                {
                    sampleRate      = (double)this._minOutputSampleRate;
                    framesPerBuffer = (int)((double)this._outputBufferSize / (2.0 * this._soundCardRatio));
                }
                switch (this._inputType)
                {
                case InputType.SoundCard:
                    if (this._inputDevice == this._outputDevice)
                    {
                        this._waveDuplex = new WaveDuplex(this._inputDevice, this._inputSampleRate, this._inputBufferSize, this.DuplexFiller);
                    }
                    else
                    {
                        this._iqStream = new ComplexFifoStream(BlockMode.BlockingRead);
                        ComplexFifoStream iqStream2 = this._iqStream;
                        bool read2 = false;
                        iqStream2.SetLog("_iqStream", 20000, read2, true);
                        this._audioStream = new FloatFifoStream(BlockMode.BlockingWrite, this._outputBufferSize);
                        Console.WriteLine("_audioStream created with size " + this._outputBufferSize.ToString());
                        FloatFifoStream audioStream3 = this._audioStream;
                        bool            write3       = false;
                        audioStream3.SetLog("_audioStream", this._outputBufferSize, true, write3);
                        this._waveRecorder = new WaveRecorder(this._inputDevice, this._inputSampleRate, this._inputBufferSize, this.RecorderFiller);
                        this._wavePlayer   = new WavePlayer(this._outputDevice, sampleRate, framesPerBuffer, this.PlayerFiller);
                        this._dspThread    = new Thread(this.DSPProc);
                        this._dspThread.Start();
                    }
                    break;

                case InputType.WaveFile:
                {
                    this._iqStream = new ComplexFifoStream(BlockMode.BlockingRead);
                    this._iqStream.SetLog("_iqStream", 20000, true, true);
                    this._audioStream = new FloatFifoStream(BlockMode.BlockingWrite, this._outputBufferSize * 2);
                    Console.WriteLine("_audioStream created with size " + (this._outputBufferSize * 2).ToString());
                    FloatFifoStream audioStream2 = this._audioStream;
                    bool            write2       = false;
                    audioStream2.SetLog("_audioStream", this._outputBufferSize, true, write2);
                    this._wavePlayer     = new WavePlayer(this._outputDevice, sampleRate, framesPerBuffer, this.PlayerFiller);
                    this._waveReadThread = new Thread(this.WaveFileFiller);
                    this._waveReadThread.Start();
                    this._dspThread = new Thread(this.DSPProc);
                    this._dspThread.Start();
                    break;
                }

                case InputType.Plugin:
                {
                    this._iqStream = new ComplexFifoStream(BlockMode.BlockingRead);
                    ComplexFifoStream iqStream = this._iqStream;
                    bool read = false;
                    iqStream.SetLog("_iqStream", 20000, read, true);
                    this._audioStream = new FloatFifoStream(BlockMode.BlockingWrite, this._outputBufferSize * 2);
                    Console.WriteLine("_audioStream created with size " + (this._outputBufferSize * 2).ToString());
                    FloatFifoStream audioStream = this._audioStream;
                    bool            write       = false;
                    audioStream.SetLog("_audioStream", 0, true, write);
                    this._wavePlayer = new WavePlayer(this._outputDevice, sampleRate, framesPerBuffer, this.PlayerFiller);
                    this._frontend.Start(this.FrontendFiller);
                    this._dspThread = new Thread(this.DSPProc);
                    this._dspThread.Start();
                    break;
                }
                }
            }
        }