コード例 #1
0
/**
 * Updates the source specific parameter like e.g. volume and pitch based on the associated
 * wave instance.	
 */
void FSLESSoundSource::Update( void )
{
	SCOPE_CYCLE_COUNTER( STAT_AudioUpdateSources );
	
	if( !WaveInstance || Paused )
	{
		return;
	}
	
	float Volume = WaveInstance->Volume * WaveInstance->VolumeMultiplier;
	if( SetStereoBleed() )
	{
		// Emulate the bleed to rear speakers followed by stereo fold down
		Volume *= 1.25f;
	}
	Volume *= GVolumeMultiplier;
	Volume = FMath::Clamp(Volume, 0.0f, MAX_VOLUME);
	
	const float Pitch = FMath::Clamp<float>(WaveInstance->Pitch, MIN_PITCH, MAX_PITCH);

	// Set whether to apply reverb
	SetReverbApplied(true);

	// Set the HighFrequencyGain value
	SetHighFrequencyGain();
	
	FVector Location;
	FVector	Velocity;
	
	// See file header for coordinate system explanation.
	Location.X = WaveInstance->Location.X;
	Location.Y = WaveInstance->Location.Z; // Z/Y swapped to match UE coordinate system
	Location.Z = WaveInstance->Location.Y; // Z/Y swapped to match UE coordinate system
	
	Velocity.X = WaveInstance->Velocity.X;
	Velocity.Y = WaveInstance->Velocity.Z; // Z/Y swapped to match UE coordinate system
	Velocity.Z = WaveInstance->Velocity.Y; // Z/Y swapped to match UE coordinate system
	
	// We're using a relative coordinate system for un- spatialized sounds.
	if( !WaveInstance->bUseSpatialization )
	{
		Location = FVector( 0.f, 0.f, 0.f );
	}
	
	// Set volume & Pitch
	// also Location & Velocity
	
	// Convert volume to millibels.
	SLmillibel MaxMillibel = 0;
	SLmillibel MinMillibel = -3000;
	(*SL_VolumeInterface)->GetMaxVolumeLevel( SL_VolumeInterface, &MaxMillibel );
	SLmillibel VolumeMillibel = (Volume * (MaxMillibel - MinMillibel)) + MinMillibel;
	VolumeMillibel = FMath::Clamp(VolumeMillibel, MinMillibel, MaxMillibel);
	
	SLresult result = (*SL_VolumeInterface)->SetVolumeLevel(SL_VolumeInterface, VolumeMillibel);
	check(SL_RESULT_SUCCESS == result);

}
コード例 #2
0
/**
 * Initializes a source with a given wave instance and prepares it for playback.
 *
 * @param	WaveInstance	wave instance being primed for playback
 * @return	true			if initialization was successful, false otherwise
 */
bool FCoreAudioSoundSource::Init( FWaveInstance* InWaveInstance )
{
	if (InWaveInstance->OutputTarget != EAudioOutputTarget::Controller)
	{
		// Find matching buffer.
		Buffer = FCoreAudioSoundBuffer::Init( AudioDevice, InWaveInstance->WaveData, InWaveInstance->StartTime > 0.f );
	
		// Buffer failed to be created, or there was an error with the compressed data
		if( Buffer && Buffer->NumChannels > 0 )
		{
			SCOPE_CYCLE_COUNTER( STAT_AudioSourceInitTime );
		
			WaveInstance = InWaveInstance;

			// Set whether to apply reverb
			SetReverbApplied( true );

			if (WaveInstance->StartTime > 0.f)
			{
				Buffer->Seek(WaveInstance->StartTime);
			}

			// Submit audio buffers
			switch( Buffer->SoundFormat )
			{
				case SoundFormat_PCM:
				case SoundFormat_PCMPreview:
					SubmitPCMBuffers();
					break;
				
				case SoundFormat_PCMRT:
					SubmitPCMRTBuffers();
					break;
			}

			// Initialization succeeded.
			return( true );
		}
	}
	
	// Initialization failed.
	return false;
}