Audio init problem

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
matkeupon
Posts: 26
Joined: Sat Jul 02, 2005 10:58 pm

Audio init problem

Post by matkeupon »

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: Select all

void updatesound(unsigned short *buf, unsigned int reqn) {
	int i, voix;
	int sample;
	int *buf32 = (int *)( (int)buf | 0x40000000);

	for&#40;i = 0; i < &#40;reqn >> 1&#41;; i++&#41; &#123;
		if&#40;mix&#91;0&#93;.son < mix&#91;0&#93;.finson&#41; &#123;
			sample = *mix&#91;0&#93;.son++;
		&#125; else sample = 0;
		for&#40;voix = 1; voix < nb_mix; voix++&#41; &#123;
			if&#40;mix&#91;voix&#93;.son < mix&#91;voix&#93;.finson&#41; sample += *mix&#91;voix&#93;.son++;
		&#125;

		sample >>= 2;
		if&#40;sample > 32767&#41; sample = 32767;
		if&#40;sample < -32768&#41; sample = -32768;
		sample |= &#40;sample << 16&#41;;
		*buf32++ = sample;
	&#125;
&#125;

static void audiothread&#40;void&#41; &#123;
	volatile int bufidx = 0;
	void *bufptr;
	
	for&#40;;;&#41; &#123;
		bufptr = &sbuffer&#91;bufidx&#93;;

		updatesound&#40;bufptr, sbufmid&#41;;

		sceAudioOutputBlocking&#40;audiohandle, 0x8000, bufptr&#41;;

		bufidx = 1 - bufidx;
	&#125;

	sceKernelExitThread&#40;0&#41;;
	return;
&#125;

void InitSound&#40;void&#41; &#123;
	audiohandle = sceAudioChReserve&#40;PSP_AUDIO_NEXT_CHANNEL, sbufmid, PSP_AUDIO_FORMAT_MONO&#41;;
	if&#40;audiohandle < 0&#41; return;

	audiothandle = sceKernelCreateThread&#40;"audiot01", &#40;void*&#41;&audiothread, 0x12, 0x10000, 0, NULL&#41;;
	if&#40;audiothandle < 0&#41; return;

	int a = sceKernelStartThread&#40;audiothandle, 0, NULL&#41;;
	if&#40;a != 0&#41; &#123;
		sceKernelDeleteThread&#40;audiothandle&#41;;
		audiothandle = -1;
	&#125;
&#125;
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 ?
Post Reply