MEAP The Library

MOZZI
MEAP The Class
C++ tips
Mozzi Reworks
mOscil
mSample
Generators
mDust
mNoise
mOperator
mSineLFO
mEnvSection
Effects
mBitcrusher
mChorus
mDigitalDelay
mFlanger
mPlateReverb
mSchroederReverb
DSP
mDelayLine
mFeedbackComb
mFeedforwardComb
mFIR
mIIR
mNaturalComb
mOnePoleLPF
mResonz
mRingz
mSchroederAllpass
mInstruments
mDrumRack
mFM4Instrument
mMarimbaInstrument
mPopInstrument
mRompler
mStringInstrument
mStringSynthInstrument
Composition
mMML
mTransitionTable
Utilities
mEventDelayMicros
mRandomDistribution

class: mFM4Instrument


four operator FM instrument

Description

mFM4Instrument is a polyphonic four-operator FM synth instrument (like the yamaha DX11 or ableton’s Operator instrument). It inherits all functions from the mInstrument parent class and adds the following functionality.

Template Parameters

template <uint16_t mPOLYPHONY = 4, uint32_t mNUM_CELLS = sin8192_int16_NUM_CELLS, class T = int16_t>

mPOLYPHONY: number of voices the instrument can play simultaneously

mNUM_CELLS: size (in samples) of wavetable used by operator oscillators

T: datatype of wavetable used by operator oscillators

Class Methods

Constructor

mFM4Instrument(const T *TABLE_NAME = sin8192_int16_DATA, uint8_t *midi_table_name = NULL)

TABLE_NAME: data array of table for operator’ oscillators

midi_table_name: (OPTIONAL) table of MIDI data you want the instrument to play


void update()

Internally updates operators’ envelopes, etc. MUST BE CALLED IN updateControl()


void next()

Calculates a sample of output. Nominally 16-bit signal level. MUST BE CALLED IN updateAudio()


void setAlgorithm(uint16_t algorithm)

Sets FM algorithm (ie how the four operators are connected together) to one of the following (parentheses indicate operators are added together, arrow indicates right side is modulated by left side. Operators to the right of the rightmost arrow are heard as carriers

void setTable(uint16_t operator_num, const T *TABLE_NAME)

Sets table of an operator’s oscillator. NOTE: if you are changing tables on the fly, all should be of the same length and data type set in your object’s template

operator_num: number of operator to modify (0 to 3)

TABLE_NAME: data array of table for operator’s oscillator


void setFixedFreq(uint16_t operator_num, float fixed_freq)

Used to take an operator in and out of fixed frequency mode. This mode is useful when using the mOperator as an LFO in a voice, or for various sound effects.

operator_num: number of operator to modify (0 to 3)


void setLoopingOn(uint16_t operator_num)

Sets an operator’s envelope to restart to attack once reaching end of release phase.

operator_num: number of operator to modify (0 to 3)


void setLoopingOff(uint16_t operator_num)

Sets an operator’s envelope to stop once it reaches end of release phase;

operator_num: number of operator to modify (0 to 3)


void setPhaseSyncOn(uint16_t operator_num)

When phase sync is enabled (which is the default), operator’s oscillator will reset to beginning of wavetable when noteOn is called

operator_num: number of operator to modify (0 to 3)


void setPhaseSyncOff(uint16_t operator_num)

See above ***

void setDroneOn(uint16_t operator_num)

Enables drone mode for an operator, bypassing the envelope, playing continuously .

operator_num: number of operator to modify (0 to 3)


void setDroneOff(uint16_t operator_num)

Disables drone mode for an operator. Envelope will control oscillator’s volume.

operator_num: number of operator to modify (0 to 3)


void setADSR(uint16_t operator_num, uint32_t attack_time, uint32_t decay_time, uint8_t sustain_level, uint32_t release_time)

Sets ADSR envelope parameters for an operator

operator_num: number of operator to modify (0 to 3)

attack_time: attack time in ms

decay_time: decay time in ms

sustain_level: sustain level (0-255)

release_time: release time in ms


void setGain(uint16_t operator_num, uint16_t gain)

Sets output gain of an operator (0-255)

operator_num: number of operator to modify (0 to 3)


Example

// ===== GLOBAL DECLARATIONS =====
mFM4Instrument<4> my_fm; // creating an FM instrument with default sine wave oscillators and 4-voice polyphony

// ===== in setup() =====
my_fm.setAlgorithm(7); // choose an FM algorithm
my_fm.setADSR(0, 400, 400, 200, 1000); // set ADSR parameters for operator #0
my_fm.setGain(1, 100); // set gain of operators 1 and 3. because they are the modulator operators in this algorithm, setting their gain sets the modulation amount
my_fm.setGain(3, 100);

// ===== in updateControl =====
my_fm.update(); // updates internal envelopes. must be called in updateControl

// ===== in updateAudio =====
int64_t out_sample = my_fm.update(); // calculates a sample of audio. will be nominally 16-bit no matter what oscillator wavetables are used

Relevant Tutorials