Playing an effect from memory buffer
Posted: Sat Apr 14, 2012 5:55 pm
Hi
Experimenting with MAXMOD I was trying to play a sound that I had loaded from the filesystem. The docs refer to mmEffectExt for playing external sounds; however, the code would not link. I had a look at the maxmod source and it appears the prototype for mmEffectExt is there but no implementation - hence link error.
I noticed on the forums that mmEffectEx could be used but I have had no joy. Below is my simple test code. Am I doing something stupid?
The sound effect I am trying to play is IMA ADPCM, 8000Hz. It plays fine if I use:
Similarly if I play a sound from the soundbank wirh maxmod using mmEffect that works also.
Thanks
Experimenting with MAXMOD I was trying to play a sound that I had loaded from the filesystem. The docs refer to mmEffectExt for playing external sounds; however, the code would not link. I had a look at the maxmod source and it appears the prototype for mmEffectExt is there but no implementation - hence link error.
I noticed on the forums that mmEffectEx could be used but I have had no joy. Below is my simple test code. Am I doing something stupid?
Code: Select all
/* MaxMod test */
#include <nds.h>
#include <filesystem.h>
#include <maxmod9.h>
#include <stdio.h>
#include "soundbank.h"
#include "soundbank_bin.h"
int main(int argc, char **argv) {
consoleDemoInit();
nitroFSInit();
mmInitDefaultMem((mm_addr)soundbank_bin);
// load a sample from nitro
FILE* pFile = fopen("test.ima", "rb");
u32 size = 3788;
void* pBuf = malloc(size);
fread(pBuf, size, 1, pFile);
fclose(pFile);
mm_ds_sample sample;
sample.loop_start = 0;
sample.length = size/8; // size in words - 4bit data
sample.format = 2;
sample.repeat_mode = 2;
sample.base_rate = 250; // 8000Hz *1024/32768
sample.data = pBuf;
mm_sound_effect sound;
sound.sample = &sample;
sound.rate = 1024;
sound.handle = 0;
sound.volume = 255;
sound.panning = 128;
mmEffectEx(&sound);
while(true) swiWaitForVBlank();
free(pBuf);
return 0;
}
Code: Select all
soundPlaySample(pBuf, SoundFormat_ADPCM, size, 8000, 127, 64, 0, 0);
Thanks