Exemplo n.º 1
0
        public unsafe void Play()
        {
            if (this._wavePlayer == null && this._waveDuplex == null)
            {
                this._isPlaying = true;
                try
                {
                    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._iqCircularBuffer    = new ComplexCircularBuffer(this._inputBufferSize, 6);
                            this._audioCircularBuffer = new FloatCircularBuffer(this._outputBufferSize, 2);
                            this._waveRecorder        = new WaveRecorder(this._inputDevice, this._inputSampleRate, this._inputBufferSize, this.RecorderFiller);
                            this._wavePlayer          = new WavePlayer(this._outputDevice, this._outputSampleRate, this._outputBufferSize / 2, this.PlayerFiller);
                            this._dspThread           = new Thread(this.DSPProc);
                            this._dspThread.Start();
                        }
                        break;

                    case InputType.WaveFile:
                        this._iqCircularBuffer    = new ComplexCircularBuffer(this._inputBufferSize, 6);
                        this._audioCircularBuffer = new FloatCircularBuffer(this._outputBufferSize, 2);
                        this._wavePlayer          = new WavePlayer(this._outputDevice, this._outputSampleRate, this._outputBufferSize / 2, 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._iqCircularBuffer    = new ComplexCircularBuffer(this._inputBufferSize, 6);
                        this._audioCircularBuffer = new FloatCircularBuffer(this._outputBufferSize, 2);
                        this._wavePlayer          = new WavePlayer(this._outputDevice, this._outputSampleRate, this._outputBufferSize / 2, this.PlayerFiller);
                        if (this._frontend is IIQStreamController)
                        {
                            ((IIQStreamController)this._frontend).Start(this.FrontendFiller);
                        }
                        this._dspThread = new Thread(this.DSPProc);
                        this._dspThread.Start();
                        break;
                    }
                    if (this._dspThread != null)
                    {
                        this._dspThread.Name = "DSP Thread";
                    }
                }
                catch
                {
                    this._isPlaying = false;
                    throw;
                }
            }
        }
Exemplo 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;
 }
Exemplo n.º 3
0
 public void Stop()
 {
     this._isPlaying = false;
     if (this._inputType == InputType.Plugin && this._frontend is IIQStreamController)
     {
         ((IIQStreamController)this._frontend).Stop();
         this._frontend = null;
     }
     if (this._iqCircularBuffer != null)
     {
         this._iqCircularBuffer.Close();
     }
     if (this._audioCircularBuffer != null)
     {
         this._audioCircularBuffer.Close();
     }
     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._dspThread != null)
     {
         this._dspThread.Join();
         this._dspThread = null;
     }
     if (this._waveFile != null)
     {
         this._waveFile.Dispose();
         this._waveFile = null;
     }
     this._iqCircularBuffer    = null;
     this._audioCircularBuffer = null;
     this._dspOutBuffer        = 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;
            }
        }
Exemplo 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();
            }
        }
Exemplo 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;
 }
Exemplo n.º 7
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;
                }
                }
            }
        }