Marcus wrote:
> Heres some code thats plays an 8bit sample at 16 Khz, I've currently got
it
> playing a 1 minute Prodigy Firestarter track while 4x4 offroaders is
running
> at 20FPS on the GBA unit, pretty cool..
Thanks for the code, Marcus. Works great for me too!
You might get over 20FPS if you make a small change, however:
> *(unsigned short *)TM0CNT = 0x000c3;
This enables IRQ on timer 0, which isn't necessary. Use 0x83 instead.
Otherwise, you're generating 16,000 interrupts every second, needlessly.
============
Changing the Sample Rate
Storing 0x83 into TM0CNT and 0xFFFF into TM0D sets the sample rate at
16780000 / 1024 = 16387Hz. For a different sample rate, the following
works:
Calculate X = int(16780000.0f / sample_rate + 0.5);
Set TM0D = 65536 - X
Set TM0CNT to 0x80 [no prescaling]
This gives excellent resolution for sample rate [e.g. X = 761 for 22.050Hz
which is 1/2 of CD audio rate; the resulting sample rate is 22049.93.]
Ed xxx