The current engine works with the concept of "patches". Patches are a sequence of parameters that defines how your notes or sound effects evolves over time. There's already a couples of patches I've made for Megatris I've regrouped in an include file. Add this include to your program file:
Code: Select all
#include "data/patches.inc"
Code: Select all
//FX: "Echo Droplet"
const char patch01[] PROGMEM ={
0,
0,PC_ENV_SPEED,-12,
5,PC_NOTE_UP,12,
5,PC_NOTE_DOWN,12,
5,PC_NOTE_UP,12,
5,PC_NOTE_DOWN,12,
5,PC_NOTE_CUT,0,
0,PATCH_END
};
From Beta3 the patch system has been tweaked to support a PCM channel which allows to play samples of arbitrary length. The sound type byte as been removed from the command stream and move into a special array of structs.
Code: Select all
const struct PatchStruct patches[] PROGMEM = {
{0,NULL,patch00,0,0},
{0,NULL,patch01,0,0},
{0,NULL,patch02,0,0},
{0,NULL,patch03,0,0},
{1,NULL,patch04,0,0},
...
};
Code: Select all
{1,NULL,patch04,0,0}
Second parameter (NULL) is a pointer to the PCM data if it were a PCM patch
Third parameter (patch04) is the patch's command stream pointer
Fourth (0) is the loop start position for PCM samples
Fifth (0) is the loop end position for PCM samples
Soooo....now let play some sounds! Add this line to your main() function:
Code: Select all
InitMusicPlayer(patches);
Code: Select all
TriggerFx(19,0xff,true);
19 is the patch number
0xff is the volume
true is the 'retrig' attribute. It basically means that if another TriggerFx() call is made for the same patch *before* the previous one is finished playing, it will re-trigger it right away on the same channel instead of starting another simultaneous instance of the sound onto another channel (determined by the voice stealing algorithm).
Creating new patches is really trial an error. I suggest you make an empty project to create new patches. It will compile and flash faster.
That's it! Have fun.
Uze