static void ReadWriteAudio(string input, string output) { var audio = new AudioReader(input); audio.LoadMetadata().Wait(); audio.Load(); using (var writer = new AudioWriter(output, audio.Metadata.Channels, audio.Metadata.SampleRate)) { writer.OpenWrite(true); var frame = new AudioFrame(1, audio.Metadata.Channels); while (true) { // read next sample var f = audio.NextFrame(frame); if (f == null) { break; } writer.WriteFrame(frame); } } }
public async Task LoadMetadataOgg() { var audio = new AudioReader(Res.GetPath(Res.Audio_Ogg)); await audio.LoadMetadata(); Assert.True(audio.Metadata.Codec == "vorbis"); Assert.True(audio.Metadata.BitRate == 48000); Assert.True(audio.Metadata.SampleFormat == "fltp"); Assert.True(audio.Metadata.SampleRate == 11025); Assert.True(audio.Metadata.Channels == 2); Assert.True(audio.Metadata.Streams.Length == 1); Assert.True(Math.Abs(audio.Metadata.Duration - 1.515102) < 0.01); }
public async Task LoadMetadataMp3() { var audio = new AudioReader(Res.GetPath(Res.Audio_Mp3)); await audio.LoadMetadata(); Assert.True(audio.Metadata.Codec == "mp3"); Assert.True(audio.Metadata.BitRate == 128000); Assert.True(audio.Metadata.SampleFormat == "fltp"); Assert.True(audio.Metadata.SampleRate == 44100); Assert.True(audio.Metadata.Channels == 2); Assert.True(audio.Metadata.Streams.Length == 1); Assert.True(Math.Abs(audio.Metadata.Duration - 1.549187) < 0.01); }
static void ReadPlayAudio(string input, string output) { var audio = new AudioReader(input); audio.LoadMetadata().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; } } } }