1#ifndef YM2413OKAZAKI_HH
2#define YM2413OKAZAKI_HH
11namespace YM2413Okazaki {
31 void initCarrier (std::span<const uint8_t, 8> data);
34 void setKR(uint8_t value);
36 void setML(uint8_t value);
38 void setKL(uint8_t value);
40 void setTL(uint8_t value);
42 void setWF(uint8_t value);
44 void setFB(uint8_t value);
46 void setSL(uint8_t value);
48 std::span<const unsigned, PG_WIDTH>
WF;
49 std::span<const uint8_t, 16 * 8>
KL;
80 [[nodiscard]]
unsigned calc_phase(
unsigned lfo_pm);
81 template<
bool HAS_AM,
bool FIXED_ENV>
83 template<
bool HAS_AM> [[nodiscard]]
unsigned calc_fixed_env()
const;
85 template<
bool HAS_AM,
bool FIXED_ENV>
86 [[nodiscard]]
int calc_slot_car(
unsigned lfo_pm,
int lfo_am,
int fm,
unsigned fixed_env);
87 template<
bool HAS_AM,
bool HAS_FB,
bool FIXED_ENV>
88 [[nodiscard]]
int calc_slot_mod(
unsigned lfo_pm,
int lfo_am,
unsigned fixed_env);
92 [[nodiscard]]
int calc_slot_cym(
unsigned phase7,
unsigned phase8);
93 [[nodiscard]]
int calc_slot_hat(
unsigned phase7,
unsigned phase8,
bool noise);
95 void updateTLL(
unsigned freq,
bool actAsCarrier);
98 void updateAll(
unsigned freq,
bool actAsCarrier);
100 template<
typename Archive>
101 void serialize(Archive& ar,
unsigned version);
131 void setSustain(
bool sustain,
bool modActAsCarrier);
137 template<
typename Archive>
138 void serialize(Archive& ar,
unsigned version);
147 void reset()
override;
148 void writePort(
bool port, uint8_t value,
int offset)
override;
149 void pokeReg(uint8_t reg, uint8_t data)
override;
150 [[nodiscard]] uint8_t
peekReg(uint8_t reg)
const override;
151 void generateChannels(std::span<float*, 9 + 5> bufs,
unsigned num)
override;
154 [[nodiscard]]
Patch&
getPatch(
unsigned instrument,
bool carrier);
156 template<
typename Archive>
157 void serialize(Archive& ar,
unsigned version);
160 void writeReg(uint8_t r, uint8_t data);
172 void setRhythmFlags(uint8_t old);
173 void update_key_status();
174 [[nodiscard]]
bool isRhythm()
const;
175 [[nodiscard]]
unsigned getFreq(
unsigned channel)
const;
177 template<
unsigned FLAGS>
178 void calcChannel(
Channel& ch, std::span<float> buf);
182 std::array<Channel, 9> channels;
194 std::array<std::array<Patch, 2>, 19> patches;
197 std::array<uint8_t, 0x40> reg;
198 uint8_t registerLatch;
Abstract interface for the YM2413 core.
void serialize(Archive &ar, unsigned version)
void setSustain(bool sustain, bool modActAsCarrier)
void setPatch(unsigned num, YM2413 &ym2413)
void reset(YM2413 &ym2413)
void setSL(uint8_t value)
Sets sustain level [0..15].
void setFB(uint8_t value)
Sets the amount of feedback [0..7].
Patch()
Creates an uninitialized Patch object; call initXXX() before use.
void initModulator(std::span< const uint8_t, 8 > data)
std::span< const unsigned, PG_WIDTH > WF
void setTL(uint8_t value)
Set volume (total level) [0..63].
std::span< const uint8_t, 16 *8 > KL
void setKL(uint8_t value)
Sets Key scale level [0..3].
void initCarrier(std::span< const uint8_t, 8 > data)
void setML(uint8_t value)
Sets the frequency multiplier factor [0..15].
void setWF(uint8_t value)
Set waveform [0..1].
void setKR(uint8_t value)
Sets the Key Scale of Rate (0 or 1).
void serialize(Archive &ar, unsigned version)
void setVolume(unsigned value)
int calc_slot_snare(bool noise)
int calc_slot_mod(unsigned lfo_pm, int lfo_am, unsigned fixed_env)
void setPatch(const Patch &patch)
void updateTLL(unsigned freq, bool actAsCarrier)
void calc_envelope_outline(unsigned &out)
EnvPhaseIndex eg_phase_max
void updatePG(unsigned freq)
void updateRKS(unsigned freq)
void setEnvelopeState(EnvelopeState state)
std::array< unsigned, 8 > dPhase
unsigned calc_envelope(int lfo_am, unsigned fixed_env)
unsigned calc_phase(unsigned lfo_pm)
unsigned calc_fixed_env() const
std::span< const int, 16 > dPhaseDRTableRks
int calc_slot_hat(unsigned phase7, unsigned phase8, bool noise)
int calc_slot_cym(unsigned phase7, unsigned phase8)
int calc_slot_car(unsigned lfo_pm, int lfo_am, int fm, unsigned fixed_env)
void updateAll(unsigned freq, bool actAsCarrier)
uint8_t peekReg(uint8_t reg) const override
Read from a YM2413 register (for debug).
void serialize(Archive &ar, unsigned version)
void writePort(bool port, uint8_t value, int offset) override
Write to the YM2413 register/data port.
void generateChannels(std::span< float *, 9+5 > bufs, unsigned num) override
Generate the sound output.
void pokeReg(uint8_t reg, uint8_t data) override
Write to a YM2413 register (for debug).
float getAmplificationFactor() const override
Returns normalization factor.
void reset() override
Reset this YM2413 core.
Patch & getPatch(unsigned instrument, bool carrier)
This file implemented 3 utility functions: