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
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