Ejemplo n.º 1
0
 /// <summary>
 /// Implements the Read method of IWaveProvider by delegating to the abstract
 /// Read method taking a short array
 /// </summary>
 public int Read(byte[] buffer, int offset, int count)
 {
     WaveBuffer waveBuffer = new WaveBuffer(buffer);
     int samplesRequired = count / 2;
     int samplesRead = Read(waveBuffer.ShortBuffer, offset / 2, samplesRequired);
     return samplesRead * 2;
 }
        /// <summary>
        /// Reads bytes from this WaveProvider
        /// </summary>
        public int Read(byte[] buffer, int offset, int count)
        {
            int sourceBytesRequired = count * 2;
            this.sourceBuffer = BufferHelpers.Ensure(this.sourceBuffer, sourceBytesRequired);
            WaveBuffer sourceWaveBuffer = new WaveBuffer(sourceBuffer);
            WaveBuffer destWaveBuffer = new WaveBuffer(buffer);

            int sourceBytesRead = sourceProvider.Read(sourceBuffer, 0, sourceBytesRequired);
            int samplesRead = sourceBytesRead / 2;
            int destOffset = offset / 2;
            for (int sample = 0; sample < samplesRead; sample += 2)
            {
                short left = sourceWaveBuffer.ShortBuffer[sample];
                short right = sourceWaveBuffer.ShortBuffer[sample + 1];
                float outSample = (left * LeftVolume) + (right * RightVolume);
                // hard limiting
                if (outSample > Int16.MaxValue)
                    outSample = Int16.MaxValue;
                if (outSample < Int16.MinValue)
                    outSample = Int16.MinValue;

                destWaveBuffer.ShortBuffer[destOffset++] = (short)outSample;
            }
            return sourceBytesRead / 2;
        }
        public override int Read(byte[] buffer, int offset, int count)
        {
            int sourceBytesRequired = count * 2;
            WaveBuffer destWaveBuffer = new WaveBuffer(buffer);

            int samplesRead = FBufferCount / 4;
            int destOffset = offset / 4;

            short ch1, ch2, ch3, ch4;
            short outSample1, outSample2;

            for (int sample = 0; sample < samplesRead; sample += 4)
            {
                ch1 = FBufferIn.ShortBuffer[sample];
                ch2 = FBufferIn.ShortBuffer[sample + 1];

                ch3 = FBufferIn.ShortBuffer[sample + 2];
                ch4 = FBufferIn.ShortBuffer[sample + 3];

                outSample1 = ch1;// (ch1 + ch2) / 2;
                outSample2 = 0;// *ch3;// (ch3 + ch4) / 2;

                destWaveBuffer.ShortBuffer[destOffset++] = outSample1;
                destWaveBuffer.ShortBuffer[destOffset++] = outSample2;
            }
            return FBufferCount / 2; // bytes returned
        }
Ejemplo n.º 4
0
 public int Read(byte[] buffer, int offset, int count)
 {
     var waveBuffer = new WaveBuffer(buffer);
     var samplesRequired = count / 4;
     var samplesRead = Read(waveBuffer.FloatBuffer, offset / 4, samplesRequired);
     return samplesRead * 4;
 }
Ejemplo n.º 5
0
 public SpeexChatCodec(BandMode bandMode, int sampleRate, string description)
 {
     decoder = new SpeexDecoder(bandMode);
     encoder = new SpeexEncoder(bandMode);
     recordingFormat = new WaveFormat(sampleRate, 16, 2);
     this.description = description;
     encoderInputBuffer = new WaveBuffer(recordingFormat.AverageBytesPerSecond); // more than enough
 }
 static byte[] PcmFromFloat(float[] pdOutput)
 {
     WaveBuffer wavebuffer = new WaveBuffer(pdOutput.Length * 4);
     for (var i = 0; i < pdOutput.Length; i++)
     {
         wavebuffer.FloatBuffer[i] = pdOutput[i];
     }
     return wavebuffer.ByteBuffer;
 }
Ejemplo n.º 7
0
 public byte[] Decode(byte[] data, int offset, int length)
 {
     var outputBufferTemp = new byte[length * 320];
     var wb = new WaveBuffer(outputBufferTemp);
     int samplesDecoded = decoder.Decode(data, offset, length, wb.ShortBuffer, 0, false);
     int bytesDecoded = samplesDecoded * 2;
     var decoded = new byte[bytesDecoded];
     Array.Copy(outputBufferTemp, 0, decoded, 0, bytesDecoded);
     return decoded;
 }
