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 "cstd.hh"
7 #include "outer.hh"
8 #include <cmath>
9 #include <memory>
10 
11 namespace openmsx {
12 
13 // Debuggable
14 
15 YM2413::Debuggable::Debuggable(
16  MSXMotherBoard& motherBoard_, const std::string& name_)
17  : SimpleDebuggable(motherBoard_, name_ + " regs", "MSX-MUSIC", 0x40)
18 {
19 }
20 
21 byte YM2413::Debuggable::read(unsigned address)
22 {
23  auto& ym2413 = OUTER(YM2413, debuggable);
24  return ym2413.core->peekReg(address);
25 }
26 
27 void YM2413::Debuggable::write(unsigned address, byte value, EmuTime::param time)
28 {
29  auto& ym2413 = OUTER(YM2413, debuggable);
30  ym2413.writeReg(address, value, time);
31 }
32 
33 
34 // YM2413
35 
36 static std::unique_ptr<YM2413Core> createCore(const DeviceConfig& config)
37 {
38  if (config.getChildDataAsBool("alternative", false)) {
39  return std::make_unique<YM2413Burczynski::YM2413>();
40  } else {
41  return std::make_unique<YM2413Okazaki::YM2413>();
42  }
43 }
44 
45 constexpr auto INPUT_RATE = unsigned(cstd::round(YM2413Core::CLOCK_FREQ / 72.0));
46 
47 YM2413::YM2413(const std::string& name_, const DeviceConfig& config)
48  : ResampledSoundDevice(config.getMotherBoard(), name_, "MSX-MUSIC", 9 + 5, INPUT_RATE, false)
49  , core(createCore(config))
50  , debuggable(config.getMotherBoard(), getName())
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:131
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
void updateStream(EmuTime::param time)
Definition: SoundDevice.cc:136
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
constexpr double round(double x)
Definition: cstd.hh:318
static constexpr int CLOCK_FREQ
Input clock frequency.
Definition: YM2413Core.hh:40
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
YM2413
Definition: YM2413.cc:88
constexpr auto INPUT_RATE
Definition: SCC.cc:113
#define OUTER(type, member)
Definition: outer.hh:38
YM2413(const std::string &name, const DeviceConfig &config)
Definition: YM2413.cc:47
void registerSound(const DeviceConfig &config)
Registers this sound device with the Mixer.
Definition: SoundDevice.cc:90