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.

DS development > Sound issues, interrupts and clicking

#89445 - Lazy1 - Sat Jun 24, 2006 11:08 pm

I got around to adding sound to wolf3d which aside from clicking and one rare bug seems to work great.
The rare bug I had caused the game to stall for about a second and part of the machinegun sprite had turned corrupt.

I figured that it was caused by the timer interrupt calling the function that was interrupted ( loading pages from a swap file ). But I'm not sure if this is the case and it has only happened once since I added support for sounds that use more than 1 page ( 4kb ).

Would setting REG_IME to 0 in all pagefile functions solve this problem?
As for the clicking, it was majorly reduced by moving all sound updates to a 0.98ms timer running on both the arm7 and arm9 but it's still there and very noticable even if reduced.

The basic cycle of sound is this:

Arm9:
1. Request from engine to play sound
2. Send sound data to arm7

Arm9 Timer2 Interrupt:
1. If the arm7 is requesting another page
1a. Load another page from the swapfile

Arm7 Timer2 Interrupt:
1. Is a sound supposed to be playing but the sound hw is finished
1a. Request another sound page from the arm9
2. Is there a sound request from the arm9
2a. Play sound

#89448 - Mighty Max - Sat Jun 24, 2006 11:23 pm

The rare bug you are seeing might be a stack problem. I had this behaviour too with some other function and it turned out that i was using that much stack that the system and irq stack were overlapping, and thus corrupting. Or you are simply changing values (globals) that exists chached in the interruped function.

The sound:
This can have multiple reasons with the solutions:
- using the ipc FIFO to better synch the functions
- have the sound in two half-buffers. If you are done with playing the first, start the second and reload the next page into the first again while playing again. This removes the delay where you don't play anything
- if you are using PCM sound, the first value of the next page is played as is, and not relative to the previous one. Say you encoded the following sequence (page border marked with | ):

80 88 90 | 84 70 66

In PCM:
80 +8 +2 -6 -14 -4

But when playing this in two chunks youll get the result:
80 88 90 | -6 -20 -24

The sharp jump might be audible as a click.
Fix: Auto repeat will continue PCM decodeing, instead of restarting at page border.
_________________
GBAMP Multiboot

#89456 - tepples - Sun Jun 25, 2006 12:07 am

Mighty Max wrote:
- if you are using PCM sound, the first value of the next page is played as is, and not relative to the previous one.

Don't you mean "DPCM" or "ADPCM"?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#89557 - Mighty Max - Sun Jun 25, 2006 2:07 pm

This applies to both. Alltho if the differential signals are of the same size as the DAC, the effect vanishes.

As far i testet in 8 bit pcm on the ds it starts clicking when i start a new stream without caring about reinitializing the startvalue or use the hardware to repeat the buffer (and tho not resetting this channel) i filled with the next data waiting to be played.
_________________
GBAMP Multiboot

#89568 - tepples - Sun Jun 25, 2006 3:58 pm

I thought the DS sound hardware's 8-bit and 16-bit PCM modes were straight PCM, not delta PCM. Or are you talking about some game's specific lossless compression? In that case, shouldn't you just Diff8bitUnFilterWram the data when loading it?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.