Beispiel #1
0
        /// <summary>
        ///   Plays the recorded audio stream.
        /// </summary>
        ///
        private void btnPlay_Click(object sender, EventArgs e)
        {
            // First, we rewind the stream
            stream.Seek(0, SeekOrigin.Begin);

            // Then we create a decoder for it
            decoder = new WaveDecoder(stream);

            // Configure the track bar so the cursor
            // can show the proper current position
            if (trackBar1.Value < decoder.Frames)
            {
                decoder.Seek(trackBar1.Value);
            }
            trackBar1.Maximum = decoder.Samples;

            // Here we can create the output audio device that will be playing the recording
            output = new AudioOutputDevice(this.Handle, decoder.SampleRate, decoder.Channels);

            // Wire up some events
            output.FramePlayingStarted += output_FramePlayingStarted;
            output.NewFrameRequested   += output_NewFrameRequested;
            output.Stopped             += output_PlayingFinished;

            // Start playing!
            output.Play();

            updateButtons();
        }
Beispiel #2
0
        /// <summary>
        /// Opens a cached audio file. Usually used for small audio files (.wav)
        /// </summary>
        public AudioSource GetSound(FileSystemEntry entry,
                                    AudioVolumeSlider?vslider = AudioVolumeSlider.None, bool loop = false)
        {
            AudioBuffer buffer;

            if (!_cached.ContainsKey(entry.FilePath))
            {
                var    decoder = new WaveDecoder(entry.Open());
                byte[] data    = null;
                decoder.GetSamples(ref data);

                buffer = AddDisposable(_engine.CreateBuffer());
                buffer.BufferData(data, decoder.Format);

                _cached[entry.FilePath] = buffer;
            }
            else
            {
                buffer = _cached[entry.FilePath];
            }

            var mixer = (vslider.HasValue && vslider.Value != AudioVolumeSlider.None) ?
                        _mixers[vslider.Value] : null;
            var source = AddDisposable(_engine.CreateSource(mixer));

            source.QueueBuffer(buffer);
            // TODO: Implement looping

            _sources.Add(source);

            return(source);
        }
Beispiel #3
0
        /// <summary>
        /// Opens a cached audio file. Usually used for small audio files (.wav)
        /// </summary>
        public AudioSource GetSound(FileSystemEntry entry, bool loop = false)
        {
            AudioBuffer buffer;

            if (!_cached.ContainsKey(entry.FilePath))
            {
                var    decoder = new WaveDecoder(entry.Open());
                byte[] data    = null;
                decoder.GetSamples(ref data);

                buffer = AddDisposable(_engine.CreateBuffer());
                buffer.BufferData(data, decoder.Format);

                _cached[entry.FilePath] = buffer;
            }
            else
            {
                buffer = _cached[entry.FilePath];
            }

            var source = AddDisposable(_engine.CreateSource());

            source.QueryBuffer(buffer);
            // TODO: Implement looping

            _sources.Add(source);

            return(source);
        }
Beispiel #4
0
        /// <summary>
        ///   Plays the recorded audio stream.
        ///   播放录制的音频流。
        /// </summary>
        ///
        private void BtnPlay_Click(object sender, EventArgs e)
        {
            // First, we rewind the stream
            //【1】首先,我们拨回初始值
            stream.Seek(0, SeekOrigin.Begin);

            // Then we create a decoder for it
            //【2】然后我们为它创建一个解码器
            decoder = new WaveDecoder(stream);

            /*Configure the track bar so the cursorcan show the proper current position
             *【3】 配置跟踪条,使光标可以显示正确的当前位置
             */
            if (trackBar1.Value < decoder.Frames)
            {
                decoder.Seek(trackBar1.Value);
            }
            trackBar1.Maximum = decoder.Samples;

            // Here we can create the output audio device that will be playing the recording
            //【4】在这里我们可以创建将播放录音的输出音频设备
            output = new AudioOutputDevice(this.Handle, decoder.SampleRate, decoder.Channels);

            // 【5】Wire up some events 注册一些事件
            //【5.1】指示帧块已开始执行事件。
            output.FramePlayingStarted += output_FramePlayingStarted;
            output.NewFrameRequested   += output_NewFrameRequested;
            output.Stopped             += output_PlayingFinished;

            // Start playing!
            output.Play();

            updateButtons();
        }
