ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

fmopl.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef AUDIO_FMOPL_H
00024 #define AUDIO_FMOPL_H
00025 
00026 #include "audio/audiostream.h"
00027 
00028 #include "common/func.h"
00029 #include "common/ptr.h"
00030 #include "common/scummsys.h"
00031 
00032 namespace Audio {
00033 class SoundHandle;
00034 }
00035 
00036 namespace Common {
00037 class String;
00038 }
00039 
00040 namespace OPL {
00041 
00042 class OPL;
00043 
00044 class Config {
00045 public:
00046     enum OplFlags {
00047         kFlagOpl2       = (1 << 0),
00048         kFlagDualOpl2   = (1 << 1),
00049         kFlagOpl3       = (1 << 2)
00050     };
00051 
00055     enum OplType {
00056         kOpl2,
00057         kDualOpl2,
00058         kOpl3
00059     };
00060 
00061     typedef int8 DriverId;
00062     struct EmulatorDescription {
00063         const char *name;
00064         const char *description;
00065 
00066         DriverId id;    // A unique ID for each driver
00067         uint32 flags;   // Capabilities of this driver
00068     };
00069 
00074     static const EmulatorDescription *getAvailable() { return _drivers; }
00075 
00079     static DriverId parse(const Common::String &name);
00080 
00085     static const EmulatorDescription *findDriver(DriverId id);
00086 
00092     static DriverId detect(OplType type);
00093 
00097     static OPL *create(DriverId driver, OplType type);
00098 
00103     static OPL *create(OplType type = kOpl2);
00104 
00105 private:
00106     static const EmulatorDescription _drivers[];
00107 };
00108 
00112 typedef Common::Functor0<void> TimerCallback;
00113 
00117 class OPL {
00118 private:
00119     static bool _hasInstance;
00120 public:
00121     OPL();
00122     virtual ~OPL() { _hasInstance = false; }
00123 
00129     virtual bool init() = 0;
00130 
00134     virtual void reset() = 0;
00135 
00142     virtual void write(int a, int v) = 0;
00143 
00150     virtual byte read(int a) = 0;
00151 
00161     virtual void writeReg(int r, int v) = 0;
00162 
00166     void start(TimerCallback *callback, int timerFrequency = kDefaultCallbackFrequency);
00167 
00171     void stop();
00172 
00177     virtual void setCallbackFrequency(int timerFrequency) = 0;
00178 
00179     enum {
00183         kDefaultCallbackFrequency = 250
00184     };
00185 
00186 protected:
00190     virtual void startCallbacks(int timerFrequency) = 0;
00191 
00195     virtual void stopCallbacks() = 0;
00196 
00200     Common::ScopedPtr<TimerCallback> _callback;
00201 };
00202 
00209 class RealOPL : public OPL {
00210 public:
00211     RealOPL();
00212     virtual ~RealOPL();
00213 
00214     // OPL API
00215     void setCallbackFrequency(int timerFrequency);
00216 
00217 protected:
00218     // OPL API
00219     void startCallbacks(int timerFrequency);
00220     void stopCallbacks();
00221 
00222 private:
00223     static void timerProc(void *refCon);
00224     void onTimer();
00225 
00226     uint _baseFreq;
00227     uint _remainingTicks;
00228 
00229     enum {
00230         kMaxFreq = 100
00231     };
00232 };
00233 
00240 class EmulatedOPL : public OPL, protected Audio::AudioStream {
00241 public:
00242     EmulatedOPL();
00243     virtual ~EmulatedOPL();
00244 
00245     // OPL API
00246     void setCallbackFrequency(int timerFrequency);
00247 
00248     // AudioStream API
00249     int readBuffer(int16 *buffer, const int numSamples);
00250     int getRate() const;
00251     bool endOfData() const { return false; }
00252 
00253 protected:
00254     // OPL API
00255     void startCallbacks(int timerFrequency);
00256     void stopCallbacks();
00257 
00268     virtual void generateSamples(int16 *buffer, int numSamples) = 0;
00269 
00270 private:
00271     int _baseFreq;
00272 
00273     enum {
00274         FIXP_SHIFT = 16
00275     };
00276 
00277     int _nextTick;
00278     int _samplesPerTick;
00279 
00280     Audio::SoundHandle *_handle;
00281 };
00282 
00283 } // End of namespace OPL
00284 
00285 #endif


Generated on Sat May 18 2019 05:01:02 for ResidualVM by doxygen 1.7.1
curved edge   curved edge