예제 #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();
        }
예제 #2
0
        public AudioInfo Decode( Stream stream, params object [] args )
        {
            AudioDecoder decoder = new AudioDecoder ( stream );

            AudioInfo audioInfo = new AudioInfo ();
            audioInfo.AudioChannel = ( AudioChannel ) decoder.WaveFormat.Channels;
            audioInfo.BitPerSample = decoder.WaveFormat.BitsPerSample / 8;
            audioInfo.SampleRate = decoder.WaveFormat.SampleRate;

            audioInfo.AudioStream = stream;
            audioInfo.AudioDecoder = this;

            audioInfo.Samples = new SampleStruct () { AudioDecoder = decoder, DataPointers = decoder.GetSamples ().GetEnumerator () };

            return audioInfo;
        }
예제 #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();
        }