jak-project/game/sound/989snd/sfxblock.cpp

49 lines
1.4 KiB
C++
Raw Normal View History

2022-05-19 16:54:36 -04:00
#include "sfxblock.h"
2022-05-19 16:54:36 -04:00
#include "blocksound_handler.h"
#include "sfxgrain.h"
#include "common/log/log.h"
2022-05-19 16:54:36 -04:00
namespace snd {
SFXBlock::SFXBlock(locator& loc, u32 id, BankTag* tag)
: SoundBank(id, BankType::SFX), m_locator(loc) {
auto data = (SFXBlockData*)tag;
auto sounddata = (SFX2Data*)((uintptr_t)data + data->FirstSound);
for (int i = 0; i < data->NumSounds; i++) {
SFX2 sound;
sound.index = i;
sound.d = sounddata[i];
m_sounds.push_back(std::move(sound));
}
for (auto& sound : m_sounds) {
auto graindata = (SFXGrain*)((uintptr_t)data + data->FirstGrain + sound.d.FirstGrain);
for (int i = 0; i < sound.d.NumGrains; i++) {
SFXGrain& grain = graindata[i];
sound.grains.push_back(new_grain((grain_type)grain.Type, grain));
}
}
}
2022-05-19 16:54:36 -04:00
std::unique_ptr<sound_handler> SFXBlock::make_handler(voice_manager& vm,
u32 sound_id,
s32 vol,
s32 pan,
SndPlayParams& params) {
auto& SFX = m_sounds[sound_id];
2022-05-19 16:54:36 -04:00
if (SFX.grains.empty()) {
// fmt::print("skipping empty sfx\n");
return nullptr;
}
auto handler =
std::make_unique<blocksound_handler>(*this, m_sounds[sound_id], vm, vol, pan, params);
2022-05-19 16:54:36 -04:00
handler->init();
return handler;
}
} // namespace snd