So many streams to play one track?

Jun 25, 2010 at 6:27 AM
Edited Jun 25, 2010 at 6:31 AM
Hi, I may just be a bit dim, so i thought i would post in here to make sure im not just wasting memory...
Currently when i load an MP3 file i have to do the following:

private void ProcessStream(FileStream musicStream) { m_MediaStream = CreateMediaStream(musicStream); m_ConvertedStream = WaveFormatConversionStream.CreatePcmStream(m_MediaStream); m_BlockAlignedStream = new BlockAlignReductionStream(m_ConvertedStream); m_LoopedStream = new LoopedStream(m_BlockAlignedStream); m_Channel = new WaveChannel32(m_LoopedStream); m_WaveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()); m_WaveOut.Init(m_Channel); m_WaveOut.Volume = 1.0f; m_Channel.Volume = Volume; } private WaveStream CreateMediaStream(FileStream fileStream) { var fileExtension = Path.GetExtension(fileStream.Name).ToLower(); switch (fileExtension) { case ".mp3": { return new Mp3FileReader(fileStream.Name); } case ".wav": { return new WaveFileReader(fileStream.Name); } default: { throw new Exception("Unsupported file"); } } }

Now each one of those members is a stream in itself, so when i want to dispose i have to call dispose on all those streams, then recreate them again... originally i was just using the using() pattern around them up until the channel was created then just leaving the channel and waveout, however if i dispose any one of those streams it throws an exception when I play or do any action on the waveout. So im assuming that they are built up through composition or something so each one just wraps the previous, is this right? and if so is there any way to get round it... WOW THIS EDITOR IS ABSOLUTE RUBBISH...