Beispiel #5
0
        private float[] getSignal(String path)
        {
            WaveDecoder decoder = new WaveDecoder(path);

            float[] samples = new float[decoder.Frames];
            decoder.Decode(samples.Length).CopyTo(samples);
            return(samples);
        }
        private static Signal loadSignalFromWaveFile(string p_filePath)
        {
            WaveDecoder sourceDecoder = new WaveDecoder(p_filePath);

            // Decode the file and store into a signal
            Signal sourceSignal = sourceDecoder.Decode();

            return(sourceSignal);
        }
Beispiel #7
0
        public static Signal ObterSinalMono(string arquivoAudio)
        {
            var audioDecoder = new WaveDecoder(arquivoAudio);

            using (var originalSignal = audioDecoder.Decode())
            {
                var monoFilter = new MonoFilter();
                return(monoFilter.Apply(originalSignal));
            }
        }
Beispiel #8
0
        public static double[] GetMfcc(string file)
        {
            WaveDecoder decoder = new WaveDecoder(file);
            Signal      signal  = decoder.Decode();
            MelFrequencyCepstrumCoefficient mfcc = new MelFrequencyCepstrumCoefficient();

            MelFrequencyCepstrumCoefficientDescriptor[] ra = mfcc.Transform(signal).ToArray();
            var query = from x in ra select x.Descriptor.Average();

            return(query.ToArray());
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            string currentFilePath = "";

            args = new string[1] {
                Path.Combine(Environment.CurrentDirectory, "SGTV.wav")
            };
            if (args != null && args.Length > 0)
            {
                var str = args[0];
                Console.WriteLine("Args : " + str);

                var waveFile = str + ".wav";// str.ToLower().Replace(".mp3", ".wav");
                var lrcFile  = str + ".lrc";
                currentFilePath = str + ".xml";
                if (File.Exists(currentFilePath) == true)
                {
                    Console.WriteLine("xml file is E");
                    DMDocument doc = DMDocument.Load(currentFilePath);
                    Lyrics     lrc = new Lyrics();

                    foreach (var sentence in doc.Sentences)
                    {
                        LyricsPhrase phrase = new LyricsPhrase()
                        {
                            BeginTime = sentence.BeginTime,
                            EndTime   = sentence.EndTime,
                            Text      = sentence.Text
                        };
                        lrc.Phrases.Add(phrase);
                    }
                    lrc.Save(lrcFile);
                }
                else
                {
                    WaveDecoder wd = new WaveDecoder();
                    wd.ProcessForRecognize(str, waveFile);

                    DictationSyncEngine engine = new DictationSyncEngine("en-US");

                    engine.SentenceRecognized += engine_SentenceRecognized;
                    engine.RecognizeCompleted += engine_RecognizeCompleted;
                    engine.Process(waveFile);
                }
            }
            else
            {
                Console.WriteLine("Args is null!");
            }
            Console.ReadLine();
        }
Beispiel #10
0
        public ComplexSignal FFTComplex(string sFile)
        {
            WaveDecoder    signalwav    = new WaveDecoder("./Sounds/" + sFile + ".wav");
            Signal         sourceSignal = signalwav.Decode();
            BlackmanWindow window       = new BlackmanWindow(fs);

            Signal[]      windows  = sourceSignal.Split(window, fs);
            Signal        wSignal  = window.Apply(sourceSignal, fs);
            ComplexSignal sComplex = wSignal.ToComplex();

            sComplex.ForwardFourierTransform();
            signalwav.Close();
            return(sComplex);
        }
        /// <summary>
        /// Open the given audio file and return an "AudioSignal" with the following info:
        ///     1. data[]: array of audio samples
        ///     2. sample rate
        ///     3. signal length in milli sec
        /// </summary>
        /// <param name="filePath">audio file path</param>
        /// <returns>AudioSignal containing its data, sample rate and length in ms</returns>
        public static AudioSignal OpenAudioFile(string filePath)
        {
            WaveDecoder waveDecoder = new WaveDecoder(filePath);

            AudioSignal signal = new AudioSignal();

            signal.sampleRate             = waveDecoder.SampleRate;
            signal.signalLengthInMilliSec = waveDecoder.Duration;
            Signal tempSignal = waveDecoder.Decode(waveDecoder.Frames);

            signal.data = new double[waveDecoder.Frames];
            tempSignal.CopyTo(signal.data);
            return(signal);
        }
