1#ifndef YM2413BURCZYNSKI_HH
2#define YM2413BURCZYNSKI_HH
11namespace YM2413Burczynski {
14static constexpr int SIN_BITS = 10;
15static constexpr size_t SIN_LEN = 1 << SIN_BITS;
16static constexpr size_t SIN_MASK = SIN_LEN - 1;
36 [[nodiscard]]
inline int calcOutput(
Channel& channel,
unsigned eg_cnt,
bool carrier,
37 unsigned lfo_am,
int phase);
39 unsigned lfo_pm,
unsigned lfo_am);
109 template<
typename Archive>
110 void serialize(Archive& ar,
unsigned version);
125 inline void updateTotalLevel(
Channel& channel);
126 inline void updateAttackRate(
int kcodeScaled);
127 inline void updateDecayRate(
int kcodeScaled);
128 inline void updateReleaseRate(
int kcodeScaled);
130 std::span<const unsigned, SIN_LEN> waveTable;
143 std::array<int, 2> op1_out = {0, 0};
144 bool eg_sustain{
false};
149 std::span<const uint8_t, 8> eg_sel_dp;
150 std::span<const uint8_t, 8> eg_sel_ar;
151 std::span<const uint8_t, 8> eg_sel_dr;
152 std::span<const uint8_t, 8> eg_sel_rr;
153 std::span<const uint8_t, 8> eg_sel_rs;
154 unsigned eg_mask_dp{0};
155 unsigned eg_mask_ar{0};
156 unsigned eg_mask_dr{0};
157 unsigned eg_mask_rr{0};
158 unsigned eg_mask_rs{0};
182 [[nodiscard]]
inline int calcOutput(
unsigned eg_cnt,
unsigned lfo_pm,
unsigned lfo_am,
int fm);
214 template<
typename Archive>
215 void serialize(Archive& ar,
unsigned version);
234 void reset()
override;
235 void writePort(
bool port, uint8_t value,
int offset)
override;
236 void pokeReg(uint8_t reg, uint8_t value)
override;
237 [[nodiscard]] uint8_t
peekReg(uint8_t reg)
const override;
238 void generateChannels(std::span<float*, 9 + 5> bufs,
unsigned num)
override;
241 template<
typename Archive>
242 void serialize(Archive& ar,
unsigned version);
245 void writeReg(uint8_t reg, uint8_t value);
249 void resetOperators();
251 [[nodiscard]]
inline bool isRhythm()
const;
253 [[nodiscard]]
Channel& getChannelForReg(uint8_t reg);
259 void updateCustomInstrument(
int part, uint8_t value);
261 void setRhythmFlags(uint8_t old);
265 std::array<Channel, 9> channels;
274 unsigned idleSamples;
287 std::array<std::array<uint8_t, 8>, 19> inst_tab;
290 std::array<uint8_t, 0x40> reg;
291 uint8_t registerLatch;
void setSustain(bool sustained)
void updateInstrument(std::span< const uint8_t, 8 > inst)
Sets all synthesis parameters as specified by the instrument.
FreqIndex getFrequencyIncrement() const
void updateInstrumentPart(int part, uint8_t value)
Sets some synthesis parameters as specified by the instrument.
void setFrequencyLow(uint8_t value)
Changes the lower 8 bits of the frequency for this channel.
void serialize(Archive &ar, unsigned version)
uint8_t getKeyCode() const
int getKeyScaleLevelBase() const
void setFrequency(int block_fnum)
Sets the frequency for this channel.
void setFrequencyHigh(uint8_t value)
Changes the higher 4 bits of the frequency for this channel.
int calcOutput(unsigned eg_cnt, unsigned lfo_pm, unsigned lfo_am, int fm)
Calculate the value of the current sample produced by this channel.
void setSustainLevel(uint8_t value)
Sets the sustain level [0..15].
EnvelopeState
Envelope Generator phases Note: These are ordered: phase constants are compared in the code.
void updateFrequency(Channel &channel)
Called by Channel when block_fnum changes.
void setEnvelopeSustained(bool value)
Sets the envelope type of the current instrument.
void setKeyOff(KeyPart part)
void setKeyOnOff(KeyPart part, bool enabled)
void setAttackRate(const Channel &channel, uint8_t value)
Sets the attack rate [0..15].
int calcOutput(Channel &channel, unsigned eg_cnt, bool carrier, unsigned lfo_am, int phase)
void setTotalLevel(Channel &channel, uint8_t value)
Sets the total level: [0..63].
void setFrequencyMultiplier(uint8_t value)
Sets the frequency multiplier [0..15].
void setReleaseRate(const Channel &channel, uint8_t value)
Sets the release rate [0..15].
void setWaveform(uint8_t value)
Sets the waveform: 0 = sinus, 1 = half sinus, half silence.
int calc_envelope(Channel &channel, unsigned eg_cnt, bool carrier)
void serialize(Archive &ar, unsigned version)
void setVibrato(bool value)
Enables (true) or disables (false) vibrato.
int calc_phase(Channel &channel, unsigned lfo_pm)
void setAmplitudeModulation(bool value)
Enables (true) or disables (false) amplitude modulation.
void setKeyOn(KeyPart part)
void setDecayRate(const Channel &channel, uint8_t value)
Sets the decay rate [0..15].
void setKeyScaleLevel(Channel &channel, uint8_t value)
Sets the key scale level: 0->0 / 1->1.5 / 2->3.0 / 3->6.0 dB/OCT.
void setFeedbackShift(uint8_t value)
Sets the amount of feedback [0..7].
bool isActive() const
Does this slot currently produce an output signal?
int calc_slot_mod(Channel &channel, unsigned eg_cnt, bool carrier, unsigned lfo_pm, unsigned lfo_am)
void setKeyScaleRate(bool value)
Sets the key scale rate: true->0, false->2.
void updateGenerators(Channel &channel)
Update phase increment counter of operator.
void generateChannels(std::span< float *, 9+5 > bufs, unsigned num) override
Generate the sound output.
void writePort(bool port, uint8_t value, int offset) override
Write to the YM2413 register/data port.
void serialize(Archive &ar, unsigned version)
void reset() override
Reset this YM2413 core.
void pokeReg(uint8_t reg, uint8_t value) override
Write to a YM2413 register (for debug).
float getAmplificationFactor() const override
Returns normalization factor.
uint8_t peekReg(uint8_t reg) const override
Read from a YM2413 register (for debug).
Abstract interface for the YM2413 core.
FixedPoint< 16 > FreqIndex
16.16 fixed point type for frequency calculations.
This file implemented 3 utility functions:
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)