Skip to content

Commit

Permalink
fix: Improve Amplitude integration in other tools.
Browse files Browse the repository at this point in the history
- Added methods to manually register and unregister default plugins to the engine.
- Set the `AM_SDK_PATH` env var to be the direct path to the SDK, and not the parent directory.
- Added include files in generated CMake config.
  • Loading branch information
na2axl committed Mar 6, 2024
1 parent af0cd22 commit 5ef42f5
Show file tree
Hide file tree
Showing 36 changed files with 303 additions and 134 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ docs/html/
docs/linklint_results/
docs/resources/_gen/
docs/.hugo_build.lock
docs/node_modules/
gen/
.DS_Store

Expand Down
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,6 @@ foreach(build_type ${AM_BUILDSYSTEM_TYPE})
target_link_libraries(${build_type}
PRIVATE
flatbuffers::flatbuffers SampleRate::samplerate xsimd
PUBLIC
mimalloc-static
)

add_dependencies(${build_type}
Expand All @@ -402,6 +400,9 @@ foreach(build_type ${AM_BUILDSYSTEM_TYPE})
endif()
endforeach()

target_link_libraries(Static PUBLIC mimalloc-static)
target_link_libraries(Shared PUBLIC mimalloc)

add_subdirectory(tools/amac)

if(BUILD_SAMPLES)
Expand All @@ -415,6 +416,7 @@ install(
TARGETS Static
EXPORT AmplitudeAudioSDKConfig
ARCHIVE DESTINATION ${AM_LIB_DESTINATION}/static
INCLUDES DESTINATION ${AM_INC_DESTINATION}
)

install(
Expand All @@ -423,8 +425,14 @@ install(
ARCHIVE DESTINATION ${AM_LIB_DESTINATION}/shared
LIBRARY DESTINATION ${AM_LIB_DESTINATION}/shared
RUNTIME DESTINATION ${AM_LIB_DESTINATION}/shared
INCLUDES DESTINATION ${AM_INC_DESTINATION}
)

install(
FILES $<TARGET_RUNTIME_DLLS:Shared>
DESTINATION ${AM_LIB_DESTINATION}/shared
)

install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${AM_INC_DESTINATION}
Expand Down
17 changes: 9 additions & 8 deletions cmake/FindAmplitudeAudioSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ if(NOT found_sdk)
endif()

message(STATUS "Using Amplitude Audio SDK at ${AM_SDK_PATH}")
set(AmplitudeAudioSDK_FOUND TRUE)

set(AMPLITUDE_COMPILE_DEFINITIONS
$<IF:$<CONFIG:Release>,AMPLITUDE_NO_ASSERTS,>
Expand Down Expand Up @@ -91,17 +92,17 @@ endif()

add_library(SparkyStudios::Audio::Amplitude::SDK::Static STATIC IMPORTED GLOBAL)
set_target_properties(SparkyStudios::Audio::Amplitude::SDK::Static PROPERTIES
IMPORTED_LOCATION "${AM_SDK_PATH}/sdk/lib/${AMPLITUDE_LIB_OS}/static/${AMPLITUDE_STATIC_LIB_NAME}"
IMPORTED_LOCATION_DEBUG "${AM_SDK_PATH}/sdk/lib/${AMPLITUDE_LIB_OS}/static/${AMPLITUDE_STATIC_LIB_NAME_DEBUG}"
INTERFACE_INCLUDE_DIRECTORIES "${AM_SDK_PATH}/sdk/include"
IMPORTED_LOCATION "${AM_SDK_PATH}/lib/${AMPLITUDE_LIB_OS}/static/${AMPLITUDE_STATIC_LIB_NAME}"
IMPORTED_LOCATION_DEBUG "${AM_SDK_PATH}/lib/${AMPLITUDE_LIB_OS}/static/${AMPLITUDE_STATIC_LIB_NAME_DEBUG}"
INTERFACE_INCLUDE_DIRECTORIES "${AM_SDK_PATH}/include"
INTERFACE_COMPILE_DEFINITIONS "AM_BUILDSYSTEM_STATIC"
)

add_library(SparkyStudios::Audio::Amplitude::SDK::Shared SHARED IMPORTED GLOBAL)
set_target_properties(SparkyStudios::Audio::Amplitude::SDK::Shared PROPERTIES
IMPORTED_LOCATION "${AM_SDK_PATH}/sdk/lib/${AMPLITUDE_LIB_OS}/shared/${AMPLITUDE_SHARED_LIB_NAME}"
IMPORTED_LOCATION_DEBUG "${AM_SDK_PATH}/sdk/lib/${AMPLITUDE_LIB_OS}/shared/${AMPLITUDE_SHARED_LIB_NAME_DEBUG}"
INTERFACE_INCLUDE_DIRECTORIES "${AM_SDK_PATH}/sdk/include"
IMPORTED_LOCATION "${AM_SDK_PATH}/lib/${AMPLITUDE_LIB_OS}/shared/${AMPLITUDE_SHARED_LIB_NAME}"
IMPORTED_LOCATION_DEBUG "${AM_SDK_PATH}/lib/${AMPLITUDE_LIB_OS}/shared/${AMPLITUDE_SHARED_LIB_NAME_DEBUG}"
INTERFACE_INCLUDE_DIRECTORIES "${AM_SDK_PATH}/include"
INTERFACE_COMPILE_DEFINITIONS "AM_BUILDSYSTEM_SHARED"
)

Expand All @@ -112,7 +113,7 @@ if(WIN32)
endif()

set_target_properties(SparkyStudios::Audio::Amplitude::SDK::Shared PROPERTIES
IMPORTED_IMPLIB "${AM_SDK_PATH}/sdk/lib/${AMPLITUDE_LIB_OS}/shared/${AMPLITUDE_STATIC_LIB_NAME}"
IMPORTED_IMPLIB_DEBUG "${AM_SDK_PATH}/sdk/lib/${AMPLITUDE_LIB_OS}/shared/${AMPLITUDE_STATIC_LIB_NAME_DEBUG}"
IMPORTED_IMPLIB "${AM_SDK_PATH}/lib/${AMPLITUDE_LIB_OS}/shared/${AMPLITUDE_STATIC_LIB_NAME}"
IMPORTED_IMPLIB_DEBUG "${AM_SDK_PATH}/lib/${AMPLITUDE_LIB_OS}/shared/${AMPLITUDE_STATIC_LIB_NAME_DEBUG}"
)
endif()
10 changes: 10 additions & 0 deletions include/SparkyStudios/Audio/Amplitude/Core/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,16 @@ namespace SparkyStudios::Audio::Amplitude
*/
static void RemovePluginSearchPath(const AmOsString& path);

/**
* @brief Register all default plugins.
*/
static void RegisterDefaultPlugins();

/**
* @brief Unregister all default plugins.
*/
static void UnregisterDefaultPlugins();

#pragma endregion

/**
Expand Down
4 changes: 2 additions & 2 deletions scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@

# The Amplitude Audio SDK schemas directory.
SCHEMA_PATHS = [
os.path.join(SDK_PATH, "sdk", "schemas")
os.path.join(SDK_PATH, "schemas")
]

# Name of the flatbuffers executable.
FLATC = (shutil.which("flatc")
or os.path.join(SDK_PATH, "sdk", "bin", os.getenv("AM_SDK_PLATFORM") or "", "flatc"))
or os.path.join(SDK_PATH, "bin", os.getenv("AM_SDK_PLATFORM") or "", "flatc"))

# Directory where unprocessed sound flatbuffers data can be found.
SOUNDS_DIR_NAME = 'sounds'
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Codecs/AMS/Codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

using namespace SparkyStudios::Audio::Amplitude::Compression::ADPCM;

namespace SparkyStudios::Audio::Amplitude::Codecs
namespace SparkyStudios::Audio::Amplitude
{
static void little_endian_to_native(void* data, const char* format)
{
Expand Down Expand Up @@ -641,4 +641,4 @@ namespace SparkyStudios::Audio::Amplitude::Codecs
const auto& path = file->GetPath();
return path.find(AM_OS_STRING(".ams")) != AmOsString::npos;
}
} // namespace SparkyStudios::Audio::Amplitude::Codecs
} // namespace SparkyStudios::Audio::Amplitude
8 changes: 4 additions & 4 deletions src/Core/Codecs/AMS/Codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

#include <Utils/Audio/Compression/ADPCM/ADPCM.h>

namespace SparkyStudios::Audio::Amplitude::Codecs
namespace SparkyStudios::Audio::Amplitude
{
[[maybe_unused]] static class AMSCodec final : public Codec
class AMSCodec final : public Codec
{
public:
class AMSDecoder final : public Decoder
Expand Down Expand Up @@ -96,7 +96,7 @@ namespace SparkyStudios::Audio::Amplitude::Codecs
void DestroyEncoder(Encoder* encoder) override;

[[nodiscard]] bool CanHandleFile(std::shared_ptr<File> file) const override;
} ams_codec; // NOLINT(cert-err58-cpp)
} // namespace SparkyStudios::Audio::Amplitude::Codecs
};
} // namespace SparkyStudios::Audio::Amplitude

#endif // SS_AMPLITUDE_AUDIO_AMS_CODEC_H
4 changes: 2 additions & 2 deletions src/Core/Codecs/MP3/Codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include <Core/Codecs/MP3/Codec.h>

namespace SparkyStudios::Audio::Amplitude::Codecs
namespace SparkyStudios::Audio::Amplitude
{
static void* onMalloc(size_t sz, void* pUserData)
{
Expand Down Expand Up @@ -176,4 +176,4 @@ namespace SparkyStudios::Audio::Amplitude::Codecs
const auto& path = file->GetPath();
return path.find(AM_OS_STRING(".mp3")) != AmOsString::npos;
}
} // namespace SparkyStudios::Audio::Amplitude::Codecs
} // namespace SparkyStudios::Audio::Amplitude
8 changes: 4 additions & 4 deletions src/Core/Codecs/MP3/Codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

#include "dr_mp3.h"

namespace SparkyStudios::Audio::Amplitude::Codecs
namespace SparkyStudios::Audio::Amplitude
{
[[maybe_unused]] static class MP3Codec final : public Codec
class MP3Codec final : public Codec
{
public:
class MP3Decoder final : public Decoder
Expand Down Expand Up @@ -86,7 +86,7 @@ namespace SparkyStudios::Audio::Amplitude::Codecs
[[nodiscard]] bool CanHandleFile(std::shared_ptr<File> file) const override;

drmp3_allocation_callbacks m_allocationCallbacks;
} mp3_codec; // NOLINT(cert-err58-cpp)
} // namespace SparkyStudios::Audio::Amplitude::Codecs
};
} // namespace SparkyStudios::Audio::Amplitude

#endif // SS_AMPLITUDE_AUDIO_MP3_CODEC_H
4 changes: 2 additions & 2 deletions src/Core/Codecs/WAV/Codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include <Core/Codecs/WAV/Codec.h>

namespace SparkyStudios::Audio::Amplitude::Codecs
namespace SparkyStudios::Audio::Amplitude
{
static void* onMalloc(size_t sz, void* pUserData)
{
Expand Down Expand Up @@ -222,4 +222,4 @@ namespace SparkyStudios::Audio::Amplitude::Codecs
const auto& path = file->GetPath();
return path.find(AM_OS_STRING(".wav")) != AmOsString::npos;
}
} // namespace SparkyStudios::Audio::Amplitude::Codecs
} // namespace SparkyStudios::Audio::Amplitude
8 changes: 4 additions & 4 deletions src/Core/Codecs/WAV/Codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

#include "dr_wav.h"

namespace SparkyStudios::Audio::Amplitude::Codecs
namespace SparkyStudios::Audio::Amplitude
{
[[maybe_unused]] static class WAVCodec final : public Codec
class WAVCodec final : public Codec
{
public:
class WAVDecoder final : public Decoder
Expand Down Expand Up @@ -92,7 +92,7 @@ namespace SparkyStudios::Audio::Amplitude::Codecs
[[nodiscard]] bool CanHandleFile(std::shared_ptr<File> file) const override;

drwav_allocation_callbacks m_allocationCallbacks;
} wav_codec; // NOLINT(cert-err58-cpp)
} // namespace SparkyStudios::Audio::Amplitude::Codecs
};
} // namespace SparkyStudios::Audio::Amplitude

#endif // SS_AMPLITUDE_AUDIO_WAV_CODEC_H
15 changes: 15 additions & 0 deletions src/Core/DefaultPlugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#ifndef AMPLITUDE_DEFAULTPLUGINS_H
#define AMPLITUDE_DEFAULTPLUGINS_H

Expand Down Expand Up @@ -47,4 +49,17 @@

#pragma endregion

#pragma region Default Codecs

#include <Core/Codecs/AMS/Codec.h>

#pragma endregion

#pragma region Default Drivers

#include <Core/Drivers/MiniAudio/Driver.h>
#include <Core/Drivers/Null/Driver.h>

#pragma endregion

#endif // AMPLITUDE_DEFAULTPLUGINS_H
4 changes: 2 additions & 2 deletions src/Core/Drivers/MiniAudio/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <Mixer/Mixer.h>

namespace SparkyStudios::Audio::Amplitude::Drivers
namespace SparkyStudios::Audio::Amplitude
{
static void* ma_malloc(size_t sz, void* pUserData)
{
Expand Down Expand Up @@ -399,4 +399,4 @@ namespace SparkyStudios::Audio::Amplitude::Drivers

return true;
}
} // namespace SparkyStudios::Audio::Amplitude::Drivers
} // namespace SparkyStudios::Audio::Amplitude
8 changes: 4 additions & 4 deletions src/Core/Drivers/MiniAudio/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

#include <Utils/miniaudio/miniaudio_utils.h>

namespace SparkyStudios::Audio::Amplitude::Drivers
namespace SparkyStudios::Audio::Amplitude
{
[[maybe_unused]] static class MiniAudioDriver final : public Driver
class MiniAudioDriver final : public Driver
{
public:
MiniAudioDriver();
Expand All @@ -49,7 +49,7 @@ namespace SparkyStudios::Audio::Amplitude::Drivers
ma_context _context;

std::vector<DeviceDescription> _devices;
} g_driver_miniaudio; // NOLINT(cert-err58-cpp)
} // namespace SparkyStudios::Audio::Amplitude::Drivers
};
} // namespace SparkyStudios::Audio::Amplitude

#endif // SS_AMPLITUDE_AUDIO_MINIAUDIO_DRIVER_H
4 changes: 2 additions & 2 deletions src/Core/Drivers/Null/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <Mixer/Mixer.h>

namespace SparkyStudios::Audio::Amplitude::Drivers
namespace SparkyStudios::Audio::Amplitude
{
static void null_mix(void* param)
{
Expand Down Expand Up @@ -83,4 +83,4 @@ namespace SparkyStudios::Audio::Amplitude::Drivers
{
return true;
}
} // namespace SparkyStudios::Audio::Amplitude::Drivers
} // namespace SparkyStudios::Audio::Amplitude
8 changes: 4 additions & 4 deletions src/Core/Drivers/Null/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <SparkyStudios/Audio/Amplitude/Amplitude.h>

namespace SparkyStudios::Audio::Amplitude::Drivers
namespace SparkyStudios::Audio::Amplitude
{
struct NullDriverDeviceData
{
Expand All @@ -28,7 +28,7 @@ namespace SparkyStudios::Audio::Amplitude::Drivers
bool mRunning;
};

[[maybe_unused]] static class NullDriver final : public Driver
class NullDriver final : public Driver
{
public:
NullDriver();
Expand All @@ -47,7 +47,7 @@ namespace SparkyStudios::Audio::Amplitude::Drivers
AmThreadHandle _thread;

NullDriverDeviceData _deviceData;
} g_driver_null; // NOLINT(cert-err58-cpp)
} // namespace SparkyStudios::Audio::Amplitude::Drivers
};
} // namespace SparkyStudios::Audio::Amplitude

#endif // SS_AMPLITUDE_AUDIO_NULL_DRIVER_H
Loading

0 comments on commit 5ef42f5

Please sign in to comment.