Having generic hard disk audio tracks: hdaudio
When I first tried to work with blender as a video editing system I was very surprised about the memory usage of the audio tracks. They are currently bound directly to the game sound system which thinks of sound rather in a notion of sound effects. Those are loaded directly into memory and saved internally into the blend file (which is the right way to handle sound effects btw).
If we want to extend the sequencer of blender to a real audio sequencer solution some day this might again come very handy. (Thinking of the short audio snippets more of instrument samples...)
But most of the time I do video editing I work with longer audio tracks which have been created in a seperate audio editing system and only put it together in the blender sequencer. For this kind of longer audio timelines it is more favourable to keep these tracks on disk and only read them into memory on demand. (Think of several two hour audio track on the timeline...)
Since both ways of thinking of audio are sensible (it depends on the needs) both are still included in the sequencer. I used the naming of the commercial audio editing program "Samplitude" and distinguished the two calling the one "Audio (RAM)" and the other "Audio (HD)". Implementation: include/BIF_editsound.h, hdaudio.c Similar to the imbuf animation system I created an abstract data type "hdaudio" that can be used to open sound files, get there duration and extract raw audio data from them at a given sample rate and position. This is totally different from the bSound-System which lacks a sensible sequencer interface (TODO)!
struct hdaudio * sound_open_hdaudio(char * name)
Open the audio file called "name" and return a hdaudio-struct on success. Anything which has an audio track in it can serve for this (especially DV-files). The current implementation uses ffmpeg to open audio files. It could be easily extended to other interfaces. It should especially additionally contain a fallback which at least works with WAV-files on any platform.
struct hdaudio * sound_copy_hdaudio(struct hdaudio * c)
Clone a hdaudio-struct. This is used by the duplicate-tool.
long sound_hdaudio_get_duration(struct hdaudio * hdaudio, int frame_rate)
Get the duration of the opened audio file in frames. You have to tell it the frame_rate. If you change the frame rate in the middle of your project, you most likely have to reload your "Audio (HD)" files. But if you think a little bit about this, you will notice that this is one of the smaller problems if you change your idea of a frame rate in the middle of the flight...
void sound_hdaudio_extract(struct hdaudio * hdaudio, short * target_buffer, int sample_position /* units of target_rate */, int target_rate, int target_channels, int nb_samples /* in target */)
This extracts samples 16-bit signed from sample_position at target_rate and target_channels. Since hdaudio does not tell you anything about the sample rate of the underlying audio file you probably guessed, that we do rate conversion on the fly. target_buffer must provide at least room for nb_samples * target_channels * 2 bytes.
void sound_close_hdaudio(struct hdaudio * hdaudio)
Close the file again and free all internal structures.