Ejemplo n.º 8
0
 public byte[] Decode(byte[] data, int offset, int length)
 {
     var outputBufferTemp = new byte[length * 320];
     var wb = new WaveBuffer(outputBufferTemp);
     int samplesDecoded = decoder.Decode(data, offset, length, wb.ShortBuffer, 0, false);
     int bytesDecoded = samplesDecoded * 2;
     var decoded = new byte[bytesDecoded];
     Array.Copy(outputBufferTemp, 0, decoded, 0, bytesDecoded);
     //Debug.WriteLine(String.Format("NSpeex: In {0} bytes, decoded {1} bytes [dec frame size = {2}]", length, bytesDecoded, decoder.FrameSize));
     return decoded;
 }
Ejemplo n.º 9
0
        protected override byte[] ProcessRecordedData(byte[] recorded, int offset, int count)
        {
            lock (lockObject)
            {
                int sourceSamples = count / 4;
                int outSamples = sourceSamples;
                byte[] sourceBuffer = new byte[sourceSamples * 4];
                Buffer.BlockCopy(recorded, offset, sourceBuffer, 0, sourceSamples * 4);
                byte[] outBuffer = new byte[outSamples * 2];
                WaveBuffer sourceWaveBuffer = new WaveBuffer(sourceBuffer);
                WaveBuffer destWaveBuffer = new WaveBuffer(outBuffer);
                int destOffset = 0;
                for (int sample = 0; sample < sourceSamples; sample++)
                {
                    #region 32 bit float to 16bit short, same channels

                    float sample32 = sourceWaveBuffer.FloatBuffer[sample] * 1.0f;              // clip
                    if (sample32 > 1.0f)
                        sample32 = 1.0f;
                    if (sample32 < -1.0f)
                        sample32 = -1.0f;
                    destWaveBuffer.ShortBuffer[destOffset++] = (short)(sample32 * Int16.MaxValue);

                    #endregion

                    #region 32 bit float to 16bit short, combine left and right channels
                    // adjust volume
                    //float leftSample32 = sourceWaveBuffer.FloatBuffer[sample] * 1.0f;              // clip
                    //if (leftSample32 > 1.0f)
                    //    leftSample32 = 1.0f;
                    //if (leftSample32 < -1.0f)
                    //    leftSample32 = -1.0f;

                    //float rightSample32 = sourceWaveBuffer.FloatBuffer[sample + 1] * 1.0f;

                    //if (rightSample32 > 1.0f)
                    //    rightSample32 = 1.0f;
                    //if (rightSample32 < -1.0f)
                    //    rightSample32 = -1.0f;

                    //short spl = (short)(((leftSample32 * Int16.MaxValue) + (int)(rightSample32 * Int16.MaxValue)) / 2);

                    //destWaveBuffer.ShortBuffer[destOffset++] = spl;
                    #endregion
                }
                Array.Copy(destWaveBuffer.ByteBuffer, convertionStream.SourceBuffer, outSamples * 2);
                int converted = convertionStream.Convert(outSamples * 2);
                converted -= converted % 4;
                byte[] result = new byte[converted];
                Array.Copy(convertionStream.DestBuffer, result, converted);
                return base.ProcessRecordedData(result, 0, converted);
            }
        }
Ejemplo n.º 10
0
 public byte[] Decode(byte[] data, int offset, int length)
 {
     if (offset != 0)
     {
         throw new ArgumentException("G722 does not yet support non-zero offsets");
     }
     int decodedLength = length * 4;
     byte[] outputBuffer = new byte[decodedLength];
     WaveBuffer wb = new WaveBuffer(outputBuffer);
     _codec.Decode(_decoderState, wb.ShortBuffer, data, length);
     return outputBuffer;
 }
Ejemplo n.º 11
0
 public byte[] Encode(byte[] data, int offset, int length)
 {
     if (offset != 0)
     {
         throw new ArgumentException("G722 does not yet support non-zero offsets");
     }
     WaveBuffer wb = new WaveBuffer(data);
     int encodedLength = length / 4;
     byte[] outputBuffer = new byte[encodedLength];
     _codec.Encode(_encoderState, outputBuffer, wb.ShortBuffer, length / 2);
     return outputBuffer;
 }
