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 > Figuring out how many samples play between vblanks

#1533 - xonox - Sun Jan 19, 2003 9:53 pm

I'm coding a simple sound routine, i update the buffers after every vblank. I'd like to know how can i figure out how many samples get played every video frame. All i got up to now is that the refresh is *around* 59.737 hz

Anyone's got some good links to pages with sound mixing theory/algorithms as well as about changing the pitch ? I am able to mix sounds and change the pitch (in a non precise way) but i want to learn more about these subjects... I searched google already but i was probably not putting in the proper keywords as i didn't get too much good info.

Thanks a lot!

#1541 - tepples - Sun Jan 19, 2003 11:35 pm

xonox wrote:
I'd like to know how can i figure out how many samples get played every video frame.

To set up audio playback, you take 65536 minus the number of cycles per sample and stuff it into a timer's start register. Therefore, you know how many cycles per sample you're using.

According to the CowBite spec, there are 1232 cycles per scanline and 228 scanlines per frame for a total of 280896 cycles per frame. Divide your number of cycles per sample into 280896 and you get the number of cycles per frame. If the result is not an integer, you will get an occasional click when synchronizing DMA playback to vblank.

For a typical mixer frequency of 18157 Hz, use 924 cycles per sample and 304 samples per frame.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#1638 - Vortex - Mon Jan 20, 2003 10:07 pm

xonox wrote:
Anyone's got some good links to pages with sound mixing theory/algorithms as well as about changing the pitch ? I am able to mix sounds and change the pitch (in a non precise way) but i want to learn more about these subjects... I searched google already but i was probably not putting in the proper keywords as i didn't get too much good info.


A good starting point is http://www.harmony-central.com - check the links under "Computer". Another good link is http://www.dspguide.com/.

#1686 - NEiM0D - Tue Jan 21, 2003 4:26 pm

I suggest double buffering with a 60Hz timer.
You can call your 'refill buffers' routine every Vblank.
Ofcourse you'll need to add a routine to check if the buffer was switched, if so, and refill the respective buffer.