Here's the patch, it should explain how their used.
Code: Select all
diff -ru ./pspaudiolib.c ../../src/pspaudiolib.c
--- ./pspaudiolib.c 2007-08-30 10:37:58.000000000 -0500
+++ ../../src/pspaudiolib.c 2007-09-08 15:26:05.828125000 -0500
@@ -18,6 +18,10 @@
#include "pspaudiolib.h"
+int sceAudio_38553111(unsigned short samples, unsigned short freq, char);
+int sceAudio_5C37C0AE(void);
+int sceAudio_E0727056(int volume, void *buffer);
+
static int audio_ready=0;
static short audio_sndbuf[PSP_NUM_AUDIO_CHANNELS][2][PSP_NUM_AUDIO_SAMPLES][2];
@@ -27,12 +31,14 @@
void pspAudioSetVolume(int channel, int left, int right)
{
- AudioStatus[channel].volumeright = right;
- AudioStatus[channel].volumeleft = left;
+ if(channel >= PSP_NUM_AUDIO_CHANNELS) return;
+ AudioStatus[channel].volumeright = right;
+ AudioStatus[channel].volumeleft = left;
}
void pspAudioChannelThreadCallback(int channel, void *buf, unsigned int reqn)
{
+ if(channel >= PSP_NUM_AUDIO_CHANNELS) return;
pspAudioCallback_t callback;
callback=AudioStatus[channel].callback;
}
@@ -40,7 +46,8 @@
void pspAudioSetChannelCallback(int channel, pspAudioCallback_t callback, void *pdata)
{
- volatile psp_audio_channelinfo *pci = &AudioStatus[channel];
+ if(channel >= PSP_NUM_AUDIO_CHANNELS) return;
+ volatile psp_audio_channelinfo *pci = &AudioStatus[channel];
pci->callback=0;
pci->pdata=pdata;
pci->callback=callback;
@@ -52,16 +59,18 @@
if (channel>=PSP_NUM_AUDIO_CHANNELS) return -1;
if (vol1>PSP_VOLUME_MAX) vol1=PSP_VOLUME_MAX;
if (vol2>PSP_VOLUME_MAX) vol2=PSP_VOLUME_MAX;
- return sceAudioOutputPannedBlocking(AudioStatus[channel].handle,vol1,vol2,buf);
+ return sceAudio_E0727056(vol1,buf);
}
+static SceUID play_sema;
+
static int AudioChannelThread(int args, void *argp)
{
volatile int bufidx=0;
int channel=*(int *)argp;
-
+
while (audio_terminate==0) {
- void *bufptr=&audio_sndbuf[channel][bufidx];
+ void *bufptr=&audio_sndbuf[channel][bufidx];
pspAudioCallback_t callback;
callback=AudioStatus[channel].callback;
if (callback) {
@@ -71,8 +80,11 @@
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);
+// pspAudioOutBlocking(channel,AudioStatus[channel].volumeleft,AudioStatus[channel].volumeright,bufptr);
+ sceKernelWaitSema(play_sema, 1, 0);
+ sceAudio_E0727056(AudioStatus[0].volumeright,bufptr);
+ sceKernelSignalSema(play_sema, 1);
+ bufidx=(bufidx?0:1);
}
sceKernelExitThread(0);
return 0;
@@ -82,7 +94,30 @@
/******************************************************************************/
-
+int pspAudioSetFrequency(unsigned short freq)
+{
+ int ret = 0;
+ switch(freq) {
+ case 8000:
+ case 12000:
+ case 16000:
+ case 24000:
+ case 32000:
+ case 48000:
+ case 11025:
+ case 22050:
+ case 44100:
+ break;
+ default:
+ return -1;
+ }
+ sceKernelWaitSema(play_sema, 1, 0);
+ sceAudio_5C37C0AE();
+ if(sceAudio_38553111(PSP_NUM_AUDIO_SAMPLES,freq,2)<0) ret = -1;
+ sceKernelSignalSema(play_sema, 1);
+ return ret;
+}
+
int pspAudioInit()
{
@@ -93,6 +128,8 @@
audio_terminate=0;
audio_ready=0;
+ play_sema = sceKernelCreateSema("play_sema", 6, 1, 1, 0);
+
for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
AudioStatus[i].handle = -1;
AudioStatus[i].threadhandle = -1;
@@ -102,13 +139,14 @@
AudioStatus[i].pdata = 0;
}
for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
- if ((AudioStatus[i].handle = sceAudioChReserve(-1,PSP_NUM_AUDIO_SAMPLES,0))<0)
+ if(pspAudioSetFrequency(44100)<0)
failed=1;
}
if (failed) {
for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
if (AudioStatus[i].handle != -1)
- sceAudioChRelease(AudioStatus[i].handle);
+ //sceAudioChRelease(AudioStatus[i].handle);
+ sceAudio_5C37C0AE();
AudioStatus[i].handle = -1;
}
return -1;
@@ -169,7 +207,7 @@
for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
if (AudioStatus[i].handle != -1) {
- sceAudioChRelease(AudioStatus[i].handle);
+ sceAudio_5C37C0AE();
AudioStatus[i].handle = -1;
}
}
diff -ru ./pspaudiolib.h ../../src/pspaudiolib.h
--- ./pspaudiolib.h 2007-08-30 10:37:34.000000000 -0500
+++ ../../src/pspaudiolib.h 2007-09-03 09:52:06.093750000 -0500
@@ -19,7 +19,7 @@
#endif
//I need just one channel, more CPU free:
-#define PSP_NUM_AUDIO_CHANNELS 2
+#define PSP_NUM_AUDIO_CHANNELS 1
//#define PSP_NUM_AUDIO_CHANNELS 4
/** This is the number of frames you can update per callback, a frame being
@@ -48,6 +48,7 @@
void pspAudioChannelThreadCallback(int channel, void *buf, unsigned int reqn);
void pspAudioSetChannelCallback(int channel, pspAudioCallback_t callback, void *pdata);
int pspAudioOutBlocking(unsigned int channel, unsigned int vol1, unsigned int vol2, void *buf);
+int pspAudioSetFrequency(unsigned short freq);
#ifdef __cplusplus
}