Ejemplo n.º 12
0
 public byte[] Decode(byte[] data, int offset, int length)
 {
     if (offset != 0)
     {
         throw new ArgumentException("G722 does not yet support non-zero offsets");
     }
     int decodedLength = length * 4;
     var outputBuffer = new byte[decodedLength];
     var wb = new WaveBuffer(outputBuffer);
     int decoded = codec.Decode(decoderState, wb.ShortBuffer, data, length);
     Debug.Assert(decodedLength == decoded * 2);  // because decoded is a number of samples
     return outputBuffer;
 }
Ejemplo n.º 13
0
        public AutoTuneWaveProvider(IWaveProvider source, AutoTuneSettings autoTuneSettings)
        {
            this.autoTuneSettings = autoTuneSettings;
            if (source.WaveFormat.SampleRate != 44100)
                throw new ArgumentException("AutoTune only works at 44.1kHz");
            if (source.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat)
                throw new ArgumentException("AutoTune only works on IEEE floating point audio data");
            if (source.WaveFormat.Channels != 1)
                throw new ArgumentException("AutoTune only works on mono input sources");

            this.source = source;
            this.pitchDetector = new AutoCorrelator(source.WaveFormat.SampleRate);
            this.pitchShifter = new SmbPitchShifter(Settings);
            this.waveBuffer = new WaveBuffer(8192);
        }
        public VoipCodecSpeex(BandMode bandMode, int sampleRate, string description, VoipCodecMode mode = VoipCodecMode.Both)
        {
            _bandMode = bandMode;
            _recordingFormat = new WaveFormat(sampleRate, 16, 1);
            _description = description;

            if (mode.HasFlag(VoipCodecMode.Decode))
                _decoder = new SpeexDecoder(bandMode);
            if (mode.HasFlag(VoipCodecMode.Encode))
            {
                _encoder = new SpeexEncoder(bandMode);
                _outputBufferTemp = new byte[_recordingFormat.AverageBytesPerSecond];
                _encoderInputBuffer = new WaveBuffer(_recordingFormat.AverageBytesPerSecond); // more than enough
            }
        }
Ejemplo n.º 15
0
        public int Read(byte[] buffer, int offset, int count)
        {
            if (waveBuffer == null || waveBuffer.MaxSize < count)
            {
                waveBuffer = new WaveBuffer(count);
            }

            int bytesRead = source.Read(waveBuffer, 0, count);
            //Debug.Assert(bytesRead == count);

            // the last bit sometimes needs to be rounded up:
            if (bytesRead > 0) bytesRead = count;

            //pitchsource->getPitches();
            int frames = bytesRead / sizeof(float); // MRH: was count
            float pitch = pitchDetector.DetectPitch(waveBuffer.FloatBuffer, frames);

            if(pitch != 0 && Frequency == 0)
                Frequency = pitch;

            // MRH: an attempt to make it less "warbly" by holding onto the pitch for at least one more buffer
            if (pitch == 0f && release < maxHold)
            {
                pitch = previousPitch;
                release++;
            }
            else
            {
                this.previousPitch = pitch;
                release = 0;
            }

            //int midiNoteNumber = 40;
            //float targetPitch = (float)(8.175 * Math.Pow(1.05946309, midiNoteNumber));

            //WaveBuffer outBuffer = new WaveBuffer(buffer);

            //pitchShifter.ShiftPitch(waveBuffer.FloatBuffer, pitch, targetPitch, outBuffer.FloatBuffer, frames);

            //if (frames > 0)
            //    iteration++;
            //else
            //{
            //    Frequency /= (float)iteration;
            //}

            return frames * 4;
        }
        /// <summary>
        /// Reads bytes from this wave stream
        /// </summary>
        /// <param name="destBuffer">The destination buffer</param>
        /// <param name="offset">Offset into the destination buffer</param>
        /// <param name="numBytes">Number of bytes read</param>
        /// <returns>Number of bytes read.</returns>
        public int Read(byte[] destBuffer, int offset, int numBytes)
        {
            int sourceBytesRequired = numBytes / 2;
            byte[] sourceBuffer = GetSourceBuffer(sourceBytesRequired);
            int sourceBytesRead = sourceProvider.Read(sourceBuffer, offset, sourceBytesRequired);
            WaveBuffer sourceWaveBuffer = new WaveBuffer(sourceBuffer);
            WaveBuffer destWaveBuffer = new WaveBuffer(destBuffer);

            int sourceSamples = sourceBytesRead / 2;
            int destOffset = offset / 4;
            for (int sample = 0; sample < sourceSamples; sample++)
            {
                destWaveBuffer.FloatBuffer[destOffset++] = (sourceWaveBuffer.ShortBuffer[sample] / 32768f) * volume;
            }

            return sourceSamples * 4;
        }
 public void RightChannelOnly()
 {
     IWaveProvider stereoStream = new TestStereoProvider();
     StereoToMonoProvider16 mono = new StereoToMonoProvider16(stereoStream);
     mono.LeftVolume = 0.0f;
     mono.RightVolume = 1.0f;
     int samples = 1000;
     byte[] buffer = new byte[samples * 2];
     int read = mono.Read(buffer, 0, buffer.Length);
     Assert.AreEqual(buffer.Length, read, "bytes read");
     WaveBuffer waveBuffer = new WaveBuffer(buffer);
     short expected = 0;
     for (int sample = 0; sample < samples; sample++)
     {
         short sampleVal = waveBuffer.ShortBuffer[sample];
         Assert.AreEqual(expected--, sampleVal, "sample #" + sample.ToString());
     }
 }
