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 

Audio init problem

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



Joined: 02 Jul 2005
Posts: 26

PostPosted: Sat Jul 30, 2005 6:00 am    Post subject: Audio init problem Reply with quote

Hi,

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:
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;
   }
}


It almost work, but I don't really get what sceAudioOutputBlocking is doing (what does blocking mean ? does it wait for the previous buffer to be fully played before returning ? or does it return only when the specified buffer is finished ?
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