[linux-audio-dev] memory-mapped wav files

james at dis-dot-dat.net james at dis-dot-dat.net
Thu Jul 13 23:06:23 UTC 2006

On Thu, 13 Jul, 2006 at 04:45PM -0400, Stephen Sinclair spake thus:
> A thought occured to me recently...
> If I am writing an application which needs to stream a large wav file,
> I am having to write something which reserves some memory, and loads
> pieces of the wav file from disk on request. Say I need to be able to
> jump around the file a bit, I would have to detect when the piece is
> not available and load it in as appropriate.
> ... which I realized is exactly what the OS VM paging system does.
> So, has anyone tried using memory-mapped files for streaming audio
> data?  (obviously, I mean, in a non-realtime thread, using a buffer).
> Or would this be totally inefficient?
> I was thinking it could really simplify programming, just directly
> accessing parts of the wav file as needed, and letting the OS load it
> up into physical memory when it wants to.

It's perfectly sensible.  I do it a lot, because it's easy.  The
problem is having to load the whole thing into memory before you
start, which makes things alow to start.  If you're playing linearly,
to solve this, you need can load it in chunks and start playing the
first chunk straight away.

> Just curious.
> Steve

More information about the Linux-audio-dev mailing list