gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Audio > Stopping sound...

#13328 - MumblyJoe - Thu Dec 11, 2003 6:21 am

I have a large sample of sound in a game I am writing, and it plays great. Only problem is stopping it. The way I understand it, I have two choices... either use interrupts or count something like vblanks which have a predictable rate and stop it based on length.

I have been trying to use interrupts, but I am having alot of problems, in fact it stops my game from running the second I enable them. My interrupt handler is in iwram and uses arm code (i hear both those things are important) and i put its address in the right memory location, but nothing. I have enabled everything right and gone over it with a fine tooth comb, but with no luck.

So basically, is there a better way?
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#13329 - poslundc - Thu Dec 11, 2003 6:24 am

Have you enabled interrupts in crt0.S? Are you clearing REG_IF upon completion of your ISR?

Posting your interrupt code may help further.

Dan.

#13331 - MumblyJoe - Thu Dec 11, 2003 6:39 am

I have been clearing REG_IF, I didnt know I had to enable them in crt0.s, which by the way I have gone back to using the default that comes with devkitadv.
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#13367 - poslundc - Thu Dec 11, 2003 11:51 pm

crt0.S has interrupts disabled by default; you need to open it up and scroll through and uncomment a line or two in order to get them working. The file is extremely well-commented so you shouldn't have a problem figuring it out.

Dan.

#14662 - Snake - Sat Jan 10, 2004 11:07 am

I had a problem stopping sound myself. The problem was I am using both sound channels so could'nt cascade the timers to use interupts to stop them. In the end I used a bit of a bodge system to stop them.
When playback is started at any point within the program, say the collision detection routine, I intialised a down counter with a value dependant on the size of the sample. This counter value is checked in the main program loop after the screen is refreshed and if > 0 it is decremented. If the result is then 0 the appropriate timer and DMA functions are cleared. This of course is fairly inaccurate but if you have an approximate 0.1s silence at the end of each sample it works fine and the counter values are easy to set. This basically uses the frame rate to time samples so you may need to play around with the period of silence at the end of the sample. My game is written completely in assembler so it's pretty fast, whether or not this is a viable possibility in C/C++ I don't know....


snake