From 0de0dd098d70e4b471ad21e05418806fcdb99903 Mon Sep 17 00:00:00 2001 From: Philippe Simons Date: Tue, 25 Jul 2017 16:07:26 +0200 Subject: use NukedOPL3 for gen_adldata --- src/gen_adldata/gen_adldata.cc | 76 +++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 46 deletions(-) (limited to 'src/gen_adldata/gen_adldata.cc') diff --git a/src/gen_adldata/gen_adldata.cc b/src/gen_adldata/gen_adldata.cc index a5c612e..52ac5e7 100644 --- a/src/gen_adldata/gen_adldata.cc +++ b/src/gen_adldata/gen_adldata.cc @@ -818,19 +818,9 @@ static void LoadBisqwit(const char* fn, unsigned bank, const char* prefix) std::fclose(fp); } -#include "../dbopl.h" +#include "../nukedopl3.h" -std::vector sampleBuf; -static void AddMonoAudio(unsigned long count, int* samples) -{ - sampleBuf.insert(sampleBuf.end(), samples, samples+count); -} - -static void AddStereoAudio(unsigned long count, int* samples) -{ - for (unsigned long i = 0; i < count; i++) - sampleBuf.insert(sampleBuf.end(), samples + i * 2, samples + i * 2 + 1); -} +std::vector stereoSampleBuf; struct DurationInfo { @@ -859,30 +849,30 @@ static DurationInfo MeasureDurations(const ins& in) : in.notenum >= 128 ? (44 + 128 - in.notenum) : in.notenum; - DBOPL::Handler opl; + _opl3_chip opl; static const short initdata[(2+3+2+2)*2] = { 0x004,96, 0x004,128, // Pulse timer 0x105, 0, 0x105,1, 0x105,0, // Pulse OPL3 enable, leave disabled 0x001,32, 0x0BD,0 // Enable wave & melodic }; - opl.Init(rate); - for(unsigned a=0; a<18; a+=2) opl.WriteReg(initdata[a], initdata[a+1]); + OPL3_Reset(&opl, rate); + for(unsigned a=0; a<18; a+=2) OPL3_WriteReg(&opl, initdata[a], initdata[a+1]); const unsigned n_notes = in.insno1 == in.insno2 ? 1 : 2; unsigned x[2]; if (n_notes == 2 && !in.pseudo4op) { - opl.WriteReg(0x105, 1); - opl.WriteReg(0x104, 1); + OPL3_WriteReg(&opl, 0x105, 1); + OPL3_WriteReg(&opl, 0x104, 1); } for(unsigned n=0; n>8); + OPL3_WriteReg(&opl, 0xA0+n*3, x[n]&0xFF); + OPL3_WriteReg(&opl, 0xB0+n*3, x[n]>>8); } const unsigned max_on = 40; @@ -910,24 +900,21 @@ static DurationInfo MeasureDurations(const ins& in) double highest_sofar = 0; for(unsigned period=0; period 512) - {opl.Generate(AddMonoAudio, AddStereoAudio, 512); n-=512;} - if(n)opl.Generate(AddMonoAudio, AddStereoAudio, n); - unsigned long count = sampleBuf.size(); + stereoSampleBuf.clear(); + stereoSampleBuf.resize(samples_per_interval * 2); + OPL3_GenerateStream(&opl, stereoSampleBuf.data(), samples_per_interval); double mean = 0.0; - for(unsigned long c=0; c highest_sofar) highest_sofar = std_deviation; @@ -938,30 +925,27 @@ static DurationInfo MeasureDurations(const ins& in) // Keyoff the note for(unsigned n=0; n>8) & 0xDF); + OPL3_WriteReg(&opl, 0xB0+n, (x[n]>>8) & 0xDF); // Now, for up to 60 seconds, measure mean amplitude. std::vector amplitudecurve_off; for(unsigned period=0; period 512) - {opl.Generate(AddMonoAudio, AddStereoAudio, 512); n-=512;} - if(n)opl.Generate(AddMonoAudio, AddStereoAudio, n); - unsigned long count = sampleBuf.size(); + stereoSampleBuf.clear(); + stereoSampleBuf.resize(samples_per_interval * 2); + OPL3_GenerateStream(&opl, stereoSampleBuf.data(), samples_per_interval); double mean = 0.0; - for(unsigned long c=0; c