2022-05-09 18:34:38 +01:00
|
|
|
/*****************************************************************************
|
2024-01-01 05:52:28 -06:00
|
|
|
* Copyright (c) 2014-2024 OpenRCT2 developers
|
2022-05-09 18:34:38 +01:00
|
|
|
*
|
|
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
|
|
|
|
*
|
|
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "AudioObject.h"
|
|
|
|
|
|
2022-09-18 16:15:42 +01:00
|
|
|
#include "../AssetPackManager.h"
|
2022-05-09 18:34:38 +01:00
|
|
|
#include "../Context.h"
|
|
|
|
|
#include "../PlatformEnvironment.h"
|
|
|
|
|
#include "../audio/AudioContext.h"
|
2024-10-15 17:39:54 +02:00
|
|
|
#include "../core/Guard.hpp"
|
2022-05-09 18:34:38 +01:00
|
|
|
#include "../core/Json.hpp"
|
|
|
|
|
#include "../core/Path.hpp"
|
|
|
|
|
|
|
|
|
|
using namespace OpenRCT2;
|
|
|
|
|
using namespace OpenRCT2::Audio;
|
|
|
|
|
|
|
|
|
|
void AudioObject::Load()
|
|
|
|
|
{
|
2022-10-01 12:07:42 +01:00
|
|
|
// Start with base samples
|
2022-09-18 16:15:42 +01:00
|
|
|
_loadedSampleTable.LoadFrom(_sampleTable, 0, _sampleTable.GetCount());
|
|
|
|
|
|
|
|
|
|
// Override samples from asset packs
|
|
|
|
|
auto context = GetContext();
|
|
|
|
|
auto assetManager = context->GetAssetPackManager();
|
|
|
|
|
if (assetManager != nullptr)
|
|
|
|
|
{
|
|
|
|
|
assetManager->LoadSamplesForObject(GetIdentifier(), _loadedSampleTable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_loadedSampleTable.Load();
|
2022-05-09 18:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioObject::Unload()
|
|
|
|
|
{
|
2022-09-18 16:15:42 +01:00
|
|
|
_loadedSampleTable.Unload();
|
2022-05-09 18:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioObject::ReadJson(IReadObjectContext* context, json_t& root)
|
|
|
|
|
{
|
2022-09-18 16:15:42 +01:00
|
|
|
Guard::Assert(root.is_object(), "AudioObject::ReadJson expects parameter root to be object");
|
2022-05-09 18:34:38 +01:00
|
|
|
_sampleTable.ReadFromJson(context, root);
|
|
|
|
|
PopulateTablesFromJson(context, root);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IAudioSource* AudioObject::GetSample(uint32_t index) const
|
|
|
|
|
{
|
2022-09-18 16:15:42 +01:00
|
|
|
return _loadedSampleTable.GetSample(index);
|
2022-05-09 18:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t AudioObject::GetSampleModifier(uint32_t index) const
|
|
|
|
|
{
|
2022-09-18 16:15:42 +01:00
|
|
|
return _loadedSampleTable.GetSampleModifier(index);
|
2022-05-09 18:34:38 +01:00
|
|
|
}
|