Exemple #1
0
int main(int argc, char *argv[]) {
	char *at3_data;
	int at3_size;

	char *decode_data;
	int decode_size;
	int n;

	FILE *file;

	int atracID;
	int maxSamples = 0;
	int result;
	int channel;
	
	u32 puiPosition;
	u32 puiDataByte;
	
	if ((file = fopen("sample.at3", "rb")) != NULL) {
		fseek(file, 0, SEEK_END);
		at3_size = ftell(file);
		
		fseek(file, 0, SEEK_SET);
		
		at3_data = malloc(at3_size);
		decode_data = malloc(decode_size = 512 * 1024);
		memset(at3_data, 0, at3_size);
		memset(decode_data, 0, decode_size);
		
		fread(at3_data, at3_size, 1, file);

		fclose(file);
	}

	pspSdkLoadStartModule("flash0:/kd/audiocodec.prx", PSP_MEMORY_PARTITION_KERNEL);
	pspSdkLoadStartModule("flash0:/kd/libatrac3plus.prx", PSP_MEMORY_PARTITION_KERNEL);
	
	printf("at3: %08X, %08X\n", (unsigned int)at3_data, at3_size);
	printf("Header: %s\n", (char *)at3_data);
		
	atracID = sceAtracSetDataAndGetID(at3_data, at3_size);
	
	result = sceAtracSetLoopNum(atracID, 2);
	printf("sceAtracSetLoopNum: %08X\n", result);

	printf("sceAtracSetDataAndGetID: %08X\n", atracID);
	
	result = sceAtracGetMaxSample(atracID, &maxSamples);
	printf("sceAtracGetMaxSample: %08X, %d\n", result, maxSamples);
	
	channel = sceAudioChReserve(0, maxSamples, PSP_AUDIO_FORMAT_STEREO);
	
	result = sceAtracGetSecondBufferInfo(atracID, &puiPosition, &puiDataByte);
	printf("sceAtracGetSecondBufferInfo: %08X, %u, %u\n", result, (unsigned int)puiPosition, (unsigned int)puiDataByte);
	
	int end = 0;
	int steps = 0;
	while (!end) {
		//int remainFrame = -1;
		int remainFrame = 0;
		//int decodeBufferPosition = 0;
		int samples = 0;
		int nextSample = 0;
		u32 nextPosition = 0;
		
		if (steps < 4) {
			result = sceAtracGetNextSample(atracID, &nextSample);
			printf("sceAtracGetNextSample(%d): %d\n", result, nextSample);
			result = sceAtracGetNextDecodePosition(atracID, &nextPosition);
			printf("sceAtracGetNextDecodePosition(%d): %u\n", result, (unsigned int)nextPosition);
		}

		result = sceAtracDecodeData(atracID, (u16 *)decode_data, &samples, &end, &remainFrame);
		
		if (steps < 4) {
			
		}
		
		sceAudioSetChannelDataLen(channel, samples);
		sceAudioOutputBlocking(channel, 0x8000, decode_data);
		
		result = sceAtracGetRemainFrame(atracID, &remainFrame);

		if (steps < 4) {
			printf("sceAtracDecodeData: %08X, at3_size: %d, decode_size: %d, samples: %d, end: %d, remainFrame: %d\n\n", result, at3_size, decode_size, samples, end, remainFrame);
			if (steps == 1) {
				for (n = 0; n < 32; n++) printf("%04X ", (u16)decode_data[n]);
			}
			printf("sceAtracGetRemainFrame: %08X\n", result);
		}

		steps++;
	}
	
	sceAudioChRelease(channel);
	result = sceAtracReleaseAtracID(atracID);
	printf("sceAtracGetRemainFrame: %08X\n", result);

	return 0;
}
Exemple #2
0
SceInt32 CPMFPlayer::InitAudio()
{
	int i = 0, fail = 0;

	Audio.m_AudioChannel = sceAudioChReserve(-1, 512, PSP_AUDIO_FORMAT_STEREO);
	if(Audio.m_AudioChannel < 0)
	{
		sprintf(m_LastError, "sceAudioChReserve() failed: 0x%08X", (int)Audio.m_AudioChannel);
		return -1;
	}

	sceAudioSetChannelDataLen(Audio.m_AudioChannel, m_MpegAtracOutSize / 4);

	Audio.m_ThreadID = sceKernelCreateThread("audio_thread", T_Audio, 0x3D, 0x10000, PSP_THREAD_ATTR_USER, NULL);
	if(Audio.m_ThreadID < 0)
	{
		sprintf(m_LastError, "sceKernelCreateThread() failed: 0x%08X", (int)Audio.m_ThreadID);
		goto exit0;
	}

	Audio.m_SemaphoreStart = sceKernelCreateSema("audio_start_sema",  0, 0, 1, NULL);
	if(Audio.m_SemaphoreStart < 0)
	{
		sprintf(m_LastError, "sceKernelCreateSema() failed: 0x%08X", (int)Audio.m_SemaphoreStart);
		goto exit1;
	}

	Audio.m_SemaphoreLock = sceKernelCreateSema("audio_lock_sema",  0, 1, 1, NULL);
	if(Audio.m_SemaphoreLock	< 0 )
	{
		sprintf(m_LastError, "sceKernelCreateSema() failed: 0x%08X", (int)Audio.m_SemaphoreLock);
		goto exit2;
	}

	Audio.m_iNumBuffers			= 4;
	Audio.m_iFullBuffers		= 0;
	Audio.m_iPlayBuffer			= 1;
	Audio.m_iDecodeBuffer		= 0;
	Audio.m_iAbort				= 0;
	Audio.m_LastError			= m_LastError;

	for(i = 0; i < Audio.m_iNumBuffers; i++)
	{
		Audio.m_pAudioBuffer[i] = NULL;
		Audio.m_iBufferTimeStamp[i] = 0;
	}

	for(i = 0; i < Audio.m_iNumBuffers; i++)
	{
		Audio.m_pAudioBuffer[i] = memalign(64, m_MpegAtracOutSize);
		if(Audio.m_pAudioBuffer[i] < 0) fail++;
	}

	if(fail > 0)
	{
		for(i = 0; i < Audio.m_iNumBuffers; i++)
		{
			if(Audio.m_pAudioBuffer[i] != NULL)
				free(Audio.m_pAudioBuffer[i]);
		}

		sprintf(m_LastError, "malloc() failed!");
		goto exit3;
	}

	return 0;

exit3:
	sceKernelDeleteSema(Audio.m_SemaphoreLock);
exit2:
	sceKernelDeleteSema(Audio.m_SemaphoreStart);
exit1:
	sceKernelDeleteThread(Audio.m_ThreadID);
exit0:
	sceAudioChRelease(Audio.m_AudioChannel);

	return -1;
}