diff options
author | Max Horn | 2004-10-11 22:19:22 +0000 |
---|---|---|
committer | Max Horn | 2004-10-11 22:19:22 +0000 |
commit | bdf66b1a072b93bfb128f7a6368b500b81d0036f (patch) | |
tree | 31e6bf3fe6c0d4791163e3c69dd5647ee81138ad /backends | |
parent | 1036e88aa63adfe503a8d22d3b2df207d8e235c2 (diff) | |
download | scummvm-rg350-bdf66b1a072b93bfb128f7a6368b500b81d0036f.tar.gz scummvm-rg350-bdf66b1a072b93bfb128f7a6368b500b81d0036f.tar.bz2 scummvm-rg350-bdf66b1a072b93bfb128f7a6368b500b81d0036f.zip |
Make use of the new setupPremix variant (i.e. use an AudioStream subclass instead of a premix proc)
svn-id: r15523
Diffstat (limited to 'backends')
-rw-r--r-- | backends/midi/adlib.cpp | 35 | ||||
-rw-r--r-- | backends/midi/ym2612.cpp | 27 |
2 files changed, 37 insertions, 25 deletions
diff --git a/backends/midi/adlib.cpp b/backends/midi/adlib.cpp index 64b768868e..43baee673c 100644 --- a/backends/midi/adlib.cpp +++ b/backends/midi/adlib.cpp @@ -19,6 +19,7 @@ */ #include "stdafx.h" +#include "sound/audiostream.h" #include "sound/mididrv.h" #include "sound/fmopl.h" #include "sound/mixer.h" @@ -543,7 +544,7 @@ static void create_lookup_table() { // //////////////////////////////////////// -class MidiDriver_ADLIB : public MidiDriver { +class MidiDriver_ADLIB : public AudioStream, public MidiDriver { friend class AdlibPart; friend class AdlibPercussionChannel; @@ -567,6 +568,20 @@ public: MidiChannel *allocateChannel(); MidiChannel *getPercussionChannel() { return &_percussion; } // Percussion partially supported + // AudioStream API + int readBuffer(int16 *buffer, const int numSamples) { + memset(buffer, 0, 2 * numSamples); // FIXME + generate_samples(buffer, numSamples); + return numSamples; + } + int16 read() { + error("ProcInputStream::read not supported"); + } + bool isStereo() const { return false; } + bool endOfData() const { return false; } + + int getRate() const { return _mixer->getOutputRate(); } + private: bool _isOpen; bool _game_SmallHeader; @@ -624,8 +639,6 @@ private: static void struct10_setup(Struct10 * s10); static int random_nr(int a); void mc_key_on(AdlibVoice *voice, AdlibInstrument *instr, byte note, byte velocity); - - static void premix_proc(void *param, int16 *buf, uint len); }; // MidiChannel method implementations @@ -859,7 +872,7 @@ int MidiDriver_ADLIB::open() { _samples_per_tick = (_mixer->getOutputRate() << FIXP_SHIFT) / BASE_FREQ; - _mixer->setupPremix(premix_proc, this); + _mixer->setupPremix(this); return 0; } @@ -875,7 +888,7 @@ void MidiDriver_ADLIB::close() { } // Detach the premix callback handler - _mixer->setupPremix(0, 0); + _mixer->setupPremix(0); // Turn off the OPL emulation // YM3812Shutdown(); @@ -989,10 +1002,6 @@ MidiDriver *MidiDriver_ADLIB_create(SoundMixer *mixer) { // All the code brought over from IMuseAdlib -void MidiDriver_ADLIB::premix_proc(void *param, int16 *buf, uint len) { - ((MidiDriver_ADLIB *) param)->generate_samples(buf, len); -} - void MidiDriver_ADLIB::adlib_write(byte port, byte value) { if (_adlib_reg_cache[port] == value) return; @@ -1007,9 +1016,6 @@ void MidiDriver_ADLIB::adlib_write(byte port, byte value) { void MidiDriver_ADLIB::generate_samples(int16 *data, int len) { int step; - int16 *origData = data; - uint origLen = len; - do { step = len; if (step > (_next_tick >> FIXP_SHIFT)) @@ -1026,11 +1032,6 @@ void MidiDriver_ADLIB::generate_samples(int16 *data, int len) { data += step; len -= step; } while (len); - - // Convert mono data to stereo - for (int i = (origLen - 1); i >= 0; i--) { - origData[2 * i] = origData[2 * i + 1] = origData[i]; - } } void MidiDriver_ADLIB::reset_tick() { diff --git a/backends/midi/ym2612.cpp b/backends/midi/ym2612.cpp index 3a5b1e1cab..f701a1541e 100644 --- a/backends/midi/ym2612.cpp +++ b/backends/midi/ym2612.cpp @@ -24,6 +24,7 @@ #include "stdafx.h" #include "common/util.h" +#include "sound/audiostream.h" #include "sound/mididrv.h" #include "sound/mixer.h" @@ -157,7 +158,7 @@ public: void sysEx_customInstrument(uint32 type, byte *instr); }; -class MidiDriver_YM2612 : public MidiDriver { +class MidiDriver_YM2612 : public AudioStream, public MidiDriver { protected: MidiChannel_YM2612 *_channel[16]; @@ -178,7 +179,6 @@ protected: void rate(uint16 r); void generate_samples(int16 *buf, int len); - static void premix_proc(void *param, int16 *buf, uint len); public: MidiDriver_YM2612(SoundMixer *mixer); @@ -198,6 +198,21 @@ public: MidiChannel *allocateChannel() { return 0; } MidiChannel *getPercussionChannel() { return 0; } + + + // AudioStream API + int readBuffer(int16 *buffer, const int numSamples) { + memset(buffer, 0, 2 * numSamples); // FIXME + generate_samples(buffer, numSamples / 2); + return numSamples; + } + int16 read() { + error("ProcInputStream::read not supported"); + } + bool isStereo() const { return true; } + bool endOfData() const { return false; } + + int getRate() const { return _mixer->getOutputRate(); } }; //////////////////////////////////////// @@ -754,7 +769,7 @@ MidiDriver_YM2612::~MidiDriver_YM2612() { int MidiDriver_YM2612::open() { if (_isOpen) return MERR_ALREADY_OPEN; - _mixer->setupPremix(premix_proc, this); + _mixer->setupPremix(this); _isOpen = true; return 0; } @@ -765,7 +780,7 @@ void MidiDriver_YM2612::close() { _isOpen = false; // Detach the premix callback handler - _mixer->setupPremix(0, 0); + _mixer->setupPremix(0); } void MidiDriver_YM2612::setTimerCallback(void *timer_param, Timer::TimerProc timer_proc) { @@ -822,10 +837,6 @@ void MidiDriver_YM2612::sysEx(byte *msg, uint16 length) { _channel[msg[1]]->sysEx_customInstrument('EUP ', &msg[2]); } -void MidiDriver_YM2612::premix_proc(void *param, int16 *buf, uint len) { - ((MidiDriver_YM2612 *) param)->generate_samples(buf, len); -} - void MidiDriver_YM2612::generate_samples(int16 *data, int len) { int step; |