コード例 #1
0
ファイル: audio.cpp プロジェクト: MatChung/scummvm-ps3
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;
}
コード例 #2
0
ファイル: display_manager.cpp プロジェクト: danzat/scummvm
void MasterGuRenderer::setupCallbackThread() {
	DEBUG_ENTER_FUNC();

	// start the thread that updates the display
	threadCreateAndStart("DisplayCbThread", PRIORITY_DISPLAY_THREAD, STACK_DISPLAY_THREAD);
}