Beispiel #12
0
        public void SignalLoadSave()
        {
            string input = Path.Combine(NUnit.Framework.TestContext.CurrentContext.TestDirectory, "Resources", "a.wav");

            Signal sourceSignal = Signal.FromFile(input);

            Assert.AreEqual(352800, sourceSignal.Samples);
            Assert.AreEqual(sourceSignal.Samples, sourceSignal.NumberOfSamples);
            Assert.AreEqual(176400, sourceSignal.Length);
            Assert.AreEqual(sourceSignal.Length, sourceSignal.NumberOfFrames);
            Assert.AreEqual(4000, sourceSignal.Duration.TotalMilliseconds);
            Assert.AreEqual(2, sourceSignal.Channels);
            Assert.AreEqual(44100, sourceSignal.SampleRate);
            Assert.AreEqual(sizeof(float) * 352800, sourceSignal.NumberOfBytes);

            string output = Path.Combine(NUnit.Framework.TestContext.CurrentContext.TestDirectory, "ab.wav");

            sourceSignal.Save(output);

            FileStream destinationStream = new FileStream(output, FileMode.Open, FileAccess.Read);

            // Create a decoder to read the destination stream
            WaveDecoder destDecoder = new WaveDecoder(destinationStream);

            Assert.AreEqual(2, destDecoder.Channels);
            Assert.AreEqual(176400, destDecoder.Frames);
            Assert.AreEqual(352800, destDecoder.Samples);
            Assert.AreEqual(4000, destDecoder.Duration);
            Assert.AreEqual(44100, destDecoder.SampleRate);
            Assert.AreEqual(32, destDecoder.BitsPerSample);
            Assert.AreEqual(1411200 * 2, destDecoder.AverageBitsPerSecond);

            // Decode the destination stream
            Signal destSignal = destDecoder.Decode();

            // Assert that the signal which has been saved to the destination
            // stream and the signal which has just been read from this same
            // stream are identical
            Assert.AreEqual(sourceSignal.Length, destSignal.Length);
            Assert.AreEqual(sourceSignal.SampleFormat, destSignal.SampleFormat);
            Assert.AreEqual(sourceSignal.SampleRate, destSignal.SampleRate);
            Assert.AreEqual(sourceSignal.Samples, destSignal.Samples);
            Assert.AreEqual(sourceSignal.Duration, destSignal.Duration);

            byte[] actual   = sourceSignal.ToByte();
            byte[] expected = destSignal.ToByte();
            Assert.AreEqual(expected, actual);
        }
        public void ComplexSignalConstructor()
        {
            var          sourceStream      = SignalTest.GetSignal("a.wav");
            MemoryStream destinationStream = new MemoryStream();

            // Create a decoder for the source stream
            WaveDecoder sourceDecoder = new WaveDecoder(sourceStream);

            // Decode the signal in the source stream
            Signal sourceSignal = sourceDecoder.Decode();

            int length = (int)Math.Pow(2, 12);

            RaisedCosineWindow window = RaisedCosineWindow.Hamming(length);

            Assert.AreEqual(length, window.Length);

            Signal[] windows = sourceSignal.Split(window, 1024);

            Assert.AreEqual(windows.Length, 172);

            foreach (var w in windows)
            {
                Assert.AreEqual(length, w.Length);
            }

            ComplexSignal[] complex = windows.Apply(ComplexSignal.FromSignal);

            for (int i = 0; i < complex.Length - 1; i++)
            {
                ComplexSignal c = complex[i];
                Assert.AreEqual(2, c.Channels);
                Assert.AreEqual(93, c.Duration.TotalMilliseconds);
                Assert.AreEqual(4096, c.Length);
                Assert.AreEqual(SampleFormat.Format128BitComplex, c.SampleFormat);
                Assert.AreEqual(44100, c.SampleRate);
                Assert.AreEqual(ComplexSignalStatus.Normal, c.Status);
            }

            complex.ForwardFourierTransform();

            for (int i = 0; i < complex.Length - 1; i++)
            {
                ComplexSignal c = complex[i];
                Assert.AreEqual(ComplexSignalStatus.FourierTransformed, c.Status);
            }
        }
