Exemplo n.º 1
0
FSLESSoundBuffer* FSLESSoundBuffer::Init(  FSLESAudioDevice* AudioDevice ,USoundWave* InWave )
{
	SCOPE_CYCLE_COUNTER( STAT_AudioResourceCreationTime );

	// Can't create a buffer without any source data
	if( InWave == NULL || InWave->NumChannels == 0 )
	{
		UE_LOG( LogAndroidAudio, Warning, TEXT("InitBuffer with Null sound data"));
		return( NULL );
	}
	
	FSLESSoundBuffer* Buffer = NULL;
	
	EDecompressionType DecompressionType = InWave->DecompressionType;

	switch( DecompressionType )
	{
	case DTYPE_Setup:
		// Has circumvented precache mechanism - precache now
		AudioDevice->Precache(InWave, true, false);

		// if it didn't change, we will recurse forever
		check(InWave->DecompressionType != DTYPE_Setup);

		// Recall this function with new decompression type
		return( Init( AudioDevice, InWave ) );
		break;

	case DTYPE_Native:
		// Upload entire wav
		if( InWave->ResourceID )
		{
			Buffer = static_cast<FSLESSoundBuffer*>(AudioDevice->WaveBufferMap.FindRef( InWave->ResourceID ));
		}

		if( Buffer == NULL )
		{
			Buffer = CreateNativeBuffer( AudioDevice, InWave );
		}
		break;

	case DTYPE_RealTime:
		// Always create a new buffer for streaming ogg vorbis data
		Buffer = CreateQueuedBuffer( AudioDevice, InWave );
		break;
	
	case DTYPE_Procedural:
		// New buffer for procedural data
		Buffer = CreateProceduralBuffer(AudioDevice, InWave);
		break;

	case DTYPE_Invalid:
	case DTYPE_Preview:
	default:
		UE_LOG( LogAndroidAudio, Warning, TEXT("Init Buffer on unsupported sound type name = %s type = %d"), *InWave->GetName(), int32(DecompressionType));
		break;
	}
	
	return Buffer;
}
Exemplo n.º 2
0
/**
 * Static function used to create a buffer.
 *
 * @param InWave USoundWave to use as template and wave source
 * @param AudioDevice audio device to attach created buffer to
 * @return FXAudio2SoundBuffer pointer if buffer creation succeeded, NULL otherwise
 */
FXAudio2SoundBuffer* FXAudio2SoundBuffer::Init( FAudioDevice* AudioDevice, USoundWave* Wave, bool bForceRealTime )
{
	// Can't create a buffer without any source data
	if( Wave == NULL || Wave->NumChannels == 0 )
	{
		return( NULL );
	}

	FAudioDeviceManager* AudioDeviceManager = GEngine->GetAudioDeviceManager();

	FXAudio2Device* XAudio2Device = ( FXAudio2Device* )AudioDevice;
	FXAudio2SoundBuffer* Buffer = NULL;

	// Allow the precache to happen if necessary
	EDecompressionType DecompressionType = Wave->DecompressionType;
	if (bForceRealTime && DecompressionType != DTYPE_Setup && DecompressionType != DTYPE_Streaming)
	{
		DecompressionType = DTYPE_RealTime;
	}

	switch( DecompressionType )
	{
	case DTYPE_Setup:
		// Has circumvented precache mechanism - precache now
		AudioDevice->Precache(Wave, true, false);

		// if it didn't change, we will recurse forever
		check(Wave->DecompressionType != DTYPE_Setup);

		// Recall this function with new decompression type
		return( Init( AudioDevice, Wave, bForceRealTime ) );

	case DTYPE_Preview:
		// Find the existing buffer if any
		if( Wave->ResourceID )
		{
			Buffer = (FXAudio2SoundBuffer*)AudioDeviceManager->GetSoundBufferForResourceID(Wave->ResourceID);
		}

		// Override with any new PCM data even if some already exists. 
		if( Wave->RawPCMData )
		{
			// Upload the preview PCM data to it
			Buffer = CreatePreviewBuffer( XAudio2Device, Wave, Buffer );
		}
		break;

	case DTYPE_Procedural:
		// Always create a new buffer for streaming procedural data
		Buffer = CreateProceduralBuffer( XAudio2Device, Wave );
		break;

	case DTYPE_RealTime:
		// Always create a new buffer for streaming ogg vorbis data
		Buffer = CreateQueuedBuffer( XAudio2Device, Wave );
		break;

	case DTYPE_Native:
	case DTYPE_Xenon:
		// Upload entire wav to XAudio2
		if( Wave->ResourceID )
		{
			Buffer = (FXAudio2SoundBuffer*)AudioDeviceManager->GetSoundBufferForResourceID(Wave->ResourceID);
		}

		if( Buffer == NULL )
		{
			Buffer = CreateNativeBuffer( XAudio2Device, Wave );
		}
		break;

	case DTYPE_Streaming:
		// Always create a new buffer for streaming sounds
		Buffer = CreateStreamingBuffer( XAudio2Device, Wave );
		break;

	case DTYPE_Invalid:
	default:
		// Invalid will be set if the wave cannot be played
		break;
	}

	return( Buffer );
}