From f1f29302f5401c4782985cec4d47d069b99036ee Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Fri, 3 Apr 2015 00:18:58 -0400 Subject: AUDIO: Remove the legacy OPL API --- engines/cine/sound.cpp | 88 ++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 42 deletions(-) (limited to 'engines/cine/sound.cpp') diff --git a/engines/cine/sound.cpp b/engines/cine/sound.cpp index 069a4787ac..8da6dba532 100644 --- a/engines/cine/sound.cpp +++ b/engines/cine/sound.cpp @@ -128,7 +128,7 @@ protected: UpdateCallback _upCb; void *_upRef; - FM_OPL *_opl; + OPL::OPL *_opl; int _sampleRate; Audio::Mixer *_mixer; Audio::SoundHandle _soundHandle; @@ -282,8 +282,12 @@ void PCSoundDriver::resetChannel(int channel) { AdLibSoundDriver::AdLibSoundDriver(Audio::Mixer *mixer) : _upCb(0), _upRef(0), _mixer(mixer) { + _sampleRate = _mixer->getOutputRate(); - _opl = makeAdLibOPL(_sampleRate); + _opl = OPL::Config::create(); + if (!_opl || !_opl->init(_sampleRate)) + error("Failed to create OPL"); + memset(_channelsVolumeTable, 0, sizeof(_channelsVolumeTable)); memset(_instrumentsTable, 0, sizeof(_instrumentsTable)); initCard(); @@ -292,7 +296,7 @@ AdLibSoundDriver::AdLibSoundDriver(Audio::Mixer *mixer) AdLibSoundDriver::~AdLibSoundDriver() { _mixer->stopHandle(_soundHandle); - OPLDestroy(_opl); + delete _opl; } void AdLibSoundDriver::setUpdateCallback(UpdateCallback upCb, void *ref) { @@ -322,23 +326,23 @@ void AdLibSoundDriver::stopChannel(int channel) { channel = 6; } if (ins->mode == 0 || channel == 6) { - OPLWriteReg(_opl, 0xB0 | channel, 0); + _opl->writeReg(0xB0 | channel, 0); } if (ins->mode != 0) { _vibrato &= ~(1 << (10 - ins->channel)); - OPLWriteReg(_opl, 0xBD, _vibrato); + _opl->writeReg(0xBD, _vibrato); } } void AdLibSoundDriver::stopAll() { int i; for (i = 0; i < 18; ++i) { - OPLWriteReg(_opl, 0x40 | _operatorsTable[i], 63); + _opl->writeReg(0x40 | _operatorsTable[i], 63); } for (i = 0; i < 9; ++i) { - OPLWriteReg(_opl, 0xB0 | i, 0); + _opl->writeReg(0xB0 | i, 0); } - OPLWriteReg(_opl, 0xBD, 0); + _opl->writeReg(0xBD, 0); } int AdLibSoundDriver::readBuffer(int16 *buffer, const int numSamples) { @@ -348,26 +352,26 @@ int AdLibSoundDriver::readBuffer(int16 *buffer, const int numSamples) { void AdLibSoundDriver::initCard() { _vibrato = 0x20; - OPLWriteReg(_opl, 0xBD, _vibrato); - OPLWriteReg(_opl, 0x08, 0x40); + _opl->writeReg(0xBD, _vibrato); + _opl->writeReg(0x08, 0x40); static const int oplRegs[] = { 0x40, 0x60, 0x80, 0x20, 0xE0 }; for (int i = 0; i < 9; ++i) { - OPLWriteReg(_opl, 0xB0 | i, 0); + _opl->writeReg(0xB0 | i, 0); } for (int i = 0; i < 9; ++i) { - OPLWriteReg(_opl, 0xC0 | i, 0); + _opl->writeReg(0xC0 | i, 0); } for (int j = 0; j < 5; j++) { for (int i = 0; i < 18; ++i) { - OPLWriteReg(_opl, oplRegs[j] | _operatorsTable[i], 0); + _opl->writeReg(oplRegs[j] | _operatorsTable[i], 0); } } - OPLWriteReg(_opl, 1, 0x20); - OPLWriteReg(_opl, 1, 0); + _opl->writeReg(1, 0x20); + _opl->writeReg(1, 0); } void AdLibSoundDriver::update(int16 *buf, int len) { @@ -379,7 +383,7 @@ void AdLibSoundDriver::update(int16 *buf, int len) { } samplesLeft -= count; len -= count; - YM3812UpdateOne(_opl, buf, count); + _opl->readBuffer(buf, count); if (samplesLeft == 0) { if (_upCb) { (*_upCb)(_upRef); @@ -408,32 +412,32 @@ void AdLibSoundDriver::setupInstrument(const byte *data, int channel) { if (ins->mode == 0 || ins->channel == 6) { reg = &ins->regMod; - OPLWriteReg(_opl, 0x20 | mod, reg->vibrato); + _opl->writeReg(0x20 | mod, reg->vibrato); if (reg->freqMod) { tmp = reg->outputLevel & 0x3F; } else { tmp = (63 - (reg->outputLevel & 0x3F)) * _channelsVolumeTable[channel]; tmp = 63 - (2 * tmp + 127) / (2 * 127); } - OPLWriteReg(_opl, 0x40 | mod, tmp | (reg->keyScaling << 6)); - OPLWriteReg(_opl, 0x60 | mod, reg->attackDecay); - OPLWriteReg(_opl, 0x80 | mod, reg->sustainRelease); + _opl->writeReg(0x40 | mod, tmp | (reg->keyScaling << 6)); + _opl->writeReg(0x60 | mod, reg->attackDecay); + _opl->writeReg(0x80 | mod, reg->sustainRelease); if (ins->mode != 0) { - OPLWriteReg(_opl, 0xC0 | ins->channel, reg->feedbackStrength); + _opl->writeReg(0xC0 | ins->channel, reg->feedbackStrength); } else { - OPLWriteReg(_opl, 0xC0 | channel, reg->feedbackStrength); + _opl->writeReg(0xC0 | channel, reg->feedbackStrength); } - OPLWriteReg(_opl, 0xE0 | mod, ins->waveSelectMod); + _opl->writeReg(0xE0 | mod, ins->waveSelectMod); } reg = &ins->regCar; - OPLWriteReg(_opl, 0x20 | car, reg->vibrato); + _opl->writeReg(0x20 | car, reg->vibrato); tmp = (63 - (reg->outputLevel & 0x3F)) * _channelsVolumeTable[channel]; tmp = 63 - (2 * tmp + 127) / (2 * 127); - OPLWriteReg(_opl, 0x40 | car, tmp | (reg->keyScaling << 6)); - OPLWriteReg(_opl, 0x60 | car, reg->attackDecay); - OPLWriteReg(_opl, 0x80 | car, reg->sustainRelease); - OPLWriteReg(_opl, 0xE0 | car, ins->waveSelectCar); + _opl->writeReg(0x40 | car, tmp | (reg->keyScaling << 6)); + _opl->writeReg(0x60 | car, reg->attackDecay); + _opl->writeReg(0x80 | car, reg->sustainRelease); + _opl->writeReg(0xE0 | car, ins->waveSelectCar); } void AdLibSoundDriver::loadRegisterInstrument(const byte *data, AdLibRegisterSoundInstrument *reg) { @@ -490,16 +494,16 @@ void AdLibSoundDriverINS::setChannelFrequency(int channel, int frequency) { if (channel == 6) oct = 0; freq = _freqTable[note % 12]; - OPLWriteReg(_opl, 0xA0 | channel, freq); + _opl->writeReg(0xA0 | channel, freq); freq = (oct << 2) | ((freq & 0x300) >> 8); if (ins->mode == 0) { freq |= 0x20; } - OPLWriteReg(_opl, 0xB0 | channel, freq); + _opl->writeReg(0xB0 | channel, freq); } if (ins->mode != 0) { _vibrato |= 1 << (10 - ins->channel); - OPLWriteReg(_opl, 0xBD, _vibrato); + _opl->writeReg(0xBD, _vibrato); } } @@ -515,16 +519,16 @@ void AdLibSoundDriverINS::playSample(const byte *data, int size, int channel, in if (ins->mode == 0 || channel == 6) { uint16 note = 12; int freq = _freqTable[note % 12]; - OPLWriteReg(_opl, 0xA0 | channel, freq); + _opl->writeReg(0xA0 | channel, freq); freq = ((note / 12) << 2) | ((freq & 0x300) >> 8); if (ins->mode == 0) { freq |= 0x20; } - OPLWriteReg(_opl, 0xB0 | channel, freq); + _opl->writeReg(0xB0 | channel, freq); } if (ins->mode != 0) { _vibrato |= 1 << (10 - ins->channel); - OPLWriteReg(_opl, 0xBD, _vibrato); + _opl->writeReg(0xBD, _vibrato); } } @@ -562,15 +566,15 @@ void AdLibSoundDriverADL::setChannelFrequency(int channel, int frequency) { } freq = _freqTable[note % 12]; - OPLWriteReg(_opl, 0xA0 | channel, freq); + _opl->writeReg(0xA0 | channel, freq); freq = (oct << 2) | ((freq & 0x300) >> 8); if (ins->mode == 0) { freq |= 0x20; } - OPLWriteReg(_opl, 0xB0 | channel, freq); + _opl->writeReg(0xB0 | channel, freq); if (ins->mode != 0) { _vibrato |= 1 << (10 - channel); - OPLWriteReg(_opl, 0xBD, _vibrato); + _opl->writeReg(0xBD, _vibrato); } } @@ -580,11 +584,11 @@ void AdLibSoundDriverADL::playSample(const byte *data, int size, int channel, in setupInstrument(data, channel); AdLibSoundInstrument *ins = &_instrumentsTable[channel]; if (ins->mode != 0 && ins->channel == 6) { - OPLWriteReg(_opl, 0xB0 | channel, 0); + _opl->writeReg(0xB0 | channel, 0); } if (ins->mode != 0) { _vibrato &= ~(1 << (10 - ins->channel)); - OPLWriteReg(_opl, 0xBD, _vibrato); + _opl->writeReg(0xBD, _vibrato); } if (ins->mode != 0) { channel = ins->channel; @@ -599,15 +603,15 @@ void AdLibSoundDriverADL::playSample(const byte *data, int size, int channel, in note = ins->amDepth; } int freq = _freqTable[note % 12]; - OPLWriteReg(_opl, 0xA0 | channel, freq); + _opl->writeReg(0xA0 | channel, freq); freq = ((note / 12) << 2) | ((freq & 0x300) >> 8); if (ins->mode == 0) { freq |= 0x20; } - OPLWriteReg(_opl, 0xB0 | channel, freq); + _opl->writeReg(0xB0 | channel, freq); if (ins->mode != 0) { _vibrato |= 1 << (10 - channel); - OPLWriteReg(_opl, 0xBD, _vibrato); + _opl->writeReg(0xBD, _vibrato); } } -- cgit v1.2.3