From b2cf9a580bf9a417d955480a9c207225afc9bb75 Mon Sep 17 00:00:00 2001 From: Coen Rampen Date: Mon, 9 May 2022 15:27:36 +0200 Subject: [PATCH] AUDIO: Add AdLib MS driver callback frequency This change allows a consumer to specify the desired timer callback frequency for the AdLib multisource MIDI driver. --- audio/adlib_ms.cpp | 11 ++++++----- audio/adlib_ms.h | 6 +++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/audio/adlib_ms.cpp b/audio/adlib_ms.cpp index ae8c8546a08..56942d62c8c 100644 --- a/audio/adlib_ms.cpp +++ b/audio/adlib_ms.cpp @@ -394,7 +394,7 @@ bool MidiDriver_ADLIB_Multisource::detectOplType(OPL::Config::OplType oplType) { return OPL::Config::detect(oplType) >= 0; } -MidiDriver_ADLIB_Multisource::MidiDriver_ADLIB_Multisource(OPL::Config::OplType oplType) : +MidiDriver_ADLIB_Multisource::MidiDriver_ADLIB_Multisource(OPL::Config::OplType oplType, int timerFrequency) : _oplType(oplType), _opl(nullptr), _isOpen(false), @@ -413,9 +413,11 @@ MidiDriver_ADLIB_Multisource::MidiDriver_ADLIB_Multisource(OPL::Config::OplType _melodicChannels(nullptr), _numMelodicChannels(0), _noteCounter(1), - _oplFrequencyConversionFactor(pow(2, 20) / 49716.0f) { + _oplFrequencyConversionFactor(pow(2, 20) / 49716.0f), + _timerFrequency(timerFrequency) { memset(_channelAllocations, 0xFF, sizeof(_channelAllocations)); Common::fill(_shadowRegisters, _shadowRegisters + sizeof(_shadowRegisters), 0); + _timerRate = 1000000 / _timerFrequency; } MidiDriver_ADLIB_Multisource::~MidiDriver_ADLIB_Multisource() { @@ -463,10 +465,9 @@ int MidiDriver_ADLIB_Multisource::open() { // Set default OPL register values. initOpl(); - _timerRate = getBaseTempo(); // Start the emulator / hardware interface. This will also start the timer // callbacks. - _opl->start(new Common::Functor0Mem(this, &MidiDriver_ADLIB_Multisource::onTimer)); + _opl->start(new Common::Functor0Mem(this, &MidiDriver_ADLIB_Multisource::onTimer), _timerFrequency); return 0; } @@ -533,7 +534,7 @@ uint32 MidiDriver_ADLIB_Multisource::property(int prop, uint32 param) { } uint32 MidiDriver_ADLIB_Multisource::getBaseTempo() { - return 1000000 / OPL::OPL::kDefaultCallbackFrequency; + return _timerRate; } MidiChannel *MidiDriver_ADLIB_Multisource::allocateChannel() { diff --git a/audio/adlib_ms.h b/audio/adlib_ms.h index 235ba8e3aa6..53231123c0a 100644 --- a/audio/adlib_ms.h +++ b/audio/adlib_ms.h @@ -589,8 +589,10 @@ public: * of OPL chip. * * @param oplType The type of OPL chip that should be used. + * @param timerFrequency The number of timer callbacks per second that + * should be generated. */ - MidiDriver_ADLIB_Multisource(OPL::Config::OplType oplType); + MidiDriver_ADLIB_Multisource(OPL::Config::OplType oplType, int timerFrequency = OPL::OPL::kDefaultCallbackFrequency); ~MidiDriver_ADLIB_Multisource(); /** @@ -1118,6 +1120,8 @@ protected: // True if the driver has been successfully opened. bool _isOpen; + // The number of timer callbacks per second. + int _timerFrequency; // Controls the behavior for calculating note frequency and volume. AccuracyMode _accuracyMode; // Controls the OPL channel allocation behavior.