diff options
author | Matthew Hoops | 2015-04-30 00:01:30 -0400 |
---|---|---|
committer | Matthew Hoops | 2015-07-07 20:19:47 -0400 |
commit | bed9da8b9dbbaa19d317f71663e42875c1717fda (patch) | |
tree | 56b714515cae107ae1f7992a2e85db1e9c800a8a /audio | |
parent | 8bcbcd6c167e8e7169f006da459f3cbe450a4a59 (diff) | |
download | scummvm-rg350-bed9da8b9dbbaa19d317f71663e42875c1717fda.tar.gz scummvm-rg350-bed9da8b9dbbaa19d317f71663e42875c1717fda.tar.bz2 scummvm-rg350-bed9da8b9dbbaa19d317f71663e42875c1717fda.zip |
AUDIO: Remove all AudioStream access to OPL
Diffstat (limited to 'audio')
-rw-r--r-- | audio/fmopl.cpp | 11 | ||||
-rw-r--r-- | audio/fmopl.h | 32 | ||||
-rw-r--r-- | audio/miles_adlib.cpp | 39 | ||||
-rw-r--r-- | audio/softsynth/adlib.cpp | 36 | ||||
-rw-r--r-- | audio/softsynth/opl/dosbox.cpp | 4 | ||||
-rw-r--r-- | audio/softsynth/opl/mame.cpp | 3 |
6 files changed, 42 insertions, 83 deletions
diff --git a/audio/fmopl.cpp b/audio/fmopl.cpp index 9af7afff54..4bc902eba0 100644 --- a/audio/fmopl.cpp +++ b/audio/fmopl.cpp @@ -188,7 +188,8 @@ bool OPL::_hasInstance = false; EmulatedOPL::EmulatedOPL() : _nextTick(0), _samplesPerTick(0), - _baseFreq(0) { + _baseFreq(0), + _handle(new Audio::SoundHandle()) { } EmulatedOPL::~EmulatedOPL() { @@ -197,6 +198,8 @@ EmulatedOPL::~EmulatedOPL() { // needs to call stop() or the pointer can still use be used in // the mixer thread at the same time. stop(); + + delete _handle; } int EmulatedOPL::readBuffer(int16 *buffer, const int numSamples) { @@ -232,13 +235,11 @@ int EmulatedOPL::getRate() const { void EmulatedOPL::startCallbacks(int timerFrequency) { setCallbackFrequency(timerFrequency); - // TODO: Eventually start mixer playback here - //g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, _handle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); + g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, _handle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); } void EmulatedOPL::stopCallbacks() { - // TODO: Eventually stop mixer playback here - //g_system->getMixer()->stopHandle(*_handle); + g_system->getMixer()->stopHandle(*_handle); } void EmulatedOPL::setCallbackFrequency(int timerFrequency) { diff --git a/audio/fmopl.h b/audio/fmopl.h index 8baa9aa218..091e0bd88d 100644 --- a/audio/fmopl.h +++ b/audio/fmopl.h @@ -23,10 +23,16 @@ #ifndef AUDIO_FMOPL_H #define AUDIO_FMOPL_H +#include "audio/audiostream.h" + #include "common/func.h" #include "common/ptr.h" #include "common/scummsys.h" +namespace Audio { +class SoundHandle; +} + namespace Common { class String; } @@ -149,23 +155,6 @@ public: virtual void writeReg(int r, int v) = 0; /** - * Read up to 'length' samples. - * - * Data will be in native endianess, 16 bit per sample, signed. - * For stereo OPL, buffer will be filled with interleaved - * left and right channel samples, starting with a left sample. - * Furthermore, the samples in the left and right are summed up. - * So if you request 4 samples from a stereo OPL, you will get - * a total of two left channel and two right channel samples. - */ - virtual int readBuffer(int16 *buffer, const int numSamples) = 0; - - /** - * Returns whether the setup OPL mode is stereo or not - */ - virtual bool isStereo() const = 0; - - /** * Start the OPL with callbacks. */ void start(TimerCallback *callback, int timerFrequency = kDefaultCallbackFrequency); @@ -205,17 +194,18 @@ protected: Common::ScopedPtr<TimerCallback> _callback; }; -class EmulatedOPL : public OPL { +class EmulatedOPL : public OPL, protected Audio::AudioStream { public: EmulatedOPL(); virtual ~EmulatedOPL(); // OPL API - int readBuffer(int16 *buffer, const int numSamples); - bool isRunning() const; void setCallbackFrequency(int timerFrequency); + // AudioStream API + int readBuffer(int16 *buffer, const int numSamples); int getRate() const; + bool endOfData() const { return false; } protected: // OPL API @@ -243,6 +233,8 @@ private: int _nextTick; int _samplesPerTick; + + Audio::SoundHandle *_handle; }; } // End of namespace OPL diff --git a/audio/miles_adlib.cpp b/audio/miles_adlib.cpp index 7f3f05a769..bf5c9d4a73 100644 --- a/audio/miles_adlib.cpp +++ b/audio/miles_adlib.cpp @@ -116,9 +116,9 @@ uint16 milesAdLibVolumeSensitivityTable[] = { }; -class MidiDriver_Miles_AdLib : public MidiDriver_Emulated { +class MidiDriver_Miles_AdLib : public MidiDriver { public: - MidiDriver_Miles_AdLib(Audio::Mixer *mixer, InstrumentEntry *instrumentTablePtr, uint16 instrumentTableCount); + MidiDriver_Miles_AdLib(InstrumentEntry *instrumentTablePtr, uint16 instrumentTableCount); virtual ~MidiDriver_Miles_AdLib(); // MidiDriver @@ -128,15 +128,8 @@ public: MidiChannel *allocateChannel() { return NULL; } MidiChannel *getPercussionChannel() { return NULL; } - // AudioStream - int readBuffer(int16 *data, const int numSamples); - bool isStereo() const { return _modeStereo; } - int getRate() const { return _mixer->getOutputRate(); } - int getPolyphony() const { return _modePhysicalFmVoicesCount; } - bool hasRhythmChannel() const { return false; } - - // MidiDriver_Emulated - void generateSamples(int16 *buf, int len); + bool isOpen() const { return _isOpen; } + uint32 getBaseTempo() { return 1000000 / OPL::OPL::kDefaultCallbackFrequency; } void setVolume(byte volume); virtual uint32 property(int prop, uint32 param); @@ -228,6 +221,8 @@ private: Common::TimerManager::TimerProc _adlibTimerProc; void *_adlibTimerParam; + bool _isOpen; + // stores information about all MIDI channels (not the actual OPL FM voice channels!) MidiChannelEntry _midiChannels[MILES_MIDI_CHANNEL_COUNT]; @@ -275,9 +270,9 @@ private: void pitchBendChange(byte MIDIchannel, byte parameter1, byte parameter2); }; -MidiDriver_Miles_AdLib::MidiDriver_Miles_AdLib(Audio::Mixer *mixer, InstrumentEntry *instrumentTablePtr, uint16 instrumentTableCount) - : MidiDriver_Emulated(mixer), _masterVolume(15), _opl(0), - _adlibTimerProc(0), _adlibTimerParam(0) { +MidiDriver_Miles_AdLib::MidiDriver_Miles_AdLib(InstrumentEntry *instrumentTablePtr, uint16 instrumentTableCount) + : _masterVolume(15), _opl(0), + _adlibTimerProc(0), _adlibTimerParam(0), _isOpen(false) { _instrumentTablePtr = instrumentTablePtr; _instrumentTableCount = instrumentTableCount; @@ -324,10 +319,9 @@ int MidiDriver_Miles_AdLib::open() { _opl->init(); - MidiDriver_Emulated::open(); + _isOpen = true; _opl->start(new Common::Functor0Mem<void, MidiDriver_Miles_AdLib>(this, &MidiDriver_Miles_AdLib::onTimer)); - _mixer->playStream(Audio::Mixer::kPlainSoundType, &_mixerSoundHandle, this, -1, _mixer->kMaxChannelVolume, 0, DisposeAfterUse::NO, true); resetAdLib(); @@ -335,9 +329,8 @@ int MidiDriver_Miles_AdLib::open() { } void MidiDriver_Miles_AdLib::close() { - _mixer->stopHandle(_mixerSoundHandle); - delete _opl; + _isOpen = false; } void MidiDriver_Miles_AdLib::setVolume(byte volume) { @@ -444,14 +437,6 @@ void MidiDriver_Miles_AdLib::send(uint32 b) { } } -void MidiDriver_Miles_AdLib::generateSamples(int16 *data, int len) { - // Dummy implementation until we no longer inherit from MidiDriver_Emulated -} - -int MidiDriver_Miles_AdLib::readBuffer(int16 *data, const int numSamples) { - return _opl->readBuffer(data, numSamples); -} - void MidiDriver_Miles_AdLib::setTimerCallback(void *timerParam, Common::TimerManager::TimerProc timerProc) { _adlibTimerProc = timerProc; _adlibTimerParam = timerParam; @@ -1283,7 +1268,7 @@ MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String &filenameAdLib, c // Free instrument file/stream data delete[] streamDataPtr; - return new MidiDriver_Miles_AdLib(g_system->getMixer(), instrumentTablePtr, instrumentTableCount); + return new MidiDriver_Miles_AdLib(instrumentTablePtr, instrumentTableCount); } } // End of namespace Audio diff --git a/audio/softsynth/adlib.cpp b/audio/softsynth/adlib.cpp index c7b5297e2d..f609164495 100644 --- a/audio/softsynth/adlib.cpp +++ b/audio/softsynth/adlib.cpp @@ -927,18 +927,20 @@ static void createLookupTable() { // //////////////////////////////////////// -class MidiDriver_ADLIB : public MidiDriver_Emulated { +class MidiDriver_ADLIB : public MidiDriver { friend class AdLibPart; friend class AdLibPercussionChannel; public: - MidiDriver_ADLIB(Audio::Mixer *mixer); + MidiDriver_ADLIB(); int open(); void close(); void send(uint32 b); void send(byte channel, uint32 b); // Supports higher than channel 15 uint32 property(int prop, uint32 param); + bool isOpen() const { return _isOpen; } + uint32 getBaseTempo() { return 1000000 / OPL::OPL::kDefaultCallbackFrequency; } void setPitchBendRange(byte channel, uint range); void sysEx_customInstrument(byte channel, uint32 type, const byte *instr); @@ -946,12 +948,6 @@ public: MidiChannel *allocateChannel(); MidiChannel *getPercussionChannel() { return &_percussion; } // Percussion partially supported - - // AudioStream API - int readBuffer(int16 *data, const int numSamples); - bool isStereo() const { return _opl->isStereo(); } - int getRate() const { return _mixer->getOutputRate(); } - virtual void setTimerCallback(void *timerParam, Common::TimerManager::TimerProc timerProc); private: @@ -980,7 +976,8 @@ private: AdLibPart _parts[32]; AdLibPercussionChannel _percussion; - void generateSamples(int16 *buf, int len); + bool _isOpen; + void onTimer(); void partKeyOn(AdLibPart *part, const AdLibInstrument *instr, byte note, byte velocity, const AdLibInstrument *second, byte pan); void partKeyOff(AdLibPart *part, byte note); @@ -1382,8 +1379,7 @@ void AdLibPercussionChannel::sysEx_customInstrument(uint32 type, const byte *ins // MidiDriver method implementations -MidiDriver_ADLIB::MidiDriver_ADLIB(Audio::Mixer *mixer) - : MidiDriver_Emulated(mixer) { +MidiDriver_ADLIB::MidiDriver_ADLIB() { uint i; _scummSmallHeader = false; @@ -1411,13 +1407,14 @@ MidiDriver_ADLIB::MidiDriver_ADLIB(Audio::Mixer *mixer) _opl = 0; _adlibTimerProc = 0; _adlibTimerParam = 0; + _isOpen = false; } int MidiDriver_ADLIB::open() { if (_isOpen) return MERR_ALREADY_OPEN; - MidiDriver_Emulated::open(); + _isOpen = true; int i; AdLibVoice *voice; @@ -1461,8 +1458,6 @@ int MidiDriver_ADLIB::open() { #endif _opl->start(new Common::Functor0Mem<void, MidiDriver_ADLIB>(this, &MidiDriver_ADLIB::onTimer)); - _mixer->playStream(Audio::Mixer::kPlainSoundType, &_mixerSoundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); - return 0; } @@ -1471,7 +1466,8 @@ void MidiDriver_ADLIB::close() { return; _isOpen = false; - _mixer->stopHandle(_mixerSoundHandle); + // Stop the OPL timer + _opl->stop(); uint i; for (i = 0; i < ARRAYSIZE(_voices); ++i) { @@ -1625,14 +1621,6 @@ void MidiDriver_ADLIB::adlibWriteSecondary(byte reg, byte value) { } #endif -void MidiDriver_ADLIB::generateSamples(int16 *data, int len) { - // Dummy implementation until we no longer inherit from MidiDriver_Emulated -} - -int MidiDriver_ADLIB::readBuffer(int16 *data, const int numSamples) { - return _opl->readBuffer(data, numSamples); -} - void MidiDriver_ADLIB::onTimer() { if (_adlibTimerProc) (*_adlibTimerProc)(_adlibTimerParam); @@ -2318,7 +2306,7 @@ MusicDevices AdLibEmuMusicPlugin::getDevices() const { } Common::Error AdLibEmuMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const { - *mididriver = new MidiDriver_ADLIB(g_system->getMixer()); + *mididriver = new MidiDriver_ADLIB(); return Common::kNoError; } diff --git a/audio/softsynth/opl/dosbox.cpp b/audio/softsynth/opl/dosbox.cpp index 6e8b4a94ed..3d90ec93d0 100644 --- a/audio/softsynth/opl/dosbox.cpp +++ b/audio/softsynth/opl/dosbox.cpp @@ -177,10 +177,6 @@ bool OPL::init() { _emulator->WriteReg(0x105, 1); } - // FIXME: Remove this once EmulatedOPL is actually controlling playback - if (!_callback) - start(0); - return true; } diff --git a/audio/softsynth/opl/mame.cpp b/audio/softsynth/opl/mame.cpp index d43f638496..696169be09 100644 --- a/audio/softsynth/opl/mame.cpp +++ b/audio/softsynth/opl/mame.cpp @@ -61,9 +61,6 @@ bool OPL::init() { _opl = MAME::makeAdLibOPL(g_system->getMixer()->getOutputRate()); - // FIXME: Remove this once EmulatedOPL is actually controlling playback - start(0); - return (_opl != 0); } |