Ejemplo n.º 18
0
 public int Read(byte[] buffer, int offset, int count)
 {
     _readBuffer = NAudio.Utils.BufferHelpers.Ensure(_readBuffer, count);
     _outBuffer = NAudio.Utils.BufferHelpers.Ensure(_outBuffer, count);
     Array.Clear(_outBuffer, 0, _outBuffer.Length);
     WaveBuffer outBuffer = new WaveBuffer(_outBuffer);
     foreach (IWaveProvider prov in _providers)
     {
         int ReadCnt = (prov.Read(_readBuffer, 0, _outBuffer.Length) / 2);
         WaveBuffer readBuff = new WaveBuffer(_readBuffer);
         for (int i = 0; i < ReadCnt; i++)
         {
             outBuffer.ShortBuffer[i] += readBuff.ShortBuffer[i];
         }
     }
     Array.Copy(_outBuffer, 0, buffer, offset, count);
     return count;
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Reads bytes from this WaveProvider
        /// </summary>
        public int Read(byte[] buffer, int offset, int count)
        {            
            int sourceBytesRequired = count / 2;
            this.sourceBuffer = BufferHelpers.Ensure(this.sourceBuffer, sourceBytesRequired);
            WaveBuffer sourceWaveBuffer = new WaveBuffer(sourceBuffer);
            WaveBuffer destWaveBuffer = new WaveBuffer(buffer);

            int sourceBytesRead = sourceProvider.Read(sourceBuffer, 0, sourceBytesRequired);
            int samplesRead = sourceBytesRead / 2;
            int destOffset = offset / 2;
            for (int sample = 0; sample < samplesRead; sample++)
            {
                short sampleVal = sourceWaveBuffer.ShortBuffer[sample];
                destWaveBuffer.ShortBuffer[destOffset++] = (short)(LeftVolume * sampleVal);
                destWaveBuffer.ShortBuffer[destOffset++] = (short)(RightVolume * sampleVal);
            }
            return samplesRead * 4;
        }
 public void LeftChannelOnly()
 {
     IWaveProvider monoStream = new TestMonoProvider();
     MonoToStereoProvider16 stereo = new MonoToStereoProvider16(monoStream);
     stereo.LeftVolume = 1.0f;
     stereo.RightVolume = 0.0f;
     int samples = 1000;
     byte[] buffer = new byte[samples * 2];
     int read = stereo.Read(buffer, 0, buffer.Length);
     Assert.AreEqual(buffer.Length, read, "bytes read");
     WaveBuffer waveBuffer = new WaveBuffer(buffer);
     short expected = 0;
     for (int sample = 0; sample < samples; sample+=2)
     {
         short sampleLeft = waveBuffer.ShortBuffer[sample];
         short sampleRight = waveBuffer.ShortBuffer[sample+1];
         Assert.AreEqual(expected++, sampleLeft, "sample left");
         Assert.AreEqual(0, sampleRight, "sample right");
     }
 }
Ejemplo n.º 21
0
        private static int WaveFloatTo16(byte[] sourceBuffer, int numBytes, byte[] destBuffer)
        {
            var sourceWaveBuffer = new WaveBuffer(sourceBuffer);
            var destWaveBuffer = new WaveBuffer(destBuffer);

            int sourceSamples = numBytes/4;
            int destOffset = 0;
            for (int sample = 0; sample < sourceSamples; sample++)
            {
                float sample32 = sourceWaveBuffer.FloatBuffer[sample];
                // clip
                if (sample32 > 1.0f)
                    sample32 = 1.0f;
                if (sample32 < -1.0f)
                    sample32 = -1.0f;
                destWaveBuffer.ShortBuffer[destOffset++] = (short) (sample32*32767);
            }

            return sourceSamples*2;
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Reads bytes from this wave stream
        /// </summary>
        /// <param name="destBuffer">The destination buffer</param>
        /// <param name="offset">Offset into the destination buffer</param>
        /// <param name="numBytes">Number of bytes read</param>
        /// <returns>Number of bytes read.</returns>
        public int Read(byte[] destBuffer, int offset, int numBytes)
        {
            int sourceBytesRequired = numBytes * 2;
            byte[] sourceBuffer = GetSourceBuffer(sourceBytesRequired);
            int sourceBytesRead = sourceProvider.Read(sourceBuffer, 0, sourceBytesRequired);
            WaveBuffer sourceWaveBuffer = new WaveBuffer(sourceBuffer);
            WaveBuffer destWaveBuffer = new WaveBuffer(destBuffer);

            int sourceSamples = sourceBytesRead / 4;
            int destOffset = offset / 2;
            for (int sample = 0; sample < sourceSamples; sample++)
            {
                // adjust volume
                float sample32 = sourceWaveBuffer.FloatBuffer[sample] * volume;
                // clip
                if (sample32 > 1.0f)
                    sample32 = 1.0f;
                if (sample32 < -1.0f)
                    sample32 = -1.0f;
                destWaveBuffer.ShortBuffer[destOffset++] = (short)(sample32 * 32767);
            }

            return sourceSamples * 2;
        }
Ejemplo n.º 23
0
        private static byte[] DecodeG722(byte[] g722Data, int sampleRate)
        {
            var codec = new G722Codec();
            var state = new G722CodecState(sampleRate, G722Flags.SampleRate8000);

            var decodedLength = g722Data.Length * 2;
            var outputBuffer = new byte[decodedLength];
            var wb = new WaveBuffer(outputBuffer);
            var length = codec.Decode(state, wb.ShortBuffer, g722Data, g722Data.Length) * 2;

            if (length != outputBuffer.Length)
            {
                var outputBuffer2 = new byte[length];
                Buffer.BlockCopy(outputBuffer, 0, outputBuffer2, 0, length);
                outputBuffer = outputBuffer2;
            }

            return outputBuffer;
        }
 public void Write(byte[] buffer, int count)
 {
     FBufferIn = new WaveBuffer(buffer);
     FBufferCount = count;
 }
 /// <summary>
 /// Reads from this wave stream
 /// </summary>
 /// <param name="buffer">Audio buffer</param>
 /// <param name="offset">Offset into buffer</param>
 /// <param name="count">Number of bytes required</param>
 /// <returns>Number of bytes read</returns>
 public override int Read(byte[] buffer, int offset, int count)
 {
     WaveBuffer waveBuffer = new WaveBuffer(buffer);
     int samplesRequired = count / 4;
     int samplesRead = Read(waveBuffer.FloatBuffer, offset / 4, samplesRequired);
     return samplesRead * 4;
 }
Ejemplo n.º 26
0
 public byte[] Encode(byte[] data, int offset, int length)
 {
     if (offset != 0)
     {
         throw new ArgumentException("G722 does not yet support non-zero offsets");
     }
     WaveBuffer wb = new WaveBuffer(data);
     int encodedLength = length / 4 + (length & 0x01);
     byte[] outputBuffer = new byte[encodedLength];
     int encoded = this.codec.Encode(this.encoderState, outputBuffer, wb.ShortBuffer, encodedLength << 1);
     Debug.Assert(encodedLength == encoded);
     return outputBuffer;
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Reads from this wave stream
        /// </summary>
        /// <param name="buffer">Audio buffer</param>
        /// <param name="offset">Offset into buffer</param>
        /// <param name="count">Number of bytes required</param>
        /// <returns>Number of bytes read</returns>
        public override int Read(byte[] destBuffer, int offset, int numBytes)
        {
            /*
            var waveBuffer = new WaveBuffer(buffer);
            int samplesRequired = count / 4;
            int samplesRead = Read(waveBuffer.FloatBuffer, offset / 4, samplesRequired);
            return samplesRead * 4;
             */

            lock (lockObject)
            {
                int bytesWritten = 0;
                WaveBuffer destWaveBuffer = new WaveBuffer(destBuffer);

                // 1. fill with silence
                if (this.Position < 0)
                {
                    bytesWritten = (int)Math.Min(numBytes, 0 - this.Position);
                    for (int n = 0; n < bytesWritten; n++)
                        destBuffer[n + offset] = 0;
                }
                if (bytesWritten < numBytes)
                {
                    this.sampleProvider.LoadNextChunk(readerStream, (numBytes - bytesWritten) / 8);
                    float left, right;

                    int outIndex = (offset / 4) + bytesWritten / 4;
                    while (this.sampleProvider.GetNextSample(out left, out right) && bytesWritten < numBytes)
                    {
                        // implement better panning laws. 
                        left = (pan <= 0) ? left : (left * (1 - pan) / 2.0f);
                        right = (pan >= 0) ? right : (right * (pan + 1) / 2.0f);
                        left *= this.Volume;
                        right *= this.Volume;
                        destWaveBuffer.FloatBuffer[outIndex++] = left;
                        destWaveBuffer.FloatBuffer[outIndex++] = right;
                        bytesWritten += 8;
                        if (Sample != null) RaiseSample(left, right);
                    }
                }
                // 3. Fill out with zeroes
                if (PadWithZeroes && bytesWritten < numBytes)
                {
                    Array.Clear(destBuffer, offset + bytesWritten, numBytes - bytesWritten);
                    bytesWritten = numBytes;
                }
                this.Position += bytesWritten;
                return bytesWritten;
            }

        }
Ejemplo n.º 28
0
 public void LoadNextChunk(IWaveProvider source, int samplePairsRequired)
 {
     int sourceBytesRequired = samplePairsRequired * 8;
     sourceBuffer = BufferHelpers.Ensure(sourceBuffer, sourceBytesRequired);
     sourceWaveBuffer = new WaveBuffer(sourceBuffer);
     sourceSamples = source.Read(sourceBuffer, 0, sourceBytesRequired) / 4;
     sourceSample = 0;
 }
Ejemplo n.º 29
0
        private static byte[] EncodeG722(byte[] pcmMonoData, int sampleRate)
        {
            var codec = new G722Codec();
            var state = new G722CodecState(sampleRate, G722Flags.SampleRate8000);

            var wb = new WaveBuffer(pcmMonoData);
            var encodedLength = pcmMonoData.Length / 2;
            var outputBuffer = new byte[encodedLength];
            var length = codec.Encode(state, outputBuffer, wb.ShortBuffer, pcmMonoData.Length / 2);

            if (length != outputBuffer.Length)
            {
                var outputBuffer2 = new byte[length];
                Buffer.BlockCopy(outputBuffer, 0, outputBuffer2, 0, length);
                outputBuffer = outputBuffer2;
            }

            return outputBuffer;
        }
        private void RenderFile()
        {
            SampleAggregator.RaiseRestart();
            using (WaveFileReader reader = new WaveFileReader(this.voiceRecorderState.ActiveFile))
            {
                this.samplesPerSecond = reader.WaveFormat.SampleRate;
                SampleAggregator.NotificationCount = reader.WaveFormat.SampleRate/10;

                byte[] buffer = new byte[1024];
                WaveBuffer waveBuffer = new WaveBuffer(buffer);
                waveBuffer.ByteBufferCount = buffer.Length;
                int bytesRead;
                do
                {
                    bytesRead = reader.Read(waveBuffer, 0, buffer.Length);
                    int samples = bytesRead / 2;
                    for (int sample = 0; sample < samples; sample++)
                    {
                        if (bytesRead > 0)
                        {
                            sampleAggregator.Add(waveBuffer.ShortBuffer[sample] / 32768f);
                        }
                    }
                } while (bytesRead > 0);
                int totalSamples = (int)reader.Length / 2;
                TotalWaveFormSamples = totalSamples / sampleAggregator.NotificationCount;
                SelectAll();
            }
            audioPlayer.LoadFile(this.voiceRecorderState.ActiveFile);
        }