Beispiel #14
0
        public void ComplexSignalConstructor()
        {
            UnmanagedMemoryStream sourceStream      = Properties.Resources.Grand_Piano___Fazioli___major_A_middle;
            MemoryStream          destinationStream = new MemoryStream();

            // Create a decoder for the source stream
            WaveDecoder sourceDecoder = new WaveDecoder(sourceStream);

            // Decode the signal in the source stream
            Signal sourceSignal = sourceDecoder.Decode();

            int length = (int)Math.Pow(2, 12);

            RaisedCosineWindow window = RaisedCosineWindow.Hamming(length);

            Assert.AreEqual(length, window.Length);

            Signal[] windows = sourceSignal.Split(window, 1024);

            Assert.AreEqual(windows.Length, 172);

            foreach (var w in windows)
            {
                Assert.AreEqual(length, w.Length);
            }

            ComplexSignal[] complex = windows.Apply(ComplexSignal.FromSignal);

            for (int i = 0; i < complex.Length - 1; i++)
            {
                ComplexSignal c = complex[i];
                Assert.AreEqual(2, c.Channels);
                Assert.AreEqual(92, c.Duration);
                Assert.AreEqual(4096, c.Length);
                Assert.AreEqual(SampleFormat.Format128BitComplex, c.SampleFormat);
                Assert.AreEqual(44100, c.SampleRate);
                Assert.AreEqual(ComplexSignalStatus.Normal, c.Status);
            }

            complex.ForwardFourierTransform();

            for (int i = 0; i < complex.Length - 1; i++)
            {
                ComplexSignal c = complex[i];
                Assert.AreEqual(ComplexSignalStatus.FourierTransformed, c.Status);
            }
        }
Beispiel #15
0
        public void SetDirectoryPaths(string folderPath)
        {
            audioFileName = Directory.GetFiles(folderPath, "*.wav").Select(Path.GetFileName).OrderBy(r => r.Length).ToArray();

            for (int i = 0; i < audioFileName.Length; i++)
            {
                string      fileName = audioFileName[i];
                WaveDecoder sourceWD = new WaveDecoder(fileName);
                Signal      sourceS  = sourceWD.Decode();

                RaisedCosineWindow window  = RaisedCosineWindow.Hamming(1024);
                Signal[]           windows = sourceS.Split(window, 512);

                ComplexSignal[] complex = windows.Apply(ComplexSignal.FromSignal);

                complex.ForwardFourierTransform();
            }
        }
Beispiel #16
0
        private void btnPlay_Click(object sender, EventArgs e)
        {
            stream.Seek(0, SeekOrigin.Begin);
            decoder = new WaveDecoder(stream);

            if (trackBar1.Value < decoder.Frames)
            {
                decoder.Seek(trackBar1.Value);
            }
            trackBar1.Maximum = decoder.Samples;

            output = new AudioOutputDevice(this.Handle, decoder.SampleRate, decoder.Channels);
            output.NewFrameRequested   += new EventHandler <NewFrameRequestedEventArgs>(output_NewFrameRequested);
            output.Stopped             += new EventHandler(output_PlayingFinished);
            output.FramePlayingStarted += new EventHandler <PlayFrameEventArgs>(output_FramePlayingStarted);
            output.Play();

            updateButtons();
        }
