Page 1 of 1

SFX without looping?

Posted: Wed Jan 13, 2010 12:49 pm
by martijnversluis
Hi,

I have a problem when I play SFX's. I use mmEffectEx() to play them, but they loop eternally. However, mmEffectEx() does not have a loop parameter. Do you have to stop a SFX always, or is there a way to play them only once?

Below the code i use. At the moment I only play one sound using sound_play(SFX_GAME_WON);

Code: Select all

#include <nds.h>
#include <maxmod9.h>
#include <stdio.h>
#include "space-sound.h"

#include "soundbank.h"
#include "soundbank_bin.h"

mm_sound_effect sounds[MSL_BANKSIZE];
mm_sfxhand handlers[MSL_BANKSIZE];
int i;

void sound_load() {
	mmInitDefaultMem((mm_addr)soundbank_bin);
	for(i = 0; i < MSL_BANKSIZE; i++) {
		mmLoadEffect(i);
		mm_sound_effect s;
		s.id = i;
		s.rate = 1024;
		s.handle = 0;
		s.volume = 220;
		s.panning = 128;
		sounds[i] = s;
	}
}

void sound_unload() {
	for(i = 0; i < MSL_BANKSIZE; i++)
		mmUnloadEffect(i);
}

void sound_play(int sound) {
	handlers[sound] = mmEffectEx(&sounds[sound]);
}

void sound_abort(int sound) {
	mmEffectCancel(handlers[sound]);
}

Re: SFX without looping?

Posted: Tue Jan 19, 2010 5:32 pm
by eKid
The sound will loop if there is looping information in the wav file itself (stored in the 'sampler chunk'). I'm not sure how you created the wav file but you need to remove that loop point somehow (unless there is some other bug in maxmod causing this...).

Re: SFX without looping?

Posted: Thu Feb 25, 2010 1:11 pm
by n315on
Another thing to look at is make sure your function being called is not in a loop. I had similar problems with adding and subtracting from scores.

EDIT: (Update). I copied your functions into one of my programs using three WAV files, and did not get looping sounds. Your functions where better written than mine, so I'll just probably continue to use them, so thank you for that.