Ejemplo n.º 1
1
/**
 * Static function used to create an OpenAL buffer and upload decompressed ogg vorbis data to.
 *
 * @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::CreateNativeBuffer( FXAudio2Device* XAudio2Device, USoundWave* Wave )
{
	// Check to see if thread has finished decompressing on the other thread
	if( Wave->AudioDecompressor != NULL )
	{
		Wave->AudioDecompressor->EnsureCompletion();

		// Remove the decompressor
		delete Wave->AudioDecompressor;
		Wave->AudioDecompressor = NULL;
	}

	// Create new buffer.
	FXAudio2SoundBuffer* Buffer = new FXAudio2SoundBuffer( XAudio2Device, SoundFormat_PCM );

	// Take ownership the PCM data
	Buffer->PCM.PCMData = Wave->RawPCMData;
	Buffer->PCM.PCMDataSize = Wave->RawPCMDataSize;

	Wave->RawPCMData = NULL;

	// Keep track of associated resource name.
	Buffer->InitWaveFormatEx( WAVE_FORMAT_PCM, Wave, true );

	FAudioDeviceManager* AudioDeviceManager = GEngine->GetAudioDeviceManager();
	check(AudioDeviceManager != nullptr);
	AudioDeviceManager->TrackResource(Wave, Buffer);

	Wave->RemoveAudioResource();

	return( Buffer );
}
Ejemplo n.º 2
0
FXAudio2SoundBuffer* FXAudio2SoundBuffer::CreateStreamingBuffer( FXAudio2Device* XAudio2Device, USoundWave* Wave )
{
	// Always create a new buffer for streaming sounds
	FXAudio2SoundBuffer* Buffer = new FXAudio2SoundBuffer(XAudio2Device, SoundFormat_Streaming);

	// Prime the first two buffers and prepare the decompression
	FSoundQualityInfo QualityInfo = { 0 };

	Buffer->DecompressionState = XAudio2Device->CreateCompressedAudioInfo(Wave);

	if (Buffer->DecompressionState->StreamCompressedInfo(Wave, &QualityInfo))
	{
		// Refresh the wave data
		Wave->SampleRate = QualityInfo.SampleRate;
		Wave->NumChannels = QualityInfo.NumChannels;
		Wave->RawPCMDataSize = QualityInfo.SampleDataSize;
		Wave->Duration = QualityInfo.Duration;

		// Clear out any dangling pointers
		Buffer->PCM.PCMData = NULL;
		Buffer->PCM.PCMDataSize = 0;

		Buffer->InitWaveFormatEx(WAVE_FORMAT_PCM, Wave, false);
	}
	else
	{
		Wave->DecompressionType = DTYPE_Invalid;
		Wave->NumChannels = 0;

		Wave->RemoveAudioResource();
	}

	return(Buffer);
}
/**
 * Static function used to create an OpenAL buffer and dynamically upload decompressed ogg vorbis data to.
 *
 * @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::CreateQueuedBuffer( FXAudio2Device* XAudio2Device, USoundWave* Wave )
{
	check(XAudio2Device);
	check(Wave);

	// Check to see if thread has finished decompressing on the other thread
	if( Wave->AudioDecompressor != nullptr )
	{
		Wave->AudioDecompressor->EnsureCompletion();

		// Remove the decompressor
		delete Wave->AudioDecompressor;
		Wave->AudioDecompressor = nullptr;
	}

	// Always create a new buffer for real time decompressed sounds
	FXAudio2SoundBuffer* Buffer = new FXAudio2SoundBuffer( XAudio2Device, SoundFormat_PCMRT );

	// If the buffer was precached as native, the resource data will have been lost and we need to re-initialize it
	if (Wave->ResourceData == nullptr)
	{
		Wave->InitAudioResource(XAudio2Device->GetRuntimeFormat(Wave));
	}

	Buffer->DecompressionState = XAudio2Device->CreateCompressedAudioInfo(Wave);

	if (Buffer->DecompressionState)
	{
		// Start the async task that parses the decompressed asset header info
		// Doing this step synchronously causes huge main-thread hitches for large ogg-vorbis files
		check(Buffer->RealtimeAsyncHeaderParseTask == nullptr);
		Buffer->RealtimeAsyncHeaderParseTask = new FAsyncRealtimeAudioTask(Buffer, Wave);
		Buffer->RealtimeAsyncHeaderParseTask->StartBackgroundTask();

		// Clear out any dangling pointers
		Buffer->PCM.PCMData = NULL;
		Buffer->PCM.PCMDataSize = 0;

		Buffer->InitWaveFormatEx( WAVE_FORMAT_PCM, Wave, false );
	}
	else
	{
		Wave->DecompressionType = DTYPE_Invalid;
		Wave->NumChannels = 0;

		Wave->RemoveAudioResource();
	}

	return Buffer;
}
Ejemplo n.º 4
0
/**
 * Static function used to create an OpenAL buffer and dynamically upload procedural data to.
 *
 * @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::CreateProceduralBuffer( FXAudio2Device* XAudio2Device, USoundWave* Wave )
{
	// Always create a new buffer for real time decompressed sounds
	FXAudio2SoundBuffer* Buffer = new FXAudio2SoundBuffer( XAudio2Device, SoundFormat_PCMRT );

	// Clear out any dangling pointers
	Buffer->DecompressionState = NULL;
	Buffer->PCM.PCMData = NULL;
	Buffer->PCM.PCMDataSize = 0;
	Buffer->InitWaveFormatEx( WAVE_FORMAT_PCM, Wave, false );

	// No tracking of this resource as it's temporary
	Buffer->ResourceID = 0;
	Wave->ResourceID = 0;

	return( Buffer );
}
Ejemplo n.º 5
0
/**
 * Static function used to create an OpenAL buffer and dynamically upload decompressed ogg vorbis data to.
 *
 * @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::CreateQueuedBuffer( FXAudio2Device* XAudio2Device, USoundWave* Wave )
{
	// Check to see if thread has finished decompressing on the other thread
	if( Wave->AudioDecompressor != nullptr )
	{
		Wave->AudioDecompressor->EnsureCompletion();

		// Remove the decompressor
		delete Wave->AudioDecompressor;
		Wave->AudioDecompressor = nullptr;
	}

	// Always create a new buffer for real time decompressed sounds
	FXAudio2SoundBuffer* Buffer = new FXAudio2SoundBuffer( XAudio2Device, SoundFormat_PCMRT );

	// Prime the first two buffers and prepare the decompression
	FSoundQualityInfo QualityInfo = { 0 };

	Buffer->DecompressionState = XAudio2Device->CreateCompressedAudioInfo(Wave);

	if (Buffer->DecompressionState && Buffer->DecompressionState->ReadCompressedInfo(Wave->ResourceData, Wave->ResourceSize, &QualityInfo))
	{
		// Clear out any dangling pointers
		Buffer->PCM.PCMData = NULL;
		Buffer->PCM.PCMDataSize = 0;

		Buffer->InitWaveFormatEx( WAVE_FORMAT_PCM, Wave, false );
	}
	else
	{
		Wave->DecompressionType = DTYPE_Invalid;
		Wave->NumChannels = 0;

		Wave->RemoveAudioResource();
	}

	return Buffer;
}