Exemplo n.º 1
0
        private void ReadHeader()
        {
            BinaryReader binaryReader = new BinaryReader(this._stream);

            if (WaveFile.ReadChunk(binaryReader) != "RIFF")
            {
                throw new Exception("Invalid file format");
            }
            int num = binaryReader.ReadInt32();

            if (WaveFile.ReadChunk(binaryReader) != "WAVE")
            {
                throw new Exception("Invalid file format");
            }
            if (WaveFile.ReadChunk(binaryReader) != "fmt ")
            {
                throw new Exception("Invalid file format");
            }
            num = binaryReader.ReadInt32();
            if (num < 16)
            {
                throw new Exception("Invalid file format");
            }
            this._formatTag = binaryReader.ReadInt16();
            this._isPCM     = (this._formatTag == 1);
            short num2 = binaryReader.ReadInt16();

            if (num2 != 2)
            {
                throw new Exception("Invalid file format");
            }
            this._sampleRate     = binaryReader.ReadInt32();
            this._avgBytesPerSec = binaryReader.ReadInt32();
            this._blockAlign     = binaryReader.ReadInt16();
            this._bitsPerSample  = binaryReader.ReadInt16();
            for (num -= 16; num > 0; num--)
            {
                binaryReader.ReadByte();
            }
            string text = "";

            while (this._stream.Position < this._stream.Length)
            {
                text = WaveFile.ReadChunk(binaryReader);
                if (text == "data")
                {
                    break;
                }
                num = binaryReader.ReadInt32();
                while (this._stream.Position < this._stream.Length && num > 0)
                {
                    binaryReader.ReadByte();
                    num--;
                }
            }
            if (this._stream.Position >= this._stream.Length)
            {
                throw new Exception("Invalid file format");
            }
            this._size    = binaryReader.ReadInt32();
            this._dataPos = this._stream.Position;
            int num3 = num2 * this._sampleRate * this._bitsPerSample / 8;

            this._duration = this._size / num3;
        }
Exemplo 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;
 }
Exemplo n.º 3
0
        public void OpenFile(string filename, int outputDevice, int bufferSizeInMs)
        {
            Stop();

            try
            {
                _inputType = InputType.WaveFile;
                _waveFile = new WaveFile(filename);
                _outputDevice = outputDevice;
                _bufferSizeInMs = bufferSizeInMs;
                _inputSampleRate = _waveFile.SampleRate;
                _inputBufferSize = (int) (_bufferSizeInMs * _inputSampleRate / 1000);

                _decimationStageCount = GetDecimationStageCount();

                var decimationFactor = (int) Math.Pow(2.0, _decimationStageCount);
                _inputBufferSize = _inputBufferSize / decimationFactor * decimationFactor;
                _inputBufferSize = _inputBufferSize / _processorCount * _processorCount;
                _bufferSizeInMs = (int) Math.Round(_inputBufferSize / _inputSampleRate * 1000);
                _outputSampleRate = _inputSampleRate / decimationFactor;
                _outputBufferSize = _inputBufferSize / decimationFactor * 2;
            }
            catch
            {
                Stop();
                throw;
            }
        }
Exemplo n.º 4
0
 public void OpenFile(string filename, int outputDevice, int bufferSizeInMs)
 {
     this.Stop();
       try
       {
     this._inputType = StreamControl.InputType.WaveFile;
     this._waveFile = new WaveFile(filename);
     this._outputDevice = outputDevice;
     this._bufferSizeInMs = bufferSizeInMs;
     this._inputSampleRate = (double) this._waveFile.SampleRate;
     this._inputBufferSize = (int) ((double) this._bufferSizeInMs * this._inputSampleRate / 1000.0);
     this._decimationStageCount = this.GetDecimationStageCount();
     int num = (int) Math.Pow(2.0, (double) this._decimationStageCount);
     this._inputBufferSize = this._inputBufferSize / num * num;
     this._inputBufferSize = this._inputBufferSize / StreamControl._processorCount * StreamControl._processorCount;
     this._bufferSizeInMs = (int) Math.Round((double) this._inputBufferSize / this._inputSampleRate * 1000.0);
     this._outputSampleRate = this._inputSampleRate / (double) num;
     this._outputBufferSize = this._inputBufferSize / num * 2;
       }
       catch
       {
     this.Stop();
     throw;
       }
 }
Exemplo 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;
 }