Well, of course it’s possible (unless you’re using some hardware mixer
with weird libitations :-), but you’d probably need some support from the
mixing engine.
I’d say it’s pretty simple in theory, if the mixer is designed with it in
mind - otherwise, it might end up in quite a messy hack.
One example would be the audio engine of “Kobo Deluxe” (probably the
final name of “SKobo”) - as most other mixers, it generates one buffer
for each SDL_audio call to the callback. There are 16 channels with state
info looking like this:
typedef struct
{
audio_samp_t samp;
int nsamp; / number of samples /
int position;
int vol; / percent of default */
int ctl[AC_COUNT];
} audio_channel_t;
As you probably guessed, this is not suitable for save/restore
functionality as it looks now, as you can’t grab the “samp” pointer and
store it somewhere. The pointer (which is a pointer to raw sample data;
not a struct!) would have to be replaced by an “index” that’s guaranteed
to always map to the same sound. (You could translate the indexes to real
names in text format to be on the safe side - just in case there would be
a reason to change the internals of the game later on.)
That fixed, you could just grab all fields of these structs and save them
to disk. (NOT by writing the structs as binary data, though…!
Non-portable and unreliable.) Writing the values back should restore the
engine to exactly where it was when you saved the state, with single
buffer accuracy. (Provided the engine does the sound look-up once per
buffer - or you’d need an “audio_force_load()” feature as well.)
Hmm… I might just go ahead and do this. OTOH, who needs to save a Kobo
game…?
//David Olofson — Programmer, Reologica Instruments AB
.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |
--------------------------------------> david at linuxdj.com -'On Friday 14 September 2001 21:45, Kovacs wrote:
Hi,
i'm currently working on a game and i want to implement save/load
feature. But for me headaches makes audio saving & loading:
Requirements are, that i want that sound gets fully resumed- sound
& music (music is not so important). So is it possible to know at what
offset every sample currently playing is (eg. how much of sample is
played)? And is it possible to start playing sample from selected
offset, not from beginning?