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.

Beginners > Problem looping sound **FIXED**

#112486 - misterDtD - Sat Dec 16, 2006 9:15 pm

I am using timer 1 (along with an interrupt) to loop my sound, in the tutorial I am taking, they have me use "TIMER1 = 65536 - BGM_LENGTH;" to start my timer, but my sound's lenght is 320000 so 65536-320000=-254464, which makes my sound loop in the middle, which I really don't want.

here is the sound file.

So, how do I make my timer work with my music being as long as it is (and it isn't very long, only 13 seconds.)

~DtD
NOTE: I did reduce the sound's quality to a 24000 sampiling rate, mono, and an 8 bit-rate


Last edited by misterDtD on Sat Dec 16, 2006 11:46 pm; edited 1 time in total

#112496 - QuantumDoja - Sat Dec 16, 2006 11:42 pm

Im not sure, but I dont think you can play mp3 or wav on the gameboy, your going to have to convert your sound file first.....i think its *.mod???
_________________
Chris Davis

#112498 - misterDtD - Sat Dec 16, 2006 11:46 pm

You can play converted (to raw data) PCM WAV files.
MOD is just another music format, but it still has to be converted to raw data.

Anyway, I fixed my problem, the stupid timer wasn't big enough for my sound's lenght (well I already knew that), so I made a interupt function for timer 0 (the timer controlling my sound) that incremented a variable every time, then once the variable > sound lenght I looped the sound and restarted the variable.

~DtD

#112499 - tepples - Sat Dec 16, 2006 11:50 pm

In order to play waveforms longer than 65536 samples without using a mixer, you'll need to keep track of how many samples are left in a separate variable. Cascade the sample timer into a second timer set to 65536 - 64000 = 1536, and then every time it fires, subtract 64000 from the number of samples left. Once there are fewer than 64000 samples left, set the timer to 64000 minus the actual number of samples left.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.