forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

More audio functions

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
crazyc



Joined: 17 Jun 2005
Posts: 410

PostPosted: Thu Aug 09, 2007 6:20 am    Post subject: More audio functions Reply with quote

These functions bypass the software mixer (the mixer seems to have more then a little overhead) and (apparently) support an assortment of sample rates in hardware. I get a visible performance improvement by using them with a source stream at a sample rate of 22050. I don't know what will happen if you use them with the regular mixed audio functions.
Code:
int sceAudio_38553111(unsigned short samples, unsigned short freq, char)  // play with conversion?
                  // samples must be < 4112
                  // freq == {48000, 44100, 32000, 24000, 22050, 16000, 12000, 11050, 8000}
                  // the last param can only be 2, maybe number of channels?

int sceAudio_5C37C0AE(void)         // disable conversion?

int sceAudio_E0727056(int volume, void *buffer) // blocking output
                  // volume max is probably PSP_AUDIO_VOLUME_MAX but can be set to anything
Back to top
View user's profile Send private message
cooleyes



Joined: 18 May 2006
Posts: 125

PostPosted: Wed Sep 12, 2007 12:18 pm    Post subject: Reply with quote

good job!
thanks!
Back to top
View user's profile Send private message
crazyc



Joined: 17 Jun 2005
Posts: 410

PostPosted: Wed Sep 12, 2007 1:05 pm    Post subject: Reply with quote

Speaking of this, if the developer of LightMP3 reads this, I have a patch for you.
Back to top
View user's profile Send private message
mypspdev



Joined: 11 Jul 2007
Posts: 178

PostPosted: Wed Sep 12, 2007 6:25 pm    Post subject: Reply with quote

crazyc wrote:
Speaking of this, if the developer of LightMP3 reads this, I have a patch for you.

very interesting, thanks.
Some users here are involved in porting of Flite to PSP / SDK (Flite is text-to-speech, text-to-wave, file.txt-to-speech, file.txt-to-wave).
Output is 8khz or 16khz. Of course it's preferred 8khz: quality is ok, RAM involvement is less.
We could be interested on this way avoiding oversamplig loops.
Could anyone please explain some more on patch or better propose an example of how to output sounds using this approch.
Thanks
Back to top
View user's profile Send private message
TakutoKaneshiro



Joined: 07 Sep 2007
Posts: 4

PostPosted: Wed Sep 12, 2007 10:16 pm    Post subject: Reply with quote

Yes, Im too want to know more about these audio functions. Im currently doing port of one good PC game and have a problem with SDL sound.
Can somebody explain, how to link against those functions (they arent in PSPSDK, am I right?) and make use of them?

Is sceAudio_38553111(unsigned short samples, unsigned short freq, char) used for initializing sound engine?
And sceAudio_E0727056(int volume, void *buffer) must be called in in order to play buffer?
Back to top
View user's profile Send private message
crazyc



Joined: 17 Jun 2005
Posts: 410

PostPosted: Thu Sep 13, 2007 2:14 am    Post subject: Reply with quote

Here's the patch, it should explain how their used.
Code:
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
 }
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Thu Sep 13, 2007 4:30 am    Post subject: Reply with quote

Nice! For apps where you either only need one channel, or do the mixing yourself, this will be more useful than the regular audio lib. :)
Back to top
View user's profile Send private message AIM Address
crazyc



Joined: 17 Jun 2005
Posts: 410

PostPosted: Sat Oct 06, 2007 11:44 pm    Post subject: Reply with quote

In the 3.xx firmwares you have to wait until sceAudioOutput2GetRestSample returns 0 before calling sceAudio_5C37C0AE. Also sceAudioOutput2OutputBlocking only calls sceAudio_E0727056, sceAudioOutput2Release only calls sceAudio_5C37C0AE and
Code:

int sceAudioOutput2Reserve(int samples) {
 return sceAudio_38553111(samples, 44100, 2);
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group