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 > Playing/converting sounds

#158263 - ZeroSum - Sun Jun 08, 2008 1:30 pm

Hi again, I'm trying to play sounds using libnds but am having some trouble playing them correctly. The SimpleSound example works great but using the example code and raw's in my own code everything sounds extremely 'tinny' and distorted. I've been searching around but keep getting contradictory information.

1. What is the 'correct' format for my own simple sound effects (1-2 second wav's)? So far I'm converting to 11025hz, 8bit, signed raw files using SoX.

2. How do I get the makefile to convert the .raw's to .o for me? I've added (copied from the SimpleSound example makefile):
Code:
#---------------------------------------------------------------------------------
%.raw.o   :   %.raw
#---------------------------------------------------------------------------------
   @echo $(notdir $<)
   @$(bin2o)

to the makefile and made sure the raw was in the data dir but it seems to do nothing. I'm rather new to makefiles so I'm guessing I've missed something. I've just been renaming the .raw to a .bin but would prefer not to have to do that.

3. The code I'm using to play sounds is just like from the example:
Code:

TransferSoundData blaster = {
   blaster_bin,      /* Sample address */
   blaster_bin_size,   /* Sample length */
   11025,            /* Sample rate */
   127,            /* Volume */
   64,               /* panning */
   1                /* format */
};

playSound(&blaster);

I'm using the default arm7 code and devkitPro r23b. Have I (again) missed something which is why everything sounds distorted? Both my own raw's and the example ones both sound wrong.

Thanks for reading.

#158265 - eKid - Sun Jun 08, 2008 2:03 pm

Quote:
1. What is the 'correct' format for my own simple sound effects (1-2 second wav's)? So far I'm converting to 11025hz, 8bit, signed raw files using SoX.


The tinny sound may be from the low sampling rate (11025 is pretty low). Does the quality improve with higher sampling rates?

Converting 16-bit to 8-bit may cause a tiny bit of distortion (a bit of white noise), but it usually isn't much of an issue.

#158268 - tepples - Sun Jun 08, 2008 5:08 pm

ZeroSum wrote:
The SimpleSound example works great but using the example code and raw's in my own code everything sounds extremely 'tinny' and distorted.

Are you playing your audio through the DS's internal speaker or through headphones? Internal speakers in handheld video game systems have a strong high-pass characteristic, blocking most sound below about 500 Hz. Headphones should reproduce bass more accurately.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#158277 - ZeroSum - Sun Jun 08, 2008 7:06 pm

Thanks for the replies, I thought it may be that too but after messing around some more I don't think thats it. The SimpleSound example on hardware will play the 'blaster' sound perfectly fine (its the blaster from Star Wars?), yet if I copy the blaster.raw file to my own program and use the exact same code the blaster sound is really distorted. I think I might have missed setting something up but comparing to the example to my code its exactly the same.

#158278 - silent_code - Sun Jun 08, 2008 7:13 pm

I am in no position to help you much, as I have only had experience with basic sound programming myself, but I can tell you, this looks a lot like you will have to show your implementation.
At least some more information is needed.
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#158333 - ZeroSum - Mon Jun 09, 2008 11:10 am

After getting up this morning I saw the problem right away. I was playing the sound inside of a keysHeld() if instead of keysDown() so the distorted sound was it playing over itself a couple of times, it works great now. Lesson learned too ><

#158334 - silent_code - Mon Jun 09, 2008 11:32 am

There is nothing better than a pair of "fresh" eyes (and ears, when working with audio.) :^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.