Re: [linux-audio-dev] memory management

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] memory management
From: Joshua Haberman (jhaberman_AT_ups.edu)
Date: Mon Nov 26 2001 - 02:51:34 EET


* Christophe Baillon (cbaillon_AT_ifrance.com) wrote:
> To treat big samples (40Mo for example) is it judicious to load the
> whole file in only one buffer ?
> If i want to insert an other sample of 5 Mo in the medium of the buffer,
> should i cut the sample into a linked list of block memory, or should i
> make a realloc() and a displacement of data in the block ?
>
> Is there interesting link on the web about algorithms used by sound
> applications ?

Audacity (audacity.sourceforge.net) breaks up audio data into blocks that
are somewhere between 500k and 1MB and stores each of these into its own
file in the temp directory. Each block file contains the audio data
uncompressed and waveform summaries to allow for quick display. We've
toyed around with the idea of using FLAC (flac.sourceforge.net) to allow
for compressed internal representation, but nothing's come of this. The
hope is that the reduced disk I/O would compensate for the overhead of
compressing and decompressing on the fly (can anyone confirm or deny?).

These blocks are reference counted and deleted when their reference count
reaches zero. Copy and paste just creates more references to the same
blocks where possible, and creates new ones where necessary (like where
the boundary of the region lies mid-block). Operations that modify audio
data create new blocks with the modified data, preserving the originals.
Blocks are never modified, and never deleted until undo data is
discarded. Throughout all editing operations, Audacity ensures that all
blockfiles have sizes that lie within established limits, determined by
benchmarking.

The current state is represented by a list of pointers to blocks. Undo
information is represented by a list of states. This makes undo and redo
almost instantaneous, since it only involves pointer manipulations. In
the unstable branch, there is a history window that allows you to jump to
any state that is currently stored in the list, and also allows you to
discard as many undo operations as you wish (so that the blocks can be
deleted, and disk space freed).

An Audacity Project is just a text file that contains metadata about the
project and the references to block files. This makes opening a project
almost instantaenous, though it requires that a project be stored as a
whole directory of block files. We may change this in the future, somehow
allowing for all the information to be stored in a single file while
preserving the advantages of the current system.

I didn't design this system -- Dominic Mazzoni, Audacity's main author,
did. He was planning to write a paper explaining it, but I don't think he
ever did. If you want to see source code, read
{BlockFile,DirManager,WaveTrack}.{cpp,h} in Audacity's source tree.

Joshua

-- 
Joshua Haberman  <joshua_AT_haberman.com>


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Mon Nov 26 2001 - 02:43:00 EET