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 > Code for sampling a loop

#10338 - funkeejeffou - Tue Sep 02, 2003 7:56 pm

Hi,

I've managed to sample a 6 second loop. My code does this :
DMA1 sends data to the FIFO each time timer 0 overflows, and when timer 0 overflows an IRQ is generated. Each Time an IRQ is generated, I keep a variable in IWRAM that is incremented by one.
The sound frequency I use is 6000Hz, and as my loop is 6 second long, everytime my variable reaches 36000, I reinitialize my variable to 0, stop the DMA transfer and reinitialize it so that the sound loop is played from the beginning. That's a personnal algorithm, and it's the first time that I try sampling a sound loop in software.
The problem is that at each loop end, there is some distortion, and I doubt my code is the best.
How does professional developpers manage to have a clean and precise sound looping?

Any suggestions are welcome.
Cheers

#10339 - tepples - Tue Sep 02, 2003 8:08 pm

You may have an off-by-one error.

You may have a data alignment error. Audio should be aligned to a 4 byte boundary.

Actually, most GBA games I've played do sample looping in software, within a soft mixer. The mixer is set up to play at a rate that divides evenly into the length of a frame. This way, you can time things in vblanks.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.