Skip to content

Commit

Permalink
989snd: Bank reading overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziemas committed Nov 11, 2023
1 parent ed63a07 commit 66099b8
Show file tree
Hide file tree
Showing 26 changed files with 944 additions and 1,286 deletions.
21 changes: 7 additions & 14 deletions game/sound/989snd/ame_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@ namespace snd {
u64 SoundFlavaHack = 0;
u8 GlobalExcite = 0;

ame_handler::ame_handler(MultiMIDIBlockHeader* block,
ame_handler::ame_handler(MultiMidi* block,
voice_manager& vm,
MIDISound& sound,
MusicBank::MIDISound& sound,
s32 vol,
s32 pan,
locator& loc,
SoundBank& bank)
: m_sound(sound),
m_bank(bank),
m_header(block),
m_locator(loc),
m_vm(vm),
m_repeats(sound.Repeats) {
: m_sound(sound), m_bank(bank), m_header(block), m_vm(vm), m_repeats(sound.Repeats) {
if (vol == VOLUME_DONT_CHANGE) {
vol = 1024;
}
Expand Down Expand Up @@ -59,14 +53,13 @@ bool ame_handler::tick() {

void ame_handler::start_segment(u32 id) {
if (m_midis.find(id) == m_midis.end()) {
auto midiblock = (MIDIBlockHeader*)(m_header->BlockPtr[id] + (uintptr_t)m_header);
auto sound_handler = (MIDISoundHandler*)((uintptr_t)midiblock + sizeof(MIDIBlockHeader));
auto& midi = m_header->midi[id];

// Skip adding if not midi type
u32 type = (sound_handler->OwnerID >> 24) & 0xf;
u32 type = (midi.SoundHandle >> 24) & 0xf;
if (type == 1 || type == 3) {
m_midis.emplace(id, std::make_unique<midi_handler>(midiblock, m_vm, m_sound, m_vol, m_pan,
m_locator, m_bank, this));
m_midis.emplace(id, std::make_unique<midi_handler>(static_cast<Midi*>(&midi), m_vm, m_sound,
m_vol, m_pan, m_bank, this));
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions game/sound/989snd/ame_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ class ame_handler : public sound_handler {
friend class midi_handler;

public:
ame_handler(MultiMIDIBlockHeader* block,
ame_handler(MultiMidi* block,
voice_manager& vm,
MIDISound& sound,
MusicBank::MIDISound& sound,
s32 vol,
s32 pan,
locator& loc,
SoundBank& bank);
bool tick() override;
SoundBank& bank() override { return m_bank; };
Expand Down Expand Up @@ -62,11 +61,10 @@ class ame_handler : public sound_handler {
void stop_segment(u32 id);
std::pair<bool, u8*> run_ame(midi_handler&, u8* stream);

MIDISound& m_sound;
MusicBank::MIDISound& m_sound;
SoundBank& m_bank;

MultiMIDIBlockHeader* m_header{nullptr};
locator& m_locator;
MultiMidi* m_header{nullptr};
voice_manager& m_vm;
s32 m_vol{0};
s32 m_pan{0};
Expand Down
10 changes: 5 additions & 5 deletions game/sound/989snd/blocksound_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void blocksound_handler::set_vol_pan(s32 vol, s32 pan) {
}

if (pan == PAN_RESET) {
m_app_pan = m_sfx.d.Pan;
m_app_pan = m_sfx.Pan;
} else if (pan != PAN_DONT_CHANGE) {
m_app_pan = pan;
}
Expand Down Expand Up @@ -180,9 +180,9 @@ void blocksound_handler::set_pbend(s32 bend) {
}

void blocksound_handler::do_grain() {
auto& grain = m_sfx.grains[m_next_grain];
auto& grain = m_sfx.Grains[m_next_grain];

s32 ret = grain->execute(*this);
s32 ret = grain(*this);

if (m_skip_grains) {
m_grains_to_play--;
Expand All @@ -193,12 +193,12 @@ void blocksound_handler::do_grain() {
}

m_next_grain++;
if (m_next_grain >= m_sfx.grains.size()) {
if (m_next_grain >= m_sfx.Grains.size()) {
m_done = true;
return;
}

m_countdown = m_sfx.grains[m_next_grain]->delay() + ret;
m_countdown = m_sfx.Grains[m_next_grain].Delay + ret;
}

} // namespace snd
14 changes: 7 additions & 7 deletions game/sound/989snd/blocksound_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "common/common_types.h"

#include "game/sound/989snd/lfo.h"
#include "sfxblock2.h"
#include "game/sound/989snd/sfxblock.h"

namespace snd {

Expand All @@ -21,18 +21,18 @@ class blocksound_voice : public vag_voice {
class blocksound_handler : public sound_handler {
public:
blocksound_handler(SoundBank& bank,
SFX2& sfx,
SFXBlock::SFX& sfx,
voice_manager& vm,
s32 sfx_vol,
s32 sfx_pan,
SndPlayParams& params)
: m_group(sfx.d.VolGroup), m_sfx(sfx), m_vm(vm), m_bank(bank) {
: m_group(sfx.VolGroup), m_sfx(sfx), m_vm(vm), m_bank(bank) {
s32 vol, pan, pitch_mod, pitch_bend;
if (sfx_vol == -1) {
sfx_vol = sfx.d.Vol;
sfx_vol = sfx.Vol;
}
if (sfx_pan == -1) {
sfx_pan = sfx.d.Pan;
sfx_pan = sfx.Pan;
}

if (params.vol.has_value()) {
Expand Down Expand Up @@ -101,7 +101,7 @@ class blocksound_handler : public sound_handler {
// }

m_next_grain = 0;
m_countdown = m_sfx.grains[0]->delay();
m_countdown = m_sfx.Grains[0].Delay;
while (m_countdown <= 0 && !m_done) {
do_grain();
}
Expand Down Expand Up @@ -141,7 +141,7 @@ class blocksound_handler : public sound_handler {
u32 m_grains_to_skip{0};
bool m_skip_grains{false};

SFX2& m_sfx;
SFXBlock::SFX& m_sfx;
voice_manager& m_vm;

std::list<std::weak_ptr<blocksound_voice>> m_voices;
Expand Down
2 changes: 1 addition & 1 deletion game/sound/989snd/lfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void LFOTracker::init() {

void LFOTracker::calc_depth() {
if (m_target == lfo_target::VOLUME) {
m_range = (m_handler.m_sfx.d.Vol * m_depth) >> 10;
m_range = (m_handler.m_sfx.Vol * m_depth) >> 10;
}
if (m_target == lfo_target::PAN) {
m_range = (180 * m_depth) >> 10;
Expand Down
Loading

0 comments on commit 66099b8

Please sign in to comment.