Virtual Harmonica

see: http://gp2x.fullsack.com/cocoon/gp2x/docs/racket/

Simple SDL_Mixer Management With Linus Sphinx's Racket.c


1. Overview

Playing recorded sounds at the appropriate time, mixing them and control of their volume is almost mandatory in every 
program I write for the gp2x so I created a wrapper that simplifies it to the point of linking and including one more 
file, calling one each initialization and clean up function and then sprinkling my code with play sound calls at the 
appropriate event.


2. Step by Step

Step one is to create your program source code directory as you would for any program, copy racket.h along with racket.c 
in there with the rest of your source then create a directory named,"wav", beneath it and in your wav directory place 
all your sound files you want your program to play and the script named, "racketmake.sh".

So now you should have:

/usr/local/gp2xdev/example/
        example.c, example.h, ..., racket.c, racket.h

/usr/local/gp2xdev/example/wav
        example.wav, ..., racketmake.sh

Step two is running racketmake.sh in the wav directory, this will read a list of the *.wav files in your wav directory 
and write two files, one is racket.elf containing the number of and list of files to load sans extension and in what
order, the other is noise.h which is included by racket.h and contains the labels of the values passed to the racketplay 
function.

racket.elf contents:

#:1
w:example

noise.h contents:

// noise header to include in your program
#define EXAMPLE 0

Step three is to start using it.


3. Usage 

Add the line, #include "racket.h", to the list of includes at the top of your c file you wish to play sounds from, add 
racket.c to the list of files linked with your program, (see the example make file for help with that), after SDL has
been initialized then start and use it: 

#include "racket.h"

racketstart(); // call one time at program start

racketplay( EXAMPLE, 0 ); // first arg is defined value from wav/noise.h, second is duration, 0 duration plays once, -1 loops forever, positve duration loops duration times

racketstop(); // call one time at program end or atexit();


4. Under The Hood

racketstart(void) reads the racket.elf file then creates an array of sound buffers loading each of the sounds into one. When 
racketvolume([2|-2]) is called in your programs main event loop to adjust the volume of all wavs at once.
racketplay(EXAMPLE, 0) is called it checks to see if that sound is currently playing, restarts it if so or starts it if not. 
racketon(EXAMPLE) starts a noise playing continuously.
racketoff(EXAMPLE) stops a noise playing continuously.
racketstop(void) deletes the array of sound buffers and releases all memory.
see racket.h for exact prototypes.

