openMSX
YM2413.cc
Go to the documentation of this file.
1 #include "YM2413.hh"
2 #include "YM2413Okazaki.hh"
3 #include "YM2413Burczynski.hh"
4 #include "DeviceConfig.hh"
5 #include "serialize.hh"
6 #include "outer.hh"
7 #include <cmath>
8 #include <memory>
9 
10 namespace openmsx {
11 
12 // Debuggable
13 
14 YM2413::Debuggable::Debuggable(
15  MSXMotherBoard& motherBoard_, const std::string& name_)
16  : SimpleDebuggable(motherBoard_, name_ + " regs", "MSX-MUSIC", 0x40)
17 {
18 }
19 
20 byte YM2413::Debuggable::read(unsigned address)
21 {
22  auto& ym2413 = OUTER(YM2413, debuggable);
23  return ym2413.core->peekReg(address);
24 }
25 
26 void YM2413::Debuggable::write(unsigned address, byte value, EmuTime::param time)
27 {
28  auto& ym2413 = OUTER(YM2413, debuggable);
29  ym2413.writeReg(address, value, time);
30 }
31 
32 
33 // YM2413
34 
35 static std::unique_ptr<YM2413Core> createCore(const DeviceConfig& config)
36 {
37  if (config.getChildDataAsBool("alternative", false)) {
38  return std::make_unique<YM2413Burczynski::YM2413>();
39  } else {
40  return std::make_unique<YM2413Okazaki::YM2413>();
41  }
42 }
43 
44 YM2413::YM2413(const std::string& name_, const DeviceConfig& config)
45  : ResampledSoundDevice(config.getMotherBoard(), name_, "MSX-MUSIC", 9 + 5)
46  , core(createCore(config))
47  , debuggable(config.getMotherBoard(), getName())
48 {
49  float input = YM2413Core::CLOCK_FREQ / 72.0f;
50  setInputRate(lrintf(input));
51 
52  registerSound(config);
53 }
54 
56 {
58 }
59 
60 void YM2413::reset(EmuTime::param time)
61 {
62  updateStream(time);
63  core->reset();
64 }
65 
66 void YM2413::writeReg(byte reg, byte value, EmuTime::param time)
67 {
68  updateStream(time);
69  core->writeReg(reg, value);
70 }
71 
72 void YM2413::generateChannels(float** bufs, unsigned num)
73 {
74  core->generateChannels(bufs, num);
75 }
76 
77 float YM2413::getAmplificationFactorImpl() const
78 {
79  return core->getAmplificationFactor();
80 }
81 
82 
83 template<typename Archive>
84 void YM2413::serialize(Archive& ar, unsigned /*version*/)
85 {
86  ar.serializePolymorphic("ym2413", *core);
87 }
89 
90 } // namespace openmsx
void writeReg(byte reg, byte value, EmuTime::param time)
Definition: YM2413.cc:66
const std::string & getName() const
Get the unique name that identifies this sound device.
Definition: SoundDevice.hh:24
void unregisterSound()
Unregisters this sound device with the Mixer.
Definition: SoundDevice.cc:130
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
static const int CLOCK_FREQ
Input clock frequency.
Definition: YM2413Core.hh:40
void updateStream(EmuTime::param time)
Definition: SoundDevice.cc:135
void setInputRate(unsigned sampleRate)
Definition: SoundDevice.hh:108
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void serialize(Archive &ar, unsigned version)
Definition: YM2413.cc:84
void reset(EmuTime::param time)
Definition: YM2413.cc:60
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:840
YM2413
Definition: YM2413.cc:88
#define OUTER(type, member)
Definition: outer.hh:38
YM2413(const std::string &name, const DeviceConfig &config)
Definition: YM2413.cc:44
void registerSound(const DeviceConfig &config)
Registers this sound device with the Mixer.
Definition: SoundDevice.cc:89