Beispiel #17
0
        public MusicAnalyse(string path)
        {
            this.path = path;

            using (var wavFile = File.Open(path, FileMode.Open))
            {
                var decoded = new WaveDecoder(wavFile).Decode();

                signal = new WaveRectifier(true).Apply(new LowPassFilter(0.9f).Apply(decoded));
                //signal = new HighPassFilter(1f).Apply(decoded);
                //signal = new WaveRectifier(false).Apply(decoded);
            }

            //var wavFile = File.Open(path, FileMode.Open)

            audio = new WaveFileReader(path);

            player = new WasapiOut();
            player.Initialize(audio);
        }
Beispiel #18
0
        private void adjustVolume(float value)
        {
            // First, we rewind the stream
            stream.Seek(0, SeekOrigin.Begin);

            // Then we create a decoder for it
            decoder = new WaveDecoder(stream);

            var signal = decoder.Decode();

            // We apply the volume filter
            var volume = new VolumeFilter(value);

            volume.ApplyInPlace(signal);

            // Then we store it again
            stream.Seek(0, SeekOrigin.Begin);
            encoder = new WaveEncoder(stream);
            encoder.Encode(signal);
        }
Beispiel #19
0
 public Decoder(Stream stream, IntPtr controlHandle, EventHandler <AudioOutputErrorEventArgs> AudioOutputError, EventHandler <PlayFrameEventArgs> FramePlayingStarted, EventHandler <NewFrameRequestedEventArgs> NewFrameRequested, EventHandler Stopped)
 {
     this.decoder = new WaveDecoder(stream);
     init(controlHandle, AudioOutputError, FramePlayingStarted, NewFrameRequested, Stopped);
 }
Beispiel #20
0
        public void WaveEncoderConstructorTest()
        {
            // Load a file in PCM 16bpp format
            // Number of samples: 352.800
            // Number of frames:  176.400
            // Sample rate:        44.100 Hz
            // Block align:         4
            // Channels:            2
            // Duration:            4.0   s
            // Bytes:             705.644
            // Bitrate:           1411kbps

            // sizeof(float) = 4
            // sizeof(int)   = 4
            // sizeof(short) = 2

            UnmanagedMemoryStream sourceStream      = Properties.Resources.Grand_Piano___Fazioli___major_A_middle;
            MemoryStream          destinationStream = new MemoryStream();

            // Create a decoder for the source stream
            WaveDecoder sourceDecoder = new WaveDecoder(sourceStream);

            Assert.AreEqual(2, sourceDecoder.Channels);
            Assert.AreEqual(352800, sourceDecoder.Samples);
            Assert.AreEqual(176400, sourceDecoder.Frames);
            Assert.AreEqual(4000, sourceDecoder.Duration);
            Assert.AreEqual(44100, sourceDecoder.SampleRate);
            Assert.AreEqual(16, sourceDecoder.BitsPerSample);
            Assert.AreEqual(1411200, sourceDecoder.AverageBitsPerSecond);

            // Decode the signal in the source stream
            Signal sourceSignal = sourceDecoder.Decode();

            Assert.AreEqual(352800, sourceSignal.Samples);
            Assert.AreEqual(176400, sourceSignal.Length);
            Assert.AreEqual(4000, sourceSignal.Duration);
            Assert.AreEqual(2, sourceSignal.Channels);
            Assert.AreEqual(44100, sourceSignal.SampleRate);
            Assert.AreEqual(sizeof(float) * 352800, sourceSignal.RawData.Length);
            Assert.AreEqual(sizeof(short) * 352800, sourceDecoder.Bytes);


            // Create a encoder for the destination stream
            WaveEncoder encoder = new WaveEncoder(destinationStream);

            // Encode the signal to the destination stream
            encoder.Encode(sourceSignal);

            Assert.AreEqual(2, encoder.Channels);
            Assert.AreEqual(352800, encoder.Samples);
            Assert.AreEqual(176400, encoder.Frames);
            Assert.AreEqual(4000, encoder.Duration);
            Assert.AreEqual(44100, encoder.SampleRate);
            Assert.AreEqual(32, encoder.BitsPerSample);
            Assert.AreEqual(sizeof(float) * 352800, encoder.Bytes);


            // Rewind both streams, them attempt to read the destination
            sourceStream.Seek(0, SeekOrigin.Begin);
            destinationStream.Seek(0, SeekOrigin.Begin);

            // Create a decoder to read the destination stream
            WaveDecoder destDecoder = new WaveDecoder(destinationStream);

            Assert.AreEqual(2, destDecoder.Channels);
            Assert.AreEqual(176400, destDecoder.Frames);
            Assert.AreEqual(352800, destDecoder.Samples);
            Assert.AreEqual(4000, destDecoder.Duration);
            Assert.AreEqual(44100, destDecoder.SampleRate);
            Assert.AreEqual(32, destDecoder.BitsPerSample);
            Assert.AreEqual(1411200, sourceDecoder.AverageBitsPerSecond);


            // Decode the destination stream
            Signal destSignal = destDecoder.Decode();

            // Assert that the signal which has been saved to the destination
            // stream and the signal which has just been read from this same
            // stream are identical
            Assert.AreEqual(sourceSignal.Length, destSignal.Length);
            Assert.AreEqual(sourceSignal.SampleFormat, destSignal.SampleFormat);
            Assert.AreEqual(sourceSignal.SampleRate, destSignal.SampleRate);
            Assert.AreEqual(sourceSignal.Samples, destSignal.Samples);
            Assert.AreEqual(sourceSignal.Duration, destSignal.Duration);


            for (int i = 0; i < sourceSignal.RawData.Length; i++)
            {
                byte actual   = sourceSignal.RawData[i];
                byte expected = destSignal.RawData[i];
                Assert.AreEqual(expected, actual);
            }
        }
