aha
This commit is contained in:
1 parent
15ab48343a
commit
c017d27b2a
11 files changed
+1554
-263
No files matched your search
@@ -1,4 +1,7 @@
|
||||
#include "assets/music_bank.hpp"
|
||||
#include "audio/audio_engine.hpp"
|
||||
#include "audio/opl3_synth.hpp"
|
||||
#include "audio/sf_synth.hpp"
|
||||
#include "core/config.hpp"
|
||||
#include "core/vfs.hpp"
|
||||
|
||||
@@ -131,6 +134,129 @@ int main() {
|
||||
CHECK(burst_stats.finite_ok && burst_stats.peak <= 0.99f && burst_stats.rms < 0.45f);
|
||||
}
|
||||
|
||||
// 6. BULLFROG.SBK generator accuracy & synth dynamics / filter / 5-track checks
|
||||
{
|
||||
assets::SoundFontBank sbk;
|
||||
CHECK(sbk.load(vfs, "SOUND/BULLFROG.SBK"));
|
||||
CHECK(!sbk.is_sf2);
|
||||
|
||||
const auto* pr2 = sbk.find_preset(0, 2); // 22LOOP (op55=7200 -> -1200 cents)
|
||||
CHECK(pr2 && !pr2->zones.empty());
|
||||
CHECK(pr2->zones[0].sample_pitch_cents == -1200);
|
||||
|
||||
const auto* pr117 = sbk.find_preset(0, 117); // AgogoLoTone (op36=2034, no op37, op38=1192)
|
||||
CHECK(pr117 && !pr117->zones.empty());
|
||||
CHECK(pr117->zones[0].vol_decay_sec > 3.0f && pr117->zones[0].vol_decay_sec < 3.5f);
|
||||
CHECK(pr117->zones[0].vol_sustain_db > 85.0f);
|
||||
CHECK(pr117->zones[0].vol_release_sec > 1.8f && pr117->zones[0].vol_release_sec < 2.2f);
|
||||
|
||||
const auto* pr0 = sbk.find_preset(0, 0); // basic kit -> HCL909 key 42
|
||||
CHECK(pr0);
|
||||
const assets::SoundFontZone* hcl = nullptr;
|
||||
for (const auto& z : pr0->zones) {
|
||||
if (42 >= z.key_lo && 42 <= z.key_hi) {
|
||||
hcl = &z;
|
||||
break;
|
||||
}
|
||||
}
|
||||
CHECK(hcl != nullptr);
|
||||
CHECK(hcl->attenuation_db > 2.4f && hcl->attenuation_db < 2.9f);
|
||||
CHECK(hcl->pan_tenths_pct == 16);
|
||||
|
||||
float prev_fc = 100000.0f;
|
||||
for (uint16_t p = 119; p <= 127; ++p) {
|
||||
const auto* pr = sbk.find_preset(0, p);
|
||||
CHECK(pr && !pr->zones.empty());
|
||||
const auto& z = pr->zones[0];
|
||||
CHECK(z.has_filter && z.filter_q_db > 10.0f && z.chorus_send > 0.9f);
|
||||
CHECK(z.filter_fc_hz < prev_fc);
|
||||
prev_fc = z.filter_fc_hz;
|
||||
}
|
||||
CHECK(prev_fc > 850.0f && prev_fc < 980.0f);
|
||||
|
||||
// Concave dynamics check on Opl3Synth and SfSynth (vel, CC 7, CC 11)
|
||||
assets::OplTimbreBank opl_bank;
|
||||
CHECK(opl_bank.load(vfs, "SOUND/SAMPLE.OPL"));
|
||||
audio::Opl3Synth opl_dyn(&opl_bank, 48000);
|
||||
audio::SfSynth sf_dyn(&sbk, &opl_bank, 48000);
|
||||
|
||||
auto render_single_rms = [](audio::IMidiSynth& syn, uint8_t ch, uint8_t prog,
|
||||
bool user_bank, uint8_t vel, uint8_t cc7, uint8_t cc11) -> float {
|
||||
syn.reset();
|
||||
syn.program_change(ch, prog);
|
||||
if (user_bank) syn.control_change(ch, 119, 1);
|
||||
syn.control_change(ch, 7, cc7);
|
||||
syn.control_change(ch, 11, cc11);
|
||||
syn.note_on(ch, 48, vel);
|
||||
std::vector<float> buf(12000 * 2, 0.0f); // 0.25s
|
||||
syn.render(buf.data(), 12000);
|
||||
double e = 0.0;
|
||||
for (float s : buf) e += static_cast<double>(s) * s;
|
||||
return static_cast<float>(std::sqrt(e / static_cast<double>(buf.size())));
|
||||
};
|
||||
|
||||
auto check_dyn = [&](audio::IMidiSynth& syn, uint8_t prog, bool user_bank, const char* label) {
|
||||
float full = render_single_rms(syn, 0, prog, user_bank, 127, 127, 127);
|
||||
float half_v = render_single_rms(syn, 0, prog, user_bank, 64, 127, 127);
|
||||
float half_c7 = render_single_rms(syn, 0, prog, user_bank, 127, 64, 127);
|
||||
float half_c11 = render_single_rms(syn, 0, prog, user_bank, 127, 127, 64);
|
||||
std::cout << " Dynamics [" << label << "]: full=" << full
|
||||
<< " vel64=" << half_v << " cc7_64=" << half_c7 << " cc11_64=" << half_c11 << "\n";
|
||||
if (!(full > 0.01f && half_v / full < 0.35f &&
|
||||
half_c7 / full < 0.38f && half_c11 / full < 0.38f)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
CHECK(check_dyn(opl_dyn, 38, false, "OPL3 prog38"));
|
||||
CHECK(check_dyn(sf_dyn, 33, false, "SF GM prog33"));
|
||||
CHECK(check_dyn(sf_dyn, 118, true, "SF BULLFROG prog118"));
|
||||
|
||||
// Acid filter spectral brightness contrast: prog 119 (8 kHz) vs prog 127 (912 Hz)
|
||||
auto measure_hf_ratio = [&](uint8_t prog) -> float {
|
||||
sf_dyn.reset();
|
||||
sf_dyn.control_change(0, 119, 1);
|
||||
sf_dyn.program_change(0, prog);
|
||||
sf_dyn.note_on(0, 36, 120);
|
||||
std::vector<float> buf(12000 * 2, 0.0f);
|
||||
sf_dyn.render(buf.data(), 12000);
|
||||
double sig_e = 0.0, diff_e = 0.0;
|
||||
for (size_t i = 2; i < buf.size(); i += 2) {
|
||||
float d = buf[i] - buf[i - 2];
|
||||
sig_e += static_cast<double>(buf[i]) * buf[i];
|
||||
diff_e += static_cast<double>(d) * d;
|
||||
}
|
||||
return static_cast<float>(std::sqrt(diff_e / std::max(sig_e, 1e-12)));
|
||||
};
|
||||
float hf_119 = measure_hf_ratio(119);
|
||||
float hf_127 = measure_hf_ratio(127);
|
||||
std::cout << " Acid filter HF ratio: prog119=" << hf_119 << " prog127=" << hf_127 << "\n";
|
||||
CHECK(hf_119 > hf_127 * 2.5f);
|
||||
|
||||
// Render all 5 tracks across both OPL3 and SoundFont backends
|
||||
constexpr audio::MusicTrackId kTracks[5] = {
|
||||
audio::MusicTrackId::TitleIntro,
|
||||
audio::MusicTrackId::Game1,
|
||||
audio::MusicTrackId::Game2,
|
||||
audio::MusicTrackId::Game3,
|
||||
audio::MusicTrackId::Game4
|
||||
};
|
||||
std::vector<float> trk_pcm(48000 * 3 * 2, 0.0f);
|
||||
for (int b = 0; b < 2; ++b) {
|
||||
cfg.music_backend = (b == 0) ? MusicBackend::Opl3 : MusicBackend::SoundFont;
|
||||
eng.apply_config(cfg, true);
|
||||
for (int t = 0; t < 5; ++t) {
|
||||
eng.play_music(kTracks[t], true);
|
||||
eng.mix_offline(trk_pcm.data(), 48000 * 3);
|
||||
BufferStats st = measure_buffer(
|
||||
trk_pcm, (b == 0) ? "All-tracks OPL3" : "All-tracks SoundFont");
|
||||
CHECK(st.finite_ok && st.peak > 0.01f && st.rms >= 0.008f);
|
||||
}
|
||||
}
|
||||
eng.stop_music();
|
||||
}
|
||||
|
||||
std::cout << "[PASS] AudioEngine, OPL3 FM, SoundFont SBK, Normalization & Limiter validated\n";
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user