Ejemplo n.º 1
0
        private void OnBufferNeeded(object sender, EventArgs e)
        {
            Array.Clear(_buffer, 0, _buffer.Length);
            var available = _audioSampleProvider != null?_audioSampleProvider.Read(_buffer, _buffer.Length) : 0;

            _dsei.SubmitBuffer(_buffer, available);
        }
Ejemplo n.º 2
0
 public void FillWith(IAudioSampleProvider audioSampleProvider)
 {
     Array.Clear(_samples, 0, _samples.Length);
     audioSampleProvider.Read(_samples, _samples.Length);
     _dataStream.Position = 0;
     _dataStream.Write(_samples, 0, _samples.Length);
 }
Ejemplo n.º 3
0
 public void FillWith(IAudioSampleProvider audioSampleProvider)
 {
     Array.Clear(_samples, 0, _samples.Length);
     audioSampleProvider.Read(_samples, _samples.Length);
     _dataStream.Position = 0;
     _dataStream.Write(_samples, 0, _samples.Length);
 }
Ejemplo n.º 4
0
        public int ReadBuffer(short[] samples, int numSamples)
        {
            var buffer         = new byte[numSamples * 2];
            var numBytes       = _audioSampleProvider.Read(buffer, buffer.Length);
            var numSamplesRead = numBytes / 2;

            for (int i = 0; i < numSamplesRead; i++)
            {
                samples[i] = buffer.ToInt16(i * 2);
            }
            return(numSamplesRead);
        }
Ejemplo n.º 5
0
        public int Read(byte[] samples, int count)
        {
            var numSamples = count / 2;
            var monoBuffer = new byte[numSamples];
            var numBytes   = _audioSampleProvider.Read(monoBuffer, numSamples);
            int offs       = 0;

            for (int i = 0; i < numBytes; i += 2)
            {
                var value = monoBuffer.ToInt16(i);
                samples.WriteInt16(offs += 2, value);
                samples.WriteInt16(offs += 2, value);
            }
            return(numBytes * 2);
        }
Ejemplo n.º 6
0
        void WriteJob()
        {
            _state = AudioOutputState.Playing;
            var data = new byte[_audioSampleProvider.AudioFormat.AverageBytesPerSecond];

            while (_state == AudioOutputState.Playing)
            {
                Array.Clear(data, 0, data.Length);
                var bytesRead = _audioSampleProvider.Read(data, data.Length);
                //if (bytesRead != 0)
                {
                    _writer.Write(data, 0, bytesRead);
                    _dataChunkSize += bytesRead;
                }
            }

            UpdateHeader();
        }