amuse/lib/AudioGroup.cpp

97 lines
3.0 KiB
C++
Raw Normal View History

#include "amuse/AudioGroup.hpp"
#include "amuse/AudioGroupData.hpp"
namespace amuse
{
2018-07-18 07:39:26 +00:00
void AudioGroup::assign(const AudioGroupData& data)
{
m_proj = AudioGroupProject::CreateAudioGroupProject(data);
m_pool = AudioGroupPool::CreateAudioGroupPool(data);
m_sdir = AudioGroupSampleDirectory::CreateAudioGroupSampleDirectory(data);
m_samp = data.getSamp();
}
void AudioGroup::assign(SystemStringView groupPath)
{
/* Reverse order when loading intermediates */
2018-07-28 04:34:29 +00:00
m_groupPath = groupPath;
2018-07-18 07:39:26 +00:00
m_sdir = AudioGroupSampleDirectory::CreateAudioGroupSampleDirectory(groupPath);
m_pool = AudioGroupPool::CreateAudioGroupPool(groupPath);
m_proj = AudioGroupProject::CreateAudioGroupProject(groupPath);
m_samp = nullptr;
}
2018-07-29 03:37:06 +00:00
const SampleEntry* AudioGroup::getSample(SampleId sfxId) const
{
2016-05-14 22:38:37 +00:00
auto search = m_sdir.m_entries.find(sfxId);
if (search == m_sdir.m_entries.cend())
return nullptr;
2018-07-29 03:37:06 +00:00
return search->second.get();
}
2018-07-31 08:04:43 +00:00
SystemString AudioGroup::getSampleBasePath(SampleId sfxId) const
{
#if _WIN32
return m_groupPath + _S('/') +
athena::utility::utf8ToWide(SampleId::CurNameDB->resolveNameFromId(sfxId));
#else
return m_groupPath + _S('/') +
SampleId::CurNameDB->resolveNameFromId(sfxId).data();
#endif
}
2018-07-29 03:37:06 +00:00
std::pair<ObjToken<SampleEntryData>, const unsigned char*>
AudioGroup::getSampleData(SampleId sfxId, const SampleEntry* sample) const
2018-07-16 07:41:15 +00:00
{
2018-07-29 03:37:06 +00:00
if (sample->m_data->m_looseData)
2018-07-16 07:41:15 +00:00
{
2018-07-28 04:34:29 +00:00
setIdDatabases();
2018-07-31 08:04:43 +00:00
SystemString basePath = getSampleBasePath(sfxId);
2018-07-29 03:37:06 +00:00
const_cast<SampleEntry*>(sample)->loadLooseData(basePath);
return {sample->m_data, sample->m_data->m_looseData.get()};
2018-07-16 07:41:15 +00:00
}
2018-07-29 03:37:06 +00:00
return {{}, m_samp + sample->m_data->m_sampleOff};
2018-07-16 07:41:15 +00:00
}
2018-07-31 08:04:43 +00:00
2018-08-03 03:45:48 +00:00
SampleFileState AudioGroup::getSampleFileState(SampleId sfxId, const SampleEntry* sample, SystemString* pathOut) const
2018-07-31 08:04:43 +00:00
{
if (sample->m_data->m_looseData)
{
setIdDatabases();
SystemString basePath = getSampleBasePath(sfxId);
return sample->getFileState(basePath, pathOut);
}
if (sample->m_data->isFormatDSP() || sample->m_data->getSampleFormat() == SampleFormat::N64)
return SampleFileState::MemoryOnlyCompressed;
return SampleFileState::MemoryOnlyWAV;
}
2018-08-03 03:45:48 +00:00
void AudioGroup::patchSampleMetadata(SampleId sfxId, const SampleEntry* sample) const
{
if (sample->m_data->m_looseData)
{
setIdDatabases();
SystemString basePath = getSampleBasePath(sfxId);
sample->patchSampleMetadata(basePath);
}
}
void AudioGroup::makeWAVVersion(SampleId sfxId, const SampleEntry* sample) const
{
if (sample->m_data->m_looseData)
{
setIdDatabases();
m_sdir._extractWAV(sfxId, *sample->m_data, m_groupPath, sample->m_data->m_looseData.get());
}
}
void AudioGroup::makeCompressedVersion(SampleId sfxId, const SampleEntry* sample) const
{
if (sample->m_data->m_looseData)
{
setIdDatabases();
m_sdir._extractCompressed(sfxId, *sample->m_data, m_groupPath, sample->m_data->m_looseData.get(), true);
}
}
}