Sound fixes (#2083)

This commit is contained in:
Ziemas
2023-01-02 03:02:38 +01:00
committed by GitHub
parent 308038a20f
commit a77d9fac01
7 changed files with 55 additions and 9 deletions
+21 -6
View File
@@ -10,6 +10,7 @@ namespace snd {
// added!
u64 SoundFlavaHack = 0;
u8 GlobalExcite = 0;
ame_handler::ame_handler(MultiMIDIBlockHeader* block,
voice_manager& vm,
@@ -137,26 +138,40 @@ std::pair<bool, u8*> ame_handler::run_ame(midi_handler& midi, u8* stream) {
bool done = false;
bool cont = true;
// fmt::print("AME SCRIPT ----\n");
// u8* dbgstream = stream;
// while (!done) {
// fmt::print("{:02x} ", *dbgstream);
// dbgstream++;
// if (*dbgstream == 0xf7) {
// dbgstream++;
// done = true;
// }
//}
// done = false;
// fmt::print("\n -------\n");
while (!done) {
auto op = static_cast<u8>(*stream++);
switch (op) {
case 0x0: {
AME_BEGIN(op)
if (m_excite <= (stream[0] + 1)) {
if (GlobalExcite <= (stream[0] + 1)) {
skip = 1;
}
AME_END(1)
} break;
case 0x1: {
AME_BEGIN(op)
if (m_excite != (stream[0] + 1)) {
if (GlobalExcite != (stream[0] + 1)) {
skip = 1;
}
AME_END(1)
} break;
case 0x2: {
AME_BEGIN(op)
if (m_excite > (stream[0] + 1)) {
if (GlobalExcite > (stream[0] + 1)) {
skip = 1;
}
AME_END(1)
@@ -213,12 +228,12 @@ std::pair<bool, u8*> ame_handler::run_ame(midi_handler& midi, u8* stream) {
AME_BEGIN(op)
cont = false;
done = true;
start_segment(m_register[stream[0] - 1]);
start_segment(m_register[stream[0]] - 1);
AME_END(1)
} break;
case 0xe: {
AME_BEGIN(op)
start_segment(m_register[stream[0] - 1]);
start_segment(m_register[stream[0]] - 1);
AME_END(1)
} break;
case 0xf: {
@@ -249,7 +264,7 @@ std::pair<bool, u8*> ame_handler::run_ame(midi_handler& midi, u8* stream) {
u8 group = stream[0];
u8 comp = 0;
if (m_groups[group].basis == 0) {
comp = m_excite;
comp = GlobalExcite;
} else {
comp = m_register[m_groups[group].basis - 1];
}
+2 -1
View File
@@ -15,6 +15,8 @@ namespace snd {
// added!
extern u64 SoundFlavaHack;
extern u8 GlobalExcite;
class midi_handler;
class ame_handler : public sound_handler {
friend class midi_handler;
@@ -72,7 +74,6 @@ class ame_handler : public sound_handler {
std::unordered_map<u32, std::unique_ptr<midi_handler>> m_midis;
u8 m_excite{0};
std::array<GroupDescription, 16> m_groups{};
std::array<u8, 16> m_register{};
std::array<u8*, 16> m_macro{};
+25
View File
@@ -325,6 +325,28 @@ void midi_handler::meta_event() {
m_seq_ptr += len + 2;
}
void midi_handler::controller_change() {
u8 channel = m_status & 0xf;
u8 controller = m_seq_ptr[0];
u8 value = m_seq_ptr[1];
switch (controller) {
// case 0x0: {} break; // TODO bank select
case 0x7: {
m_chanvol[channel] = static_cast<s8>(value);
} break;
case 0xa: {
m_chanpan[channel] = static_cast<s8>(value);
} break;
// case 0x40: {} break; // TODO damper
default:
throw midi_error(fmt::format("invalid midi controller change {}", controller));
break;
}
m_seq_ptr += 2;
}
void midi_handler::system_event() {
// fmt::print("{}: system event {:02x}\n", m_time, *m_seq_ptr);
@@ -409,6 +431,9 @@ void midi_handler::step() {
case 0x9:
note_on();
break;
case 0xB:
controller_change();
break;
case 0xD:
channel_pressure();
break;
+1
View File
@@ -135,6 +135,7 @@ class midi_handler : public sound_handler {
void note_on();
void note_off();
void controller_change();
void channel_pressure();
void program_change();
void meta_event();
+2
View File
@@ -14,6 +14,8 @@
namespace snd {
u8 g_global_excite = 0;
player::player() : m_vmanager(m_synth, m_loader) {
init_cubeb();
}
+1
View File
@@ -44,6 +44,7 @@ class player {
s32 pm,
s32 pb);
void set_sound_reg(u32 sound_id, u8 reg, u8 value);
void set_global_excite(u8 value) { GlobalExcite = value; };
bool sound_still_active(u32 sound_id);
void set_master_volume(u32 group, s32 volume);
void unload_bank(u32 bank_handle);
+3 -2
View File
@@ -242,6 +242,7 @@ void snd_SetSoundReg(s32 sound_handle, s32 which, u8 val) {
}
void snd_SetGlobalExcite(u8 value) {
// TODO
lg::warn("Unimplemented snd_SetGlobalExcite\n");
if (player) {
player->set_global_excite(value);
}
}