1#ifndef YM2413BURCZYNSKI_HH
2#define YM2413BURCZYNSKI_HH
13namespace YM2413Burczynski {
38 [[nodiscard]]
int calcOutput(
const Channel& channel,
unsigned eg_cnt,
bool carrier,
39 unsigned lfo_am,
int phase);
41 unsigned lfo_pm,
unsigned lfo_am);
111 template<
typename Archive>
112 void serialize(Archive& ar,
unsigned version);
124 void updateTotalLevel(
const Channel& channel);
125 void updateAttackRate(
int kcodeScaled);
126 void updateDecayRate(
int kcodeScaled);
127 void updateReleaseRate(
int kcodeScaled);
129 std::span<const unsigned, SIN_LEN> waveTable;
142 std::array<int, 2> op1_out = {0, 0};
143 bool eg_sustain{
false};
148 std::span<const uint8_t, 8> eg_sel_dp;
149 std::span<const uint8_t, 8> eg_sel_ar;
150 std::span<const uint8_t, 8> eg_sel_dr;
151 std::span<const uint8_t, 8> eg_sel_rr;
152 std::span<const uint8_t, 8> eg_sel_rs;
153 unsigned eg_mask_dp{0};
154 unsigned eg_mask_ar{0};
155 unsigned eg_mask_dr{0};
156 unsigned eg_mask_rr{0};
157 unsigned eg_mask_rs{0};
181 [[nodiscard]]
int calcOutput(
unsigned eg_cnt,
unsigned lfo_pm,
unsigned lfo_am,
int fm);
213 template<
typename Archive>
214 void serialize(Archive& ar,
unsigned version);
233 void reset()
override;
234 void writePort(
bool port, uint8_t value,
int offset)
override;
235 void pokeReg(uint8_t reg, uint8_t value)
override;
236 [[nodiscard]] uint8_t
peekReg(uint8_t reg)
const override;
237 void generateChannels(std::span<float*, 9 + 5> bufs,
unsigned num)
override;
240 template<
typename Archive>
241 void serialize(Archive& ar,
unsigned version);
244 void writeReg(uint8_t reg, uint8_t value);
248 void resetOperators();
250 [[nodiscard]]
bool isRhythm()
const;
252 [[nodiscard]]
Channel& getChannelForReg(uint8_t reg);
258 void updateCustomInstrument(
int part, uint8_t value);
260 void setRhythmFlags(uint8_t old);
264 std::array<Channel, 9> channels;
273 unsigned idleSamples;
286 std::array<std::array<uint8_t, 8>, 19> inst_tab;
289 std::array<uint8_t, 0x40> reg;
290 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].
int calc_phase(const Channel &channel, unsigned lfo_pm)
int calc_slot_mod(const Channel &channel, unsigned eg_cnt, bool carrier, unsigned lfo_pm, unsigned lfo_am)
int calc_envelope(const Channel &channel, unsigned eg_cnt, bool carrier)
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].
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.
void updateFrequency(const Channel &channel)
Called by Channel when block_fnum changes.
int calcOutput(const Channel &channel, unsigned eg_cnt, bool carrier, unsigned lfo_am, int phase)
void serialize(Archive &ar, unsigned version)
void setVibrato(bool value)
Enables (true) or disables (false) vibrato.
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 setFeedbackShift(uint8_t value)
Sets the amount of feedback [0..7].
void setKeyScaleLevel(const Channel &channel, uint8_t value)
Sets the key scale level: 0->0 / 1->1.5 / 2->3.0 / 3->6.0 dB/OCT.
void updateGenerators(const Channel &channel)
Update phase increment counter of operator.
void setTotalLevel(const Channel &channel, uint8_t value)
Sets the total level: [0..63].
bool isActive() const
Does this slot currently produce an output signal?
void setKeyScaleRate(bool value)
Sets the key scale rate: true->0, false->2.
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.
constexpr size_t SIN_MASK
This file implemented 3 utility functions: