Ejemplo n.º 1
0
/**
 * Handles feeding new data to a real time decompressed sound
 */
void FCoreAudioSoundSource::HandleRealTimeSource( void )
{
	// Get the next bit of streaming data
	const bool bLooped = ReadMorePCMData(1 - BufferInUse);

	// Have we reached the end of the compressed sound?
	if( bLooped )
	{
		switch( WaveInstance->LoopingMode )
		{
			case LOOP_Never:
				// Play out any queued buffers - once there are no buffers left, the state check at the beginning of IsFinished will fire
				bBuffersToFlush = true;
				break;
				
			case LOOP_WithNotification:
				// If we have just looped, and we are programmatically looping, send notification
				WaveInstance->NotifyFinished();
				break;
				
			case LOOP_Forever:
				// Let the sound loop indefinitely
				break;
		}
	}
}
Ejemplo n.º 2
0
// Requeues buffer to loop Sound Source
void FSLESSoundSource::OnRequeueBufferCallback( SLAndroidSimpleBufferQueueItf InQueueInterface ) 
{
	if (!bStreamedSound)
	{
		SLresult result = (*SL_PlayerBufferQueue)->Enqueue(SL_PlayerBufferQueue, Buffer->AudioData, Buffer->GetSize() );
		if(result != SL_RESULT_SUCCESS) 
		{ 
			UE_LOG( LogAndroidAudio, Warning, TEXT("FAILED OPENSL BUFFER Enqueue SL_PlayerBufferQueue (Requeing)"));  
		}
		bHasLooped = true;
	}
	else
	{
		// Sound decoding is complete, just waiting to finish playing
		if (bBuffersToFlush) return;

		// Enqueue the previously decoded buffer
		SLresult result = (*SL_PlayerBufferQueue)->Enqueue(SL_PlayerBufferQueue, AudioBuffers[BufferInUse].AudioData, AudioBuffers[BufferInUse].AudioDataSize );
		if(result != SL_RESULT_SUCCESS) 
		{ 
			UE_LOG( LogAndroidAudio, Warning, TEXT("FAILED OPENSL BUFFER Enqueue SL_PlayerBufferQueue (Requeing)"));  
		}

		// Switch to the next buffer and decode for the next time the callback fires
		BufferInUse = !BufferInUse;
		bHasLooped = ReadMorePCMData(BufferInUse);
	}
}
Ejemplo n.º 3
0
bool FSLESSoundSource::EnqueuePCMRTBuffer( bool bLoop )
{
	if (AudioBuffers[0].AudioData || AudioBuffers[1].AudioData)
	{
		UE_LOG( LogAndroidAudio, Warning, TEXT("Enqueue PCMRT with buffers already allocated"));
	}
	FMemory::Memzero( AudioBuffers, sizeof( SLESAudioBuffer ) * 2 );

	// Set up double buffer area to decompress to
	BufferSize = Buffer->GetRTBufferSize() * Buffer->NumChannels;

	AudioBuffers[0].AudioData = (uint8*)FMemory::Malloc(BufferSize);
	AudioBuffers[0].AudioDataSize = BufferSize;

	AudioBuffers[1].AudioData = (uint8*)FMemory::Malloc(BufferSize);
	AudioBuffers[1].AudioDataSize = BufferSize;

	// Decompress two buffers worth of data to fill up the queue
	ReadMorePCMData(0);
	ReadMorePCMData(1);

	SLresult result;

	// callback is used to submit and decompress next buffer
	result = (*SL_PlayerBufferQueue)->RegisterCallback(SL_PlayerBufferQueue, OpenSLBufferQueueCallback, (void*)this);
	
	// queue one sound buffer, as that is all Android will accept
	if(result == SL_RESULT_SUCCESS) 
	{
		result = (*SL_PlayerBufferQueue)->Enqueue(SL_PlayerBufferQueue, AudioBuffers[0].AudioData, AudioBuffers[0].AudioDataSize );
		if(result != SL_RESULT_SUCCESS) { UE_LOG( LogAndroidAudio, Fatal,TEXT("FAILED OPENSL BUFFER Enqueue SL_PlayerBufferQueue 0x%x params( %p, %d)"), result, Buffer->AudioData, int32(Buffer->GetSize())); return false;}
	}
	else
	{
		return false;
	}

	bStreamedSound = true;
	bHasLooped = false;
	bBuffersToFlush = false;
	BufferInUse = 1;
	return true;
}
Ejemplo n.º 4
0
/** 
 * Submit the relevant audio buffers to the system
 */
void FCoreAudioSoundSource::SubmitPCMRTBuffers( void )
{
	SCOPE_CYCLE_COUNTER( STAT_AudioSubmitBuffersTime );

	FMemory::Memzero( CoreAudioBuffers, sizeof( CoreAudioBuffer ) * 2 );

	bStreamedSound = true;

	// Set up double buffer area to decompress to
	CoreAudioBuffers[0].AudioData = ( uint8* )FMemory::Malloc( MONO_PCM_BUFFER_SIZE * Buffer->NumChannels );
	CoreAudioBuffers[0].AudioDataSize = MONO_PCM_BUFFER_SIZE * Buffer->NumChannels;

	CoreAudioBuffers[1].AudioData = ( uint8* )FMemory::Malloc( MONO_PCM_BUFFER_SIZE * Buffer->NumChannels );
	CoreAudioBuffers[1].AudioDataSize = MONO_PCM_BUFFER_SIZE * Buffer->NumChannels;

	NumActiveBuffers = 0;
	BufferInUse = 0;
	
	ReadMorePCMData(0);
	ReadMorePCMData(1);
}