GP2X Sound Sample Playback Too Quiet


Dave18

Member
Joined
Mar 16, 2003
Messages
352
Age
50
Hi

I have some code that generates an 8 bit sample but as the GP2X only supports 16 bit samples I need to convert it in order to play it.

My code uses Rlyeh's minimal lib and the conversion takes place in the gp2x_sound_frame function.

The code I use is:

CODE

void gp2x_sound_frame(void *blah, void *buff, int samples)
{
int z;

unsigned char *sptr1;

signed short *stream=(signed short *)buff;

if (soundframe==0) sptr1=(unsigned char*) (soundb2+soundpos);
if (soundframe==1) sptr1=(unsigned char*) (soundb3+soundpos);
if (soundframe==2) sptr1=(unsigned char*) (soundb1+soundpos);

for (z=0;z<samples;z++)
{
*(stream++)=((*(sptr1++)-0x80)<<8);
}

soundpos+=samples;
if (soundpos>=1024) soundpos=0;

}




In terms of sounding correct, this plays the sample accurately on the GP2X however the volume is so quiet that I have to hold it to my ear to hear it. The code to generate the 8 bit sample is the same as I used on the GP32, which played it back (in 8 bit format) at a normal volume.

I assume volume has to do with amplitude so I would expect the conversion above to convert a range of 0..255 to -32768..32512 which I would have thought would create a pretty decent amplitude.

I have checked that both left and right channel volume is set to 100.

Thanks for any help anyone can provide.

Dave
 
Ah, I've discovered that the volume setting code in Rlyeh's lib halves the volume levels if the machine is an F200. I wonder if this relates to issues with older firmware as I am running 4.1.1. Removing this code fixes the problem on my GP2X but I am slightly concerned that it may play too loud on older firmwares.

Does anyone know if this is the case?

Thanks

Dave
 
Dave18 said:
Ah, I've discovered that the volume setting code in Rlyeh's lib halves the volume levels if the machine is an F200. I wonder if this relates to issues with older firmware as I am running 4.1.1. Removing this code fixes the problem on my GP2X but I am slightly concerned that it may play too loud on older firmwares.

Does anyone know if this is the case?

Thanks

Dave
I wish folks would not have done this, because it almost always is a check for the presence of the touchscreen device file in /dev/... and this is bad because it does not account for the fact that later firmwares might make any effort to fix this volume problem. Take that code out of minlib and email rlyeh about it. If folks on older firmwares complain, you can add an option in your game to limit the volume. Don't base it just on the presence of the touchscreen device driver, though. Add it as an option in the game, whether in-game or on the command line or in a config file, anything but that.
 
Last edited by a moderator:
SQ, thanks, since realising the issue that was my line of thinking. I'll add a volume option so everyone can adjust it to suit them.

It's worth pointing out that Rlyeh's lib was always a WIP and was never stated to be perfect, however apart from a few small tweaks it has proved very useful.

Dave
 
Dave18 said:
SQ, thanks, since realising the issue that was my line of thinking. I'll add a volume option so everyone can adjust it to suit them.

It's worth pointing out that Rlyeh's lib was always a WIP and was never stated to be perfect, however apart from a few small tweaks it has proved very useful.

Dave
are you using the 0.c version ?
 
Last edited by a moderator:
Yes it's the 0.c version.

I was using it for my ZXGP2X spectrum emulator which I've uploaded the source for. The volume works perfectly on my F200 without halving the values.
 
Back
Top