Refactor audio clip import settings to use auto-generated bindings via AudioTool
This commit is contained in:
@@ -1,14 +1,49 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
#if COMPILE_WITH_AUDIO_TOOL
|
||||
|
||||
#include "AudioTool.h"
|
||||
#include "Engine/Core/Core.h"
|
||||
#include "Engine/Core/Memory/Allocation.h"
|
||||
#if USE_EDITOR
|
||||
#include "Engine/Serialization/Serialization.h"
|
||||
#include "Engine/Scripting/Enums.h"
|
||||
#endif
|
||||
|
||||
#define CONVERT_TO_MONO_AVG 1
|
||||
#if !CONVERT_TO_MONO_AVG
|
||||
#include "Engine/Core/Math/Math.h"
|
||||
#endif
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
String AudioTool::Options::ToString() const
|
||||
{
|
||||
return String::Format(TEXT("Format:{}, DisableStreaming:{}, Is3D:{}, Quality:{}, BitDepth:{}"), ScriptingEnum::ToString(Format), DisableStreaming, Is3D, Quality, (int32)BitDepth);
|
||||
}
|
||||
|
||||
void AudioTool::Options::Serialize(SerializeStream& stream, const void* otherObj)
|
||||
{
|
||||
SERIALIZE_GET_OTHER_OBJ(AudioTool::Options);
|
||||
|
||||
SERIALIZE(Format);
|
||||
SERIALIZE(DisableStreaming);
|
||||
SERIALIZE(Is3D);
|
||||
SERIALIZE(Quality);
|
||||
SERIALIZE(BitDepth);
|
||||
}
|
||||
|
||||
void AudioTool::Options::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
|
||||
{
|
||||
DESERIALIZE(Format);
|
||||
DESERIALIZE(DisableStreaming);
|
||||
DESERIALIZE(Is3D);
|
||||
DESERIALIZE(Quality);
|
||||
DESERIALIZE(BitDepth);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void ConvertToMono8(const int8* input, uint8* output, uint32 numSamples, uint32 numChannels)
|
||||
{
|
||||
for (uint32 i = 0; i < numSamples; i++)
|
||||
@@ -277,3 +312,5 @@ void AudioTool::ConvertFromFloat(const float* input, int32* output, uint32 numSa
|
||||
input++;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,16 +2,85 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if COMPILE_WITH_AUDIO_TOOL
|
||||
|
||||
#include "Engine/Core/Config.h"
|
||||
#include "Engine/Core/Types/BaseTypes.h"
|
||||
#if USE_EDITOR
|
||||
#include "Engine/Core/ISerializable.h"
|
||||
#endif
|
||||
#include "Engine/Audio/Types.h"
|
||||
|
||||
/// <summary>
|
||||
/// Audio data importing and processing utilities.
|
||||
/// </summary>
|
||||
class FLAXENGINE_API AudioTool
|
||||
API_CLASS(Namespace="FlaxEngine.Tools", Static) class FLAXENGINE_API AudioTool
|
||||
{
|
||||
public:
|
||||
DECLARE_SCRIPTING_TYPE_MINIMAL(AudioTool);
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Declares the imported audio clip bit depth.
|
||||
/// </summary>
|
||||
API_ENUM(Attributes="HideInEditor") enum class BitDepth : int32
|
||||
{
|
||||
// 8-bits per sample.
|
||||
_8 = 8,
|
||||
// 16-bits per sample.
|
||||
_16 = 16,
|
||||
// 24-bits per sample.
|
||||
_24 = 24,
|
||||
// 32-bits per sample.
|
||||
_32 = 32,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Audio import options.
|
||||
/// </summary>
|
||||
API_STRUCT(Attributes="HideInEditor") struct FLAXENGINE_API Options : public ISerializable
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_MINIMAL(Options);
|
||||
|
||||
/// <summary>
|
||||
/// The audio data format to import the audio clip as.
|
||||
/// </summary>
|
||||
API_FIELD(Attributes="EditorOrder(10)")
|
||||
AudioFormat Format = AudioFormat::Vorbis;
|
||||
|
||||
/// <summary>
|
||||
/// The audio data compression quality. Used only if target format is using compression. Value 0 means the smallest size, value 1 means the best quality.
|
||||
/// </summary>
|
||||
API_FIELD(Attributes="EditorOrder(20), EditorDisplay(null, \"Compression Quality\"), Limit(0, 1, 0.01f)")
|
||||
float Quality = 0.4f;
|
||||
|
||||
/// <summary>
|
||||
/// Disables dynamic audio streaming. The whole clip will be loaded into the memory. Useful for small clips (eg. gunfire sounds).
|
||||
/// </summary>
|
||||
API_FIELD(Attributes="EditorOrder(30)")
|
||||
bool DisableStreaming = false;
|
||||
|
||||
/// <summary>
|
||||
/// Checks should the clip be played as spatial (3D) audio or as normal audio. 3D audio is stored in Mono format.
|
||||
/// </summary>
|
||||
API_FIELD(Attributes="EditorOrder(40), EditorDisplay(null, \"Is 3D\")")
|
||||
bool Is3D = false;
|
||||
|
||||
/// <summary>
|
||||
/// The size of a single sample in bits. The clip will be converted to this bit depth on import.
|
||||
/// </summary>
|
||||
API_FIELD(Attributes="EditorOrder(50), VisibleIf(nameof(ShowBtiDepth))")
|
||||
BitDepth BitDepth = BitDepth::_16;
|
||||
|
||||
String ToString() const;
|
||||
|
||||
// [ISerializable]
|
||||
void Serialize(SerializeStream& stream, const void* otherObj) override;
|
||||
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
|
||||
};
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Converts a set of audio samples using multiple channels into a set of mono samples.
|
||||
/// </summary>
|
||||
@@ -58,4 +127,7 @@ public:
|
||||
{
|
||||
return (input[2] << 24) | (input[1] << 16) | (input[0] << 8);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user