32X Audio

Ask anything your want about the 32X Mushroom programming.

Moderator: BigEvilCorporation

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sun Feb 10, 2013 12:18 am

Okay, here's what you wanted. :D

This is the xmplayer with sfx support. The music playing is still the same, but now we also have an array of sfx mixers (4 in this example, but you can change it by changing the define in sound.h). You have the following functions (protos in sound.h):

Code: Select all

extern void fill_buffer(int16_t *buffer);
extern uint8_t start_sfx(int8_t *data, uint16_t srate, uint32_t loop_length, uint32_t length, uint8_t volume, uint8_t pan);
extern void update_sfx(uint8_t mix, int32_t srate, int32_t volume, int32_t pan);
extern void stop_sfx(uint8_t mix);
extern uint8_t check_sfx(uint8_t mix);
They're pretty self explanatory... you'll find example usage in main.c. You can start a sfx, stop it, check if it's still playing, and change the pitch/volume/pan on the fly. None of this affects the music.

In the example, press A to start the rain sfx, which loops forever. Press C to stop the rain sfx. Press B to start a punch sfx, which then does a "oof" sfx when the punch is done.

Remember that you can turn down the music volume by repeatedly pressing LEFT. You'll probably have to press it like 24 times to get the volume down low enough to hear the sfx well.

xmplayer-sfx.zip

ammianus
Very interested
Posts: 124
Joined: Sun Jan 29, 2012 2:10 pm
Location: North America
Contact:

Post by ammianus » Sun Feb 10, 2013 1:32 pm

:D

That sounds awesome in my headphones, with D_E3M3 playing, rain and punching sfx all at once.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sun Feb 10, 2013 6:38 pm

ammianus wrote::D

That sounds awesome in my headphones, with D_E3M3 playing, rain and punching sfx all at once.
The sound on the 32X is pretty awesome... and all I'm doing is what we probably would have seen in 2nd gen titles from Sega. Too bad it never made it that far.

The rain sfx was mostly to show how a small audio clip could be looped for a cheap atmospheric kind of background noise rather than music, but it also works with music as well. Think of this use... a waterfall. When you got within range of the waterfall, you'd start the sfx looped with a small volume, then make it louder as you got nearer. You would also change the pan as you turned to reflect which way the waterfall was.

You could use the looped sfx also for engine noise in racing games. All sorts of uses for looped sounds in games. And for single shot sfx, of course.

The other example provided by the demo is the fact that the sounds I used are all 16kHz, but played at 22kHz. Merely change the increment to handle the change in rate. The sample rates for sounds could be literally anything and they could still be played. Of course, too low and you'd here aliasing noise, and too high and you'd waste space on samples that don't play. You probably want your sounds between 8 and 16 kHz, or higher for music samples. I've noticed that XMs with a max sample rate of 28 to 32 kHz sound better than ones with 22 kHz sample rates. Of course, this all goes back to size. Too high and it may use too much memory. Of course, if you just have a few songs and don't care if your rom is 4MB, then you may want more quality.
:D

Post Reply