Esempio n. 1
0
        static void ReadWriteAudio(string input, string output)
        {
            var audio = new AudioReader(input);

            audio.LoadMetadataAsync().Wait();
            audio.Load();

            using (var writer = new AudioWriter(output, audio.Metadata.Channels, audio.Metadata.SampleRate))
            {
                writer.OpenWrite(true);

                var frame = new AudioFrame(1);
                while (true)
                {
                    // read next sample
                    var f = audio.NextFrame(frame);
                    if (f == null)
                    {
                        break;
                    }

                    writer.WriteFrame(frame);
                }
            }
        }
Esempio n. 2
0
        static void ReadPlayAudio(string input, string output)
        {
            var audio = new AudioReader(input);

            audio.LoadMetadataAsync().Wait();
            audio.Load();

            using (var player = new AudioPlayer())
            {
                player.OpenWrite(audio.Metadata.SampleRate, audio.Metadata.Channels, showWindow: false);

                // For simple playing, can just use "CopyTo"
                // audio.CopyTo(player);

                var frame = new AudioFrame(audio.Metadata.Channels);
                while (true)
                {
                    // read next frame
                    var f = audio.NextFrame(frame);
                    if (f == null)
                    {
                        break;
                    }

                    try
                    {
                        player.WriteFrame(frame);
                    }
                    catch (IOException) { break; }
                    catch
                    {
                        throw;
                    }
                }
            }
        }