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 > Sounds playing incorrectly

#25607 - daveb - Wed Aug 25, 2004 10:57 pm

I have coded a sound player based on the 'Interrupt Mode Direct Sound Example' on the audio advance page. I choose this way as the page suggested using the dma & interrupts may disrupt multi player games.

I have several wav file all slightly different formats.

I converted all of them to 16000hz using the simon tool, but some of them seem to play correctly and other seem to play at wrong speeds.

I guess it is to do with the format of the wavs before converting them with simon. If this is the problem can anybody suggest conversion tools to use to convert the wavs to a consistant format I can use on the gba, preferably some sort of array.

#25608 - poslundc - Wed Aug 25, 2004 11:03 pm

Do they sound correct when you play them on your PC after converting them?

Dan.

#25636 - daveb - Thu Aug 26, 2004 12:17 pm

The sounds sound fine when played in windows.

I have a wav file in the format unsigned 8bit, 44100hz 352 khz mono
I convert this to a 16000hz header file using the simon tool

in my program I start timer 0 and trigger an interrupt
Code:
REG_TM0D   = 0xffff;
REG_TM0CNT = 0x00C3;


then when I recieve the interrupt I do
Code:
if (!(iNextSampleA&3))
     REG_SGFIF0A=soundA[iNextSampleA<<2];
iNextSampleA++;

To point the fifo a to the sound to be played

I guess the problem (apart from me not really knowing what I am doing) is the format of the wav and the tools used to convert it. I think I need to convert the wav to be signed 8bit, but I cannot find a tool that will do this.

#25641 - poslundc - Thu Aug 26, 2004 1:56 pm

daveb wrote:
I guess the problem (apart from me not really knowing what I am doing)


That is a big problem. If you are new to the GBA, audio programming is not a good starting point, as is definitely one of the more challenging things to do and there are tons of pitfalls you can run into if you aren't very familiar with how the hardware operates.

You might check out DekuTree's sound tutorial if you feel confident enough at GBA programming and just need help wrapping your head around sound concepts.

Quote:
I think I need to convert the wav to be signed 8bit, but I cannot find a tool that will do this.


I don't know any Windows tools. I can recommend two possible courses of action:

1. Write your own tool to convert the samples from unsigned to signed.
2. Change your mixer to process unsigned samples.

If you don't feel comfortable doing either of these things... well, in all honesty you're probably going to run into a lot more trouble if you continue doing audio programming.

Dan.

#25651 - DekuTree64 - Thu Aug 26, 2004 5:46 pm

daveb wrote:
Code:
if (!(iNextSampleA&3))
     REG_SGFIF0A=soundA[iNextSampleA<<2];
iNextSampleA++;


This doesn't look quite right. What type of array is aoundA? If it's a u32, you're just shifting the wrong direction, but if it's an s8, then you need to add a cast too.

Code:
if (!(iNextSampleA&3))
     REG_SGFIF0A=((u32*)soundA)[iNextSampleA>>2];
iNextSampleA++;


That will load 4 samples into the buffer every 4 interrupts.

The unsigned wav could be a problem too. To convert it, all you have to do is subtract 128 from each byte. You might have to write your own little program to do this, and that would be pretty hard.
Try searching for a program called Cool Edit, it can save as raw signed 8-bit PCM data that can be converted to an array or .o file and used directly.
I use Cool Edit 96, but I think 2000 is still good. I think Adobe bought them though, and put a several hundred dollar price tag on it like they always do, so ignore any Adobe pages that come up.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#25984 - daveb - Thu Sep 02, 2004 4:51 pm

Thanks for the help guys. I managed to get my sound to work correctly.

One more quick question, If I pass one sound to Direct Sound Channel A and another to Direct Sound Channel B at the same time will they both play correctly or will they interfere with each other?

#25987 - tepples - Thu Sep 02, 2004 5:00 pm

PCM channel A and PCM channel B are entirely separate, except that you can enable each at full scale, half scale, or off to each of left or right. If you enable both PCM channels to the same output channel, they'll "interfere" (that is, mix) correctly.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.