Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            string fileName;
            if (args.Length == 1)
            {
                fileName = args[0];
            }
            else
            {
                var dialog = new OpenFileDialog {Title = "Select an audio file (wma, mp3, ...etc.) or video file..."};
                if (dialog.ShowDialog() != DialogResult.OK)
                    return;
                fileName = dialog.FileName;
            }

            var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            var audioDecoder = new AudioDecoder(stream);

            var outputWavStream = new FileStream("output.wav", FileMode.Create, FileAccess.Write);

            var wavWriter = new WavWriter(outputWavStream);

            // Write the WAV file
            wavWriter.Begin(audioDecoder.WaveFormat);

            // Decode the samples from the input file and output PCM raw data to the WAV stream.
            wavWriter.AppendData(audioDecoder.GetSamples());

            // Close the wav writer.
            wavWriter.End();

            audioDecoder.Dispose();
            outputWavStream.Close();
            stream.Close();
        }
Ejemplo n.º 2
0
        public static void DecodeAudioToWav(string fileName)
        {
            fileName = "Assets/sounds/" + fileName;
            var stream       = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            var audioDecoder = new AudioDecoder(stream);

            var outputWavStream = new FileStream(fileName + ".wav", FileMode.Create, FileAccess.Write);

            var wavWriter = new WavWriter(outputWavStream);

            // Write the WAV file
            wavWriter.Begin(audioDecoder.WaveFormat);

            // Decode the samples from the input file and output PCM raw data to the WAV stream.
            wavWriter.AppendData(audioDecoder.GetSamples());

            // Close the wav writer.
            wavWriter.End();

            audioDecoder.Dispose();
            outputWavStream.Close();
            stream.Close();
        }
Ejemplo n.º 3
0
        private async void btnSharpDXMP3toWav_Click(object sender, RoutedEventArgs e)
        {
            var LocalFolder = await ApplicationData.Current.LocalFolder
                                             .CreateFolderAsync(@"Assets", CreationCollisionOption.OpenIfExists);
            var folder = await StorageFolder.GetFolderFromPathAsync(Windows.ApplicationModel.Package.Current.InstalledLocation.Path + @"\Assets");
            var fileMP3 = await folder.GetFileAsync(string.Format("{0}", "Clk_1Sec1_10s_70s_150s_210s_270s.mp3"));
            var fileWav = await LocalFolder.CreateFileAsync(string.Format("{0}", "SharpDx.wav"), CreationCollisionOption.ReplaceExisting);


            using (Stream streamMP3 = await fileMP3.OpenStreamForReadAsync())
            {
                using (Stream streamWav = await fileWav.OpenStreamForWriteAsync())
                {
                    AudioDecoder audioDecoder = new AudioDecoder(streamMP3);
                    WavWriter wavWriter = new WavWriter(streamWav);
                    

                    wavWriter.Begin(audioDecoder.WaveFormat);

                    // Decode the samples from the input file and output PCM raw data to the WAV stream.
                    wavWriter.AppendData(audioDecoder.GetSamples());

                    // Close the wav writer.
                    wavWriter.End();

                    audioDecoder.Dispose();
                }
            }

            this.me1.Source = new Uri(string.Format("ms-appdata:///local/Assets/{0}", "SharpDx.wav"));

            //Stream streamMP3 = await fileMP3.OpenStreamForReadAsync();
            //Stream streamWav = await fileWav.OpenStreamForWriteAsync();
            //AudioDecoder audioDecoder = new AudioDecoder(streamMP3);
            //WavWriter wavWriter = new WavWriter(streamWav);

            //wavWriter.Begin(audioDecoder.WaveFormat);

            //// Decode the samples from the input file and output PCM raw data to the WAV stream.
            //wavWriter.AppendData(audioDecoder.GetSamples());

            //// Close the wav writer.
            //wavWriter.End();

            //audioDecoder.Dispose();
            //await streamWav.FlushAsync();
        }
Ejemplo n.º 4
0
        public SoundBufferedDataSource(FileInfo FileName)
        {
            //Extract the data from the sound file, and create a buffer with them

            //Creating the source, was not existing
            Volume = 1.0f;

            SoundStream soundstream;

            switch (FileName.Extension)
            {
            case ".wav":
                //Load the sound and bufferize it
                soundstream = new SoundStream(File.OpenRead(FileName.FullName));
                WaveFormat  = soundstream.Format;
                AudioBuffer = new AudioBuffer()
                {
                    Stream     = soundstream.ToDataStream(),
                    AudioBytes = (int)soundstream.Length,
                    Flags      = BufferFlags.EndOfStream
                };

                soundstream.Close();
                soundstream.Dispose();
                break;

            case ".wma":     // NOT good idea this can be HUGE buffer, better streaming a WMA file !
                //New data stream
                using (FileStream fileStream = new FileStream(FileName.FullName, FileMode.Open, FileAccess.Read))
                {
                    var audioDecoder    = new AudioDecoder(fileStream);
                    var outputWavStream = new MemoryStream();

                    var wavWriter = new WavWriter(outputWavStream);

                    // Write the WAV file
                    wavWriter.Begin(audioDecoder.WaveFormat);
                    // Decode the samples from the input file and output PCM raw data to the WAV stream.
                    wavWriter.AppendData(audioDecoder.GetSamples());
                    // Close the wav writer.
                    wavWriter.End();

                    outputWavStream.Position = 0;
                    soundstream = new SoundStream(outputWavStream);

                    WaveFormat  = soundstream.Format;
                    AudioBuffer = new AudioBuffer()
                    {
                        Stream     = soundstream.ToDataStream(),
                        AudioBytes = (int)soundstream.Length,
                        Flags      = BufferFlags.EndOfStream
                    };

                    soundstream.Close();
                    soundstream.Dispose();
                    outputWavStream.Dispose();
                    audioDecoder.Dispose();
                }

                break;

            default:
                break;
            }
        }