Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap a few more getters for blueprints #60

Open
wants to merge 12 commits into
base: 2.01-UE4.26
Choose a base branch
from
12 changes: 12 additions & 0 deletions FMODStudio/Source/FMODStudio/Classes/FMODAudioComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,26 @@ class FMODSTUDIO_API UFMODAudioComponent : public USceneComponent
UFUNCTION(BlueprintCallable, Category = "Audio|FMOD|Components")
void SetVolume(float volume);

/** Gets the volume level. */
UFUNCTION(BlueprintCallable, Category = "Audio|FMOD|Components")
float GetVolume();

/** Sets the pitch multiplier. */
UFUNCTION(BlueprintCallable, Category = "Audio|FMOD|Components")
void SetPitch(float pitch);

/** Gets the pitch multiplier. */
UFUNCTION(BlueprintCallable, Category = "Audio|FMOD|Components")
float GetPitch();

/** Pause/Unpause an audio component. */
UFUNCTION(BlueprintCallable, Category = "Audio|FMOD|Components")
void SetPaused(bool paused);

/** Get Pause/Unpause state of an audio component. */
UFUNCTION(BlueprintCallable, Category = "Audio|FMOD|Components")
bool GetPaused();

/** Set a parameter of the Event. */
UFUNCTION(BlueprintCallable, Category = "Audio|FMOD|Components")
void SetParameter(FName Name, float Value);
Expand Down
8 changes: 7 additions & 1 deletion FMODStudio/Source/FMODStudio/Classes/FMODBlueprintStatics.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ class FMODSTUDIO_API UFMODBlueprintStatics : public UBlueprintFunctionLibrary
UFUNCTION(BlueprintCallable, Category = "Audio|FMOD|VCA", meta = (UnsafeDuringActorConstruction = "true"))
static void VCASetVolume(class UFMODVCA *Vca, float Volume);

/** Get volume on a VCA
* @param Vca - VCA to use
*/
UFUNCTION(BlueprintCallable, Category = "Audio|FMOD|VCA", meta = (UnsafeDuringActorConstruction = "true"))
static float VCAGetVolume(class UFMODVCA *Vca);

/** Set a global parameter from the System.
* @param Name - Name of parameter
* @param Value - Value of parameter
Expand Down Expand Up @@ -319,5 +325,5 @@ class FMODSTUDIO_API UFMODBlueprintStatics : public UBlueprintFunctionLibrary
/** Set the active locale for subsequent bank loads.
*/
UFUNCTION(BlueprintCallable, Category = "Audio|FMOD")
static void SetLocale(const FString& Locale);
static bool SetLocale(const FString& Locale);
};
88 changes: 62 additions & 26 deletions FMODStudio/Source/FMODStudio/Classes/FMODSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,42 @@ struct FFMODProjectLocale
bool bDefault;
};

USTRUCT()
struct FFMODPerPlatformConfig
{
GENERATED_USTRUCT_BODY()
/**
* Sample rate to use, or 0 to match system rate.
*/

UPROPERTY(config, EditAnywhere, Category = InitSettings)
int32 SampleRate = 48000;

/** Project Output Format, should match the mode set up for the Studio project. */
UPROPERTY(config, EditAnywhere, Category = Basic)
TEnumAsByte<EFMODSpeakerMode::Type> OutputFormat = EFMODSpeakerMode::Surround_5_1;

/**
* Whether to match hardware sample rate where reasonable (44.1kHz to 48kHz).
*/
UPROPERTY(config, EditAnywhere, Category = InitSettings)
bool bMatchHardwareSampleRate = true;

/**
* DSP mixer buffer length (eg. 512, 1024) or 0 for system default.
* When changing the Buffer Length, Buffer Count also needs to be set.
*/
UPROPERTY(config, EditAnywhere, Category = InitSettings)
int32 DSPBufferLength = 0;

/**
* DSP mixer buffer count (eg. 2, 4) or 0 for system default.
* When changing the Buffer Count, Buffer Length also needs to be set.
*/
UPROPERTY(config, EditAnywhere, Category = InitSettings)
int32 DSPBufferCount = 0;
};

