Ejemplo n.º 1
0
int playerStart(char *path,pMalloc extern_malloc,pFree extern_free,	int(*callback)(int)){
	int ret,ch;MODFILE mod;
	if(!extern_malloc || !extern_free)return -1;
	if((ch=sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL,PSP_AUDIO_SAMPLE_ALIGN(768),PSP_AUDIO_FORMAT_STEREO))<0)return ch;
	myMalloc=extern_malloc;
	myFree	=extern_free;
	MODFILE_Init(&mod);
	if((ret=MODFILE_Load(path, &mod))<0)return ret;
	mod.musicvolume = 255;
	mod.sfxvolume = 255;
	mod.callback = NULL;//callback;
	MODFILE_Start(&mod);
	MODFILE_SetFormat(&mod, 44100, 2,16,1/*unsigned*/);
	SceCtrlData pad;
	sceCtrlSetSamplingCycle(0);
	sceCtrlSetSamplingMode(1);
	for(int i=0;;i++){
		sceCtrlReadBufferPositive(&pad,1);
		if(pad.Buttons&PSP_CTRL_START)break;
		mod.mixingbuf =(void*)out[i%2];
		mod.mixingbuflen = 768*2*2;
		MODFILE_Player(&mod);
		sceAudioOutputBlocking(ch, PSP_AUDIO_VOLUME_MAX,out[i%2]);
	}
	MODFILE_Stop(&mod);
	MODFILE_Free(&mod);
	sceAudioChRelease(ch);
	return 0;
}
Ejemplo n.º 2
0
static int
PSPAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
{
    int format, mixlen, i;
    this->hidden = (struct SDL_PrivateAudioData *)
        SDL_malloc(sizeof(*this->hidden));
    if (this->hidden == NULL) {
        return SDL_OutOfMemory();
    }
    SDL_zerop(this->hidden);
    switch (this->spec.format & 0xff) {
        case 8:
        case 16:
            this->spec.format = AUDIO_S16LSB;
            break;
        default:
            return SDL_SetError("Unsupported audio format");
    }

    /* The sample count must be a multiple of 64. */
    this->spec.samples = PSP_AUDIO_SAMPLE_ALIGN(this->spec.samples);
    this->spec.freq = 44100;

    /* Update the fragment size as size in bytes. */
    SDL_CalculateAudioSpec(&this->spec);

    /* Allocate the mixing buffer.  Its size and starting address must
       be a multiple of 64 bytes.  Our sample count is already a multiple of
       64, so spec->size should be a multiple of 64 as well. */
    mixlen = this->spec.size * NUM_BUFFERS;
    this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen);
    if (this->hidden->rawbuf == NULL) {
        return SDL_SetError("Couldn't allocate mixing buffer");
    }

    /* Setup the hardware channel. */
    if (this->spec.channels == 1) {
        format = PSP_AUDIO_FORMAT_MONO;
    } else {
        format = PSP_AUDIO_FORMAT_STEREO;
    }
    this->hidden->channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, this->spec.samples, format);
    if (this->hidden->channel < 0) {
        free(this->hidden->rawbuf);
        this->hidden->rawbuf = NULL;
        return SDL_SetError("Couldn't reserve hardware channel");
    }

    memset(this->hidden->rawbuf, 0, mixlen);
    for (i = 0; i < NUM_BUFFERS; i++) {
        this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size];
    }

    this->hidden->next_buffer = 0;
    return 0;
}
Ejemplo n.º 3
0
bool PspAudio::open(uint32 freq, uint32 numOfChannels, uint32 numOfSamples, callbackFunc callback, void *userData) {
	DEBUG_ENTER_FUNC();
	if (_init) {
		PSP_ERROR("audio device already initialized\n");
		return true;
	}

	PSP_DEBUG_PRINT("freq[%d], numOfChannels[%d], numOfSamples[%d], callback[%p], userData[%x]\n",
			freq, numOfChannels, numOfSamples, callback, (uint32)userData);

	numOfSamples = PSP_AUDIO_SAMPLE_ALIGN(numOfSamples);
	uint32 bufLen = numOfSamples * numOfChannels * NUM_BUFFERS * sizeof(uint16);

	PSP_DEBUG_PRINT("total buffer size[%d]\n", bufLen);

	_buffers[0] = (byte *)memalign(64, bufLen);
	if (!_buffers[0]) {
		PSP_ERROR("failed to allocate memory for audio buffers\n");
		return false;
	}
	memset(_buffers[0], 0, bufLen);	// clean the buffer

	// Fill in the rest of the buffer pointers
	byte *pBuffer = _buffers[0];
	for (int i = 1; i < NUM_BUFFERS; i++) {
		pBuffer += numOfSamples * numOfChannels * sizeof(uint16);
		_buffers[i] = pBuffer;
	}

	// Reserve a HW channel for our audio
	_pspChannel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, numOfSamples, numOfChannels == 2 ? PSP_AUDIO_FORMAT_STEREO : PSP_AUDIO_FORMAT_MONO);
	if (_pspChannel < 0) {
		PSP_ERROR("failed to reserve audio channel\n");
		return false;
	}

	PSP_DEBUG_PRINT("reserved channel[%d] for audio\n", _pspChannel);

	// Save our data
	_numOfChannels = numOfChannels;
	_numOfSamples = numOfSamples;
	_bufferSize = numOfSamples * numOfChannels * sizeof(uint16);	// should be the right size to send the app
	_callback = callback;
	_userData = userData;
	_bufferToFill = 0;
	_bufferToPlay = 0;

	_init = true;
	_paused = true;	// start in paused mode

	threadCreateAndStart("audioThread", PRIORITY_AUDIO_THREAD, STACK_AUDIO_THREAD);	// start the consumer thread

	return true;
}
Ejemplo n.º 4
0
static int SoundThread()
{
	int err=0;
	int sample_count;
	int chan;
	int realSampleCount;
	int buf = 0;

	//For SMS, we need tighter timings
	if (menuConfig.sound.perfectSynchro && gblMachineType == EM_SMS)
		sample_count = 128;
	else
		sample_count = snd.sample_rate/snd.fps;
	sample_count = PSP_AUDIO_SAMPLE_ALIGN(sample_count);
	realSampleCount = sample_count / (44100 / snd.sample_rate);
	chan = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, sample_count, PSP_AUDIO_FORMAT_STEREO);

	if(chan > 0 && sample_count > 0 && sample_count <= 2048)
	{
		for(; soundRunning; )
		{
			if (soundPause)
				memset(audioOut[buf], 0, sample_count * sizeof(sample_t));
			else
				StandardSoundProcess();

			//Game Boy: réglage du son ne fonctionne pas!
			AudioGet(audioOut[buf], sample_count, realSampleCount);
			sceAudioOutputBlocking(chan, PSP_AUDIO_VOLUME_MAX, (void*)audioOut[buf]);

			if (menuConfig.sound.perfectSynchro)
				buf = 1 - buf;
		}

		sceAudioChRelease(chan);
	}

	soundRunning = -1;
	sceKernelExitDeleteThread(0);
}