As I use only mono samples, I'd like to init the sound output myself (not using the pspaudiolib).
But I have a problem as there are always clicks in the sounds, as if there was some time between each buffer played... I need some help.
Code: Select all
void updatesound(unsigned short *buf, unsigned int reqn) {
int i, voix;
int sample;
int *buf32 = (int *)( (int)buf | 0x40000000);
for(i = 0; i < (reqn >> 1); i++) {
if(mix[0].son < mix[0].finson) {
sample = *mix[0].son++;
} else sample = 0;
for(voix = 1; voix < nb_mix; voix++) {
if(mix[voix].son < mix[voix].finson) sample += *mix[voix].son++;
}
sample >>= 2;
if(sample > 32767) sample = 32767;
if(sample < -32768) sample = -32768;
sample |= (sample << 16);
*buf32++ = sample;
}
}
static void audiothread(void) {
volatile int bufidx = 0;
void *bufptr;
for(;;) {
bufptr = &sbuffer[bufidx];
updatesound(bufptr, sbufmid);
sceAudioOutputBlocking(audiohandle, 0x8000, bufptr);
bufidx = 1 - bufidx;
}
sceKernelExitThread(0);
return;
}
void InitSound(void) {
audiohandle = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, sbufmid, PSP_AUDIO_FORMAT_MONO);
if(audiohandle < 0) return;
audiothandle = sceKernelCreateThread("audiot01", (void*)&audiothread, 0x12, 0x10000, 0, NULL);
if(audiothandle < 0) return;
int a = sceKernelStartThread(audiothandle, 0, NULL);
if(a != 0) {
sceKernelDeleteThread(audiothandle);
audiothandle = -1;
}
}