2013-09-04 13:37:36 +00:00
|
|
|
#include "Hiopl.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
// A higher level wrapper around the DOSBox OPL emulator.
|
|
|
|
|
|
|
|
Hiopl::Hiopl(int buflen) {
|
|
|
|
adlib = new DBOPL::Handler();
|
|
|
|
Buf32 = new Bit32s[buflen];
|
|
|
|
}
|
|
|
|
|
|
|
|
void Hiopl::Generate(int length, short* buffer) {
|
|
|
|
//printf("Generating %d samples\n", length);
|
|
|
|
adlib->Generate(length, Buf32);
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
buffer[i] = (short)(Buf32[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:19:22 +00:00
|
|
|
void Hiopl::Generate(int length, float* buffer) {
|
|
|
|
// This would be better done using Juce's built in audio format conversion.
|
|
|
|
adlib->Generate(length, Buf32);
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
buffer[i] = (float)(Buf32[i])/32768.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-04 13:37:36 +00:00
|
|
|
void Hiopl::SetSampleRate(int hz) {
|
|
|
|
adlib->Init(hz);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Hiopl::_WriteReg(Bit32u reg, Bit8u value) {
|
|
|
|
adlib->WriteReg(reg, value);
|
|
|
|
regCache[reg] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Hiopl::SetWaveform(int ch, int osc, Waveform wave) {
|
|
|
|
assert(_CheckParams(ch, osc));
|
|
|
|
_WriteReg(0xe0+2*ch+osc, wave);
|
|
|
|
}
|
|
|
|
|
|
|
|
Waveform Hiopl::GetWaveform(int ch, int osc) {
|
|
|
|
assert(_CheckParams(ch, osc));
|
|
|
|
return static_cast<Waveform>(regCache[0xe0+2*ch+osc]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Hiopl::KeyOn(int ch, int frq) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Hiopl::~Hiopl() {
|
|
|
|
delete Buf32;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool Hiopl::_CheckParams(int ch, int osc) {
|
|
|
|
return ch >= 0 && ch < CHANNELS && osc >= 0 && osc < OSCILLATORS;
|
|
|
|
}
|