Beispiel #21
0
        public void WaveEncoderConstructorTest()
        {
            string basePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources");

            #region doc_properties
            // Let's say we would like to decode a wave file:
            string fileName = Path.Combine(basePath, "a.wav");

            // File is in PCM 16bpp format:
            // Number of samples: 352.800
            // Number of frames:  176.400
            // Sample rate:        44.100 Hz
            // Block align:         4
            // Channels:            2
            // Duration:            4.0   s
            // Bytes:             705.644
            // Bitrate:           1411kbps

            // First, create a decoder for the file stream:
            var sourceDecoder = new WaveDecoder(fileName);

            // Now we can use it to check some of the the stream properties:
            int numberOfChannels     = sourceDecoder.NumberOfChannels; // 2
            int numberOfSamples      = sourceDecoder.NumberOfSamples;  // 352800
            int numberOfFrames       = sourceDecoder.NumberOfFrames;   // 176400
            int durationMilliseconds = sourceDecoder.Duration;         // 4000
            int sampleRate           = sourceDecoder.SampleRate;       // 44100
            int bitsPerSample        = sourceDecoder.BitsPerSample;    // 16
            int bps = sourceDecoder.AverageBitsPerSecond;              // 141200

            // Decode the signal in the source stream:
            Signal sourceSignal = sourceDecoder.Decode();

            // As we can see, all properties are kept in the signal:
            int      signalChannels   = sourceSignal.NumberOfChannels; // 2
            int      signalSamples    = sourceSignal.NumberOfSamples;  // 352800
            int      signalFrames     = sourceSignal.NumberOfFrames;   // 176400
            TimeSpan signalDuration   = sourceSignal.Duration;         // {00:00:04}
            int      signalLength     = sourceSignal.Length;           // 176400
            int      signalSampleRate = sourceSignal.SampleRate;       // 44100
            int      signalBytes      = sourceSignal.NumberOfBytes;    // 1411200

            // And this is the total number of bytes that have been read:
            int numberOfBytes = sourceDecoder.NumberOfBytesRead; // 705600
            #endregion


            Assert.AreEqual(2, numberOfChannels);
            Assert.AreEqual(352800, numberOfSamples);
            Assert.AreEqual(176400, numberOfFrames);
            Assert.AreEqual(4000, durationMilliseconds);
            Assert.AreEqual(44100, sampleRate);
            Assert.AreEqual(16, bitsPerSample);
            Assert.AreEqual(1411200, bps);
            Assert.AreEqual(sizeof(short) * 352800, numberOfBytes);

            Assert.AreEqual(352800, signalSamples);
            Assert.AreEqual(176400, signalLength);
            Assert.AreEqual(4000, signalDuration.TotalMilliseconds);
            Assert.AreEqual(2, signalChannels);
            Assert.AreEqual(44100, signalSampleRate);
            Assert.AreEqual(sizeof(float) * 352800, signalBytes);

            MemoryStream destinationStream = new MemoryStream();

            // Create a encoder for the destination stream
            WaveEncoder encoder = new WaveEncoder(destinationStream);

            // Encode the signal to the destination stream
            encoder.Encode(sourceSignal);

            Assert.AreEqual(2, encoder.Channels);
            Assert.AreEqual(352800, encoder.Samples);
            Assert.AreEqual(176400, encoder.Frames);
            Assert.AreEqual(4000, encoder.Duration);
            Assert.AreEqual(44100, encoder.SampleRate);
            Assert.AreEqual(32, encoder.BitsPerSample);
            Assert.AreEqual(sizeof(float) * 352800, encoder.Bytes);


            // Rewind both streams, them attempt to read the destination
            destinationStream.Seek(0, SeekOrigin.Begin);

            // Create a decoder to read the destination stream
            WaveDecoder destDecoder = new WaveDecoder(destinationStream);
            Assert.AreEqual(2, destDecoder.Channels);
            Assert.AreEqual(176400, destDecoder.Frames);
            Assert.AreEqual(352800, destDecoder.Samples);
            Assert.AreEqual(4000, destDecoder.Duration);
            Assert.AreEqual(44100, destDecoder.SampleRate);
            Assert.AreEqual(32, destDecoder.BitsPerSample);
            Assert.AreEqual(1411200, sourceDecoder.AverageBitsPerSecond);


            // Decode the destination stream
            Signal destSignal = destDecoder.Decode();

            // Assert that the signal which has been saved to the destination
            // stream and the signal which has just been read from this same
            // stream are identical
            Assert.AreEqual(sourceSignal.Length, destSignal.Length);
            Assert.AreEqual(sourceSignal.SampleFormat, destSignal.SampleFormat);
            Assert.AreEqual(sourceSignal.SampleRate, destSignal.SampleRate);
            Assert.AreEqual(sourceSignal.Samples, destSignal.Samples);
            Assert.AreEqual(sourceSignal.Duration, destSignal.Duration);

            byte[] actual   = sourceSignal.ToByte();
            byte[] expected = destSignal.ToByte();
            Assert.AreEqual(expected, actual);
        }
Beispiel #22
0
 /// <summary>
 ///   Constructs a new Wave file audio source.
 /// </summary>
 ///
 /// <param name="stream">The stream containing a Wave file.</param>
 ///
 public WaveFileAudioSource(Stream stream)
 {
     this.stream  = stream;
     this.decoder = new WaveDecoder();
 }
Beispiel #23
0
 /// <summary>
 ///   Constructs a new Wave file audio source.
 /// </summary>
 ///
 /// <param name="fileName">The path for the underlying source.</param>
 ///
 public WaveFileAudioSource(string fileName)
 {
     this.fileName = fileName;
     this.decoder  = new WaveDecoder();
 }
Beispiel #24
0
        public static Signal ObterSinal(string arquivoAudio)
        {
            var audioDecoder = new WaveDecoder(arquivoAudio);

            return(audioDecoder.Decode());
        }