UCLASS(config = Engine, defaultconfig)
class FMODSTUDIO_API UFMODSettings : public UObject
{
Expand Down Expand Up @@ -130,10 +166,6 @@ class FMODSTUDIO_API UFMODSettings : public UObject
UPROPERTY(config, EditAnywhere, Category = Basic, meta = (RelativeToGameContentDir))
FDirectoryPath BankOutputDirectory;

/** Project Output Format, should match the mode set up for the Studio project. */
UPROPERTY(config, EditAnywhere, Category = Basic)
TEnumAsByte<EFMODSpeakerMode::Type> OutputFormat;

/**
* Locales for localized banks. These should match the project locales configured in the FMOD Studio project.
*/
Expand All @@ -152,17 +184,23 @@ class FMODSTUDIO_API UFMODSettings : public UObject
UPROPERTY(config, EditAnywhere, Category = InitSettings)
float Vol0VirtualLevel;

/**
* Sample rate to use, or 0 to match system rate.
/**
* Scaling factor for doppler shift. Default = 1.0.
*/
UPROPERTY(config, EditAnywhere, Category = InitSettings)
int32 SampleRate;
UPROPERTY(config, EditAnywhere, Category = InitSettings)
float DopplerScale;

/**
* Whether to match hardware sample rate where reasonable (44.1kHz to 48kHz).
*/
UPROPERTY(config, EditAnywhere, Category = InitSettings)
bool bMatchHardwareSampleRate;
/**
* Relative distance factor to FMOD's units. Default = 1.0. (1.0 = 1 metre).
*/
UPROPERTY(config, EditAnywhere, Category = InitSettings)
float DistanceFactor;

/**
* Scaling factor for 3D sound rolloff or attenuation for FMOD_3D_INVERSEROLLOFF based sounds only (which is the default type). Default = 1.0.
*/
UPROPERTY(config, EditAnywhere, Category = InitSettings)
float RolloffScale;

/**
* Number of actual software voices that can be used at once.
Expand All @@ -176,19 +214,17 @@ class FMODSTUDIO_API UFMODSettings : public UObject
UPROPERTY(config, EditAnywhere, Category = InitSettings)
int32 TotalChannelCount;

/**
* DSP mixer buffer length (eg. 512, 1024) or 0 for system default.
* When changing the Buffer Length, Buffer Count also needs to be set.
*/
UPROPERTY(config, EditAnywhere, Category = InitSettings)
int32 DSPBufferLength;

/**
* DSP mixer buffer count (eg. 2, 4) or 0 for system default.
* When changing the Buffer Count, Buffer Length also needs to be set.
*/
UPROPERTY(config, EditAnywhere, Category = InitSettings)
int32 DSPBufferCount;
UPROPERTY(config, EditAnywhere, Category = PerPlatformSettings)
FFMODPerPlatformConfig DefaultPlatformSettings;

UPROPERTY(config, EditAnywhere, Category = PerPlatformSettings)
FFMODPerPlatformConfig XB1PlatformSettings;

UPROPERTY(config, EditAnywhere, Category = PerPlatformSettings)
FFMODPerPlatformConfig PS4PlatformSettings;

UPROPERTY(config, EditAnywhere, Category = PerPlatformSettings)
FFMODPerPlatformConfig SwitchPlatformSettings;

/**
* File buffer size in bytes (2048 by default).
Expand Down
39 changes: 39 additions & 0 deletions FMODStudio/Source/FMODStudio/Private/FMODAudioComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,19 @@ void UFMODAudioComponent::SetVolume(float Volume)
}
}

float UFMODAudioComponent::GetVolume()
{
if (!StudioInstance) return 0.0f;

float volume = 0.0f;
FMOD_RESULT Result = StudioInstance->getVolume(&volume);
if (Result != FMOD_OK)
{
UE_LOG(LogFMOD, Warning, TEXT("Failed to get volume"));
}
return volume;
}

void UFMODAudioComponent::SetPitch(float Pitch)
{
if (StudioInstance)
Expand All @@ -784,6 +797,19 @@ void UFMODAudioComponent::SetPitch(float Pitch)
}
}

float UFMODAudioComponent::GetPitch()
{
if (!StudioInstance) return 1.0f;

float pitch = 1.0f;
FMOD_RESULT Result = StudioInstance->getPitch(&pitch);
if (Result != FMOD_OK)
{
UE_LOG(LogFMOD, Warning, TEXT("Failed to get pitch"));
}
return pitch;
}

void UFMODAudioComponent::SetPaused(bool Paused)
{
if (StudioInstance)
Expand All @@ -796,6 +822,19 @@ void UFMODAudioComponent::SetPaused(bool Paused)
}
}

bool UFMODAudioComponent::GetPaused()
{
if (!StudioInstance) return false;

bool paused = false;
FMOD_RESULT Result = StudioInstance->getPaused(&paused);
if (Result != FMOD_OK)
{
UE_LOG(LogFMOD, Warning, TEXT("Failed to get paused"));
}
return paused;
}

void UFMODAudioComponent::SetParameter(FName Name, float Value)
{
if (StudioInstance)
Expand Down
27 changes: 25 additions & 2 deletions FMODStudio/Source/FMODStudio/Private/FMODBlueprintStatics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,29 @@ void UFMODBlueprintStatics::VCASetVolume(class UFMODVCA *Vca, float Volume)
}
}

float UFMODBlueprintStatics::VCAGetVolume(class UFMODVCA *Vca)
{
float volume = -1.0f;

FMOD::Studio::System *StudioSystem = IFMODStudioModule::Get().GetStudioSystem(EFMODSystemContext::Runtime);
if (StudioSystem != nullptr && IsValid(Vca))
{
FMOD::Studio::ID guid = FMODUtils::ConvertGuid(Vca->AssetGuid);
FMOD::Studio::VCA *vca = nullptr;
FMOD_RESULT result = StudioSystem->getVCAByID(&guid, &vca);
if (result == FMOD_OK && vca != nullptr)
{
vca->getVolume(&volume);
}
}
if (volume < 0.0f)
{
UE_LOG(LogFMOD, Warning, TEXT("Failed to get vca volume"));
volume = 0.0f;
}
return volume;
}

void UFMODBlueprintStatics::SetGlobalParameterByName(FName Name, float Value)
{
FMOD::Studio::System *StudioSystem = IFMODStudioModule::Get().GetStudioSystem(EFMODSystemContext::Runtime);
Expand Down Expand Up @@ -662,7 +685,7 @@ void UFMODBlueprintStatics::MixerResume()
}
}

void UFMODBlueprintStatics::SetLocale(const FString& Locale)
bool UFMODBlueprintStatics::SetLocale(const FString& Locale)
{
IFMODStudioModule::Get().SetLocale(Locale);
return IFMODStudioModule::Get().SetLocale(Locale);
}
7 changes: 3 additions & 4 deletions FMODStudio/Source/FMODStudio/Private/FMODSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,22 @@ UFMODSettings::UFMODSettings(const FObjectInitializer &ObjectInitializer)
{
MasterBankName = TEXT("Master");
BankOutputDirectory.Path = TEXT("FMOD");
OutputFormat = EFMODSpeakerMode::Surround_5_1;
ContentBrowserPrefix = TEXT("/Game/FMOD/");
bLoadAllBanks = true;
bLoadAllSampleData = false;
bEnableLiveUpdate = true;
bVol0Virtual = true;
Vol0VirtualLevel = 0.0001f;
DopplerScale = 1.0f;
DistanceFactor = 1.0f;
RolloffScale = 1.0f;
RealChannelCount = 64;
TotalChannelCount = 512;
DSPBufferLength = 0;
DSPBufferCount = 0;
FileBufferSize = 2048;
StudioUpdatePeriod = 0;
LiveUpdatePort = 9264;
EditorLiveUpdatePort = 9265;
ReloadBanksDelay = 5;
bMatchHardwareSampleRate = true;
bLockAllBuses = false;
}

Expand Down
Loading