public OggSong(Stream stream, bool seekable) { decoder = new OggDecoder(); decoder.Initialize(stream, seekable); effect = new DynamicSoundEffectInstance(decoder.SampleRate, (decoder.Stereo ? AudioChannels.Stereo : AudioChannels.Mono)); effect.BufferNeeded += BufferNeeded; bufferCount = -1; }
/// <summary> /// Decodes an ogg stream into a full PCM chunk (useful for sound effects) /// </summary> /// <param name="input">Input ogg data</param> /// <returns>Fully decoded PCM data</returns> public static PCMChunk Decode(Stream input) { OggDecoder decoder = new OggDecoder(); decoder.Initialize(input); MemoryStream ms = new MemoryStream(4096); foreach (PCMChunk chunk in decoder) { ms.Write(chunk.Bytes, 0, chunk.Length); } return(new PCMChunk { Bytes = ms.ToArray(), Channels = decoder.Channels, Length = (int)ms.Length, Rate = decoder.SampleRate }); }
public void Dispose() { if (decoder != null) { decoder.Dispose(); decoder = null; } if (effect != null) { effect.Dispose(); effect = null; } if (enumerator != null) { enumerator.Dispose(); enumerator = null; } bufferCount = 0; }