Cantabile Development Blog

Follow the development of music software Cantabile

Articles | Full Index | RSS Feed


Designing the Audio File Player

I've decided to stop procrastinating on this one and get it done...

Audio file playback is something I've been meaning to add to Cantabile for quite a while now. The reasons for putting it off have been mostly due to some of the issues that need to be solved.

Firstly, I wanted to be able to support more than just simple wave files, at least including support for mp3 files. While I've found the appropriate API's in Microsoft DirectShow for doing this there's a couple of annoying limitations:

  • It doesn't support all the same wave file formats as what Cantabile can write - specifically 64 bit floating point audio and the Wave64 file format.
  • There's not a simple way to get the length of an mp3 file using this API. I really need this and to work around it, I need to use 2 different API's to get it done.

I'm going to investigate other audio reader libraries see if I can simplify what needs to be done here but will probably just write two readers - one for wave formats and one for other files.

Secondly, the biggest complication with playing audio files is sample rate conversion ie: when the sample rate of the source file doesn't match the current sample rate of the audio driver. Previously I didn't have a decent sample rate conversion library that suited my licensing requirements, but I now have one. It's still tricky stuff to setup though.

Thirdly, I want to be able to show a visual representation of the audio file meaning I'll need a file format for the peak data. Rather than invent a new file format for this, Justin Frankel (of WinAmp and Reaper fame) has kindly shared Reaper's peak file format with me.

Finally, I need to design a way to not read the audio file on the same thread as the audio engine. This will involve setting up a dedicated reader thread that is reponsibile for keeping a buffer of upcoming audio ready and available.

So I've got most of the required bits, its now just a matter of pulling it all together...

Posted on May 2, 2008

Share This

Posted on May 2, 2008

Tom says:

Which sample rate conversion library did you settle on?

Also, what's the problem with getting the duration of the MP3 file with DirectShow? Did you try using IMediaSeeking.GetDuration?

Leave A Comment

All comments will be reviewed for spam before being displayed.