I think I found a bug in pspAudioLib.
This code just init and then end the audio lib but after two init-end the init fails (cannot create callback threads).
Code: Select all
int main(){
int count = 0;
pspDebugScreenInit();
SetupCallbacks();
pspDebugScreenPrintf("Eboot test\n");
pspDebugScreenPrintf("Press X to run pspAudioInit and pspAudioEnd\n");
SceCtrlData pad;
while(runningFlag){
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_CROSS){
pspDebugScreenSetXY(0, 5);
pspDebugScreenPrintf("Count: %i\n", ++count);
if (pspAudioInit())
pspDebugScreenPrintf("pspAudioInit ERROR!!!\n");
else
pspAudioEnd();
}
sceKernelDelayThread(200000);
}
sceKernelExitGame();
return 0;
}
I fixed this by just adding a "flag" in this structure
Code: Select all
typedef struct {
int threadhandle;
int threadactive; <-- THIS
int handle;
int volumeleft;
int volumeright;
pspAudioCallback_t callback;
void *pdata;
} psp_audio_channelinfo;
Code: Select all
static int AudioChannelThread(int args, void *argp)
{
volatile int bufidx=0;
int channel=*(int *)argp;
AudioStatus[channel].threadactive = 1; <-- HERE
while (audio_terminate==0) {
void *bufptr=&audio_sndbuf[channel][bufidx];
pspAudioCallback_t callback;
callback=AudioStatus[channel].callback;
if (callback) {
callback(bufptr, PSP_NUM_AUDIO_SAMPLES, AudioStatus[channel].pdata);
} else {
unsigned int *ptr=bufptr;
int i;
for (i=0; i<PSP_NUM_AUDIO_SAMPLES; ++i) *(ptr++)=0;
}
pspAudioOutBlocking(channel,AudioStatus[channel].volumeleft,AudioStatus[channel].volumeright,bufptr);
bufidx=(bufidx?0:1);
}
AudioStatus[channel].threadactive = 0; <-- HERE
sceKernelExitThread(0);
return 0;
}
Code: Select all
void pspAudioEnd()
{
int i;
audio_ready=0;
audio_terminate=1;
for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
if (AudioStatus[i].threadhandle != -1) {
//sceKernelWaitThreadEnd(AudioStatus[i].threadhandle,NULL);
while (AudioStatus[i].threadactive) <-- HERE
sceKernelDelayThread(100000);
sceKernelDeleteThread(AudioStatus[i].threadhandle);
}
AudioStatus[i].threadhandle = -1;
}
for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
if (AudioStatus[i].handle != -1) {
sceAudioChRelease(AudioStatus[i].handle);
AudioStatus[i].handle = -1;
}
}
}
EDIT: I see now this commented line:
Code: Select all
sceKernelWaitThreadEnd(AudioStatus[i].threadhandle,NULL);
Why is commented?
I dind't mention that I found the bug on 3.52M33-u4, with a kernel 3.x eboot.
Ciaooo
Sakya