QM816

QM816 - implements a Quadrature-Amplitude synthesizer. This technique was used in early digital FM synths, since it allowed allowed a cheap implementation of the same thing as long as the modulator was a sinusoidal waveform.

It has 16 2 operator channels that can be individually paired-up for 4 operator channels, for more complex sounds. Also all operators have the option for feedback, including carriers. 2 operator channels have 2, 4 operator channels have 3*4 algorithms.

The audio module generates a few default waveforms upon startup, but further ones can be supplied from files, or generated by code. Some waveform generation code is already supplied with the synth's code.

To do: Implement glissando/legato support. Maybe replace the interpolation filter later on.

class QM816 : AudioModule {}

Constructors

this
this()

Creates an instance of QM816

Members

Aliases

ChFun
alias ChFun = void delegate(int chNum, size_t length) @(nogc) pure nothrow
Undocumented in source.

Enums

ChCtrlFlags
enum ChCtrlFlags

Defines channel control flags.

ChannelParamNums
enum ChannelParamNums

Defines channel parameter numbers, within the unregistered namespace.

ChannelRegParams
enum ChannelRegParams

Defines channel parameters within the registered namespace

GlobalParamNums
enum GlobalParamNums

Defines global parameter nummbers, within the unregistered namespace

OpCtrlFlags
enum OpCtrlFlags

Defines control values

OperatorParamNums
enum OperatorParamNums

Defines operator parameter numbers, within the unregistered namespace.

TuneCtrlFlags
enum TuneCtrlFlags
Undocumented in source.

Functions

getInternalWaveformIDList
uint[] getInternalWaveformIDList()

Returns the list of internal waveform IDs if there are any.

getInternalWaveformNames
string[] getInternalWaveformNames()

Returns the names of the internal waveforms if there are any.

getParameters
MValue[] getParameters()

Returns all the possible parameters this module has.

getWaveformData
const(ubyte)[] getWaveformData(uint id)

Returns the waveform data from the

getWaveformDataFormat
WaveFormat getWaveformDataFormat(uint id)

Returns the format of the selected waveform

getWaveformIDList
uint[] getWaveformIDList()

Returns the available waveform ID list

keyOff
void keyOff(ubyte note, ubyte ch, float vel, float bend)

Implements a key-off event.

keyOn
void keyOn(ubyte note, ubyte ch, float vel, float bend)

Implements a key-on event.

midiReceive
void midiReceive(UMP data0, uint data1, uint data2, uint data3)

MIDI 2.0 data received here.

moduleSetup
void moduleSetup(ubyte[] inputs, ubyte[] outputs, int sampleRate, size_t bufferSize, ModuleManager handler)

Sets the module up.

prgRecall
void prgRecall(ubyte ch, ubyte prg, ubyte bank)

Recalls a program

readParam_double
double readParam_double(uint presetID, uint paramID)

Reads the given value (int).

readParam_int
int readParam_int(uint presetID, uint paramID)

Reads the given value (int).

readParam_long
long readParam_long(uint presetID, uint paramID)

Reads the given value (int).

readParam_string
string readParam_string(uint presetID, uint paramID)

Reads the given value (int).

renderFrame
void renderFrame(float*[] input, float*[] output)

Renders the current audio frame.

resetHPF
void resetHPF(int i)

Sets the given HPF with the given value.

resetLPF
void resetLPF(int i)

Sets the given LPF with the given value.

setALFO
void setALFO()
Undocumented in source. Be warned that the author may not have intended to support it.
setChDeleg
void setChDeleg(uint chCtrl, uint chNum, uint chCtrl0)

Sets the channel delegates

setPLFO
void setPLFO()
Undocumented in source. Be warned that the author may not have intended to support it.
setRegisteredParam
void setRegisteredParam(T val, ubyte[2] paramNum, ubyte type, ubyte chNum)

Sets a registered parameter

setUnregisteredParam
void setUnregisteredParam(uint val, ubyte[2] paramNum, ubyte chNum)

Sets an unregistered parameter (MIDI 2.0)

sysExCmd
void sysExCmd(ubyte[] msg)

Implements system exclusive command handling.

updateChannelM00
void updateChannelM00(int chNum, size_t length)

Algorithm Mode 0/0 (Serial)

updateChannelM01
void updateChannelM01(int chNum, size_t length)

Algorithm Mode 0/1 (Parallel)

updateChannelM100
void updateChannelM100(int chNum, size_t length)

Algorithm Mode1/00 (S0->S1->P0->P1)

updateChannelM101
void updateChannelM101(int chNum, size_t length)

Algorithm Mode1/01 S0->S1->P0-> P1->

updateChannelM110
void updateChannelM110(int chNum, size_t length)

Algorithm Mode1/10 S0\ ->P0->P1-> S1/

updateChannelM111
void updateChannelM111(int chNum, size_t length)

Algorithm Mode1/11 S0\ ->P0-> S1/ P1->

updateChannelM200
void updateChannelM200(int chNum, size_t length)

Algorithm Mode2/00 S0->S1\ ->P1-> P0/

updateChannelM201
void updateChannelM201(int chNum, size_t length)

Algorithm Mode2/01 /P0-> S0->S1 \P1->

updateChannelM210
void updateChannelM210(int chNum, size_t length)

Algorithm Mode2/10 S0\ S1-->P1-> P0/

updateChannelM211
void updateChannelM211(int chNum, size_t length)

Algorithm Mode2/11 S0\ /P0-> - S1/ \P1->

updateChannelM300
void updateChannelM300(int chNum, size_t length)

Algorithm Mode3/00 S0->S1-> P0->P1->

updateChannelM301
void updateChannelM301(int chNum, size_t length)

Algorithm Mode3/01 />S1-> S0->P0-> \>P1->

updateChannelM310
void updateChannelM310(int chNum, size_t length)

Algorithm Mode3/10 S0-> S1-> P0->P1->

updateChannelM311
void updateChannelM311(int chNum, size_t length)

Algorithm Mode3/11 S0-> S1-> P0-> P1->

updateChannelMD
void updateChannelMD(int chNum, size_t length)

Dummy algorithm for combined channels

updateOperator
double updateOperator(Operator op, __m128 chCtrl)

Updates an operator for a cycle chCtrl index notation: 0: velocity, 1: modulation wheel, 2: Amplitude LFO, 3: Extra Envelop Generator Returns the sum of the level control values for use with the resonant mode

updatePitchbend2Op
void updatePitchbend2Op(Operator op0, Operator op1, Channel ch, ChControllers chCtrl)

Updates automatic and manual pitchbend values (channel-assignable envelop, LFO, pitchbend CTRL) for 2 operators.

updatePitchbend4Op
void updatePitchbend4Op(Operator op0, Operator op1, Operator op2, Operator op3, Channel ch, ChControllers chCtrl)

Updates automatic and manual pitchbend values (channel-assignable envelop, LFO, pitchbend CTRL) for 4 operators.

waveformDataReceive
int waveformDataReceive(uint id, ubyte[] rawData, WaveFormat format)

Receives waveform data that has been loaded from disk for reading. Returns zero if successful, or a specific errorcode.

writeParam_double
int writeParam_double(uint presetID, uint paramID, double value)

Restores a parameter to the given preset. Returns an errorcode on failure.

writeParam_int
int writeParam_int(uint presetID, uint paramID, int value)

Restores a parameter to the given preset. Returns an errorcode on failure.

writeParam_long
int writeParam_long(uint presetID, uint paramID, long value)

Restores a parameter to the given preset. Returns an errorcode on failure.

writeParam_string
int writeParam_string(uint presetID, uint paramID, string value)

Restores a parameter to the given preset. Returns an errorcode on failure.

Static functions

generatePulseWave
short[1024] generatePulseWave(int width)

Generates a pulse wave.

generateSinewave
short[1024] generateSinewave(ubyte[4] q)

Generates a waveform from a sinewave fragment (quarter).

generateTriangularWave
short[1024] generateTriangularWave(int shape)

Generates a triangular waveform. shape controls the shape of the triangular waveform, allowing it to be morphed between triangle, saw, and ramp. `

integrateTriangularWave
short[1024] integrateTriangularWave(short[1024] input)
Undocumented in source. Be warned that the author may not have intended to support it.

Static variables

ADSR_TIME_TABLE
float[128] ADSR_TIME_TABLE;

Contains a table to calculate Attack, Decay, and Release values.

CHNL_UPDATE_CONSTS
string CHNL_UPDATE_CONSTS;

Macro for channel update constants that need to be calculated once per frame Kept in at one place to make updates easier and more consistent

CHNL_UPDATE_CONSTS0
string CHNL_UPDATE_CONSTS0;

Macro for channel update constants that need to be calculated once per frame, for combined channels' second half Kept in at one place to make updates easier and more consistent

CHNL_UPDATE_CONSTS_CYCL
string CHNL_UPDATE_CONSTS_CYCL;

Macro for channel update constants that need to be calculated for each cycle Kept in at one place to make updates easier and more consistent

CHNL_UPDATE_CONSTS_CYCL0
string CHNL_UPDATE_CONSTS_CYCL0;

Macro for channel update constants that need to be calculated for each cycle for combined channels' second half Kept in at one place to make updates easier and more consistent

CHNL_UPDATE_MIX
string CHNL_UPDATE_MIX;

Macro for output mixing

CHNL_UPDATE_MIX0
string CHNL_UPDATE_MIX0;

Macro for output mixing in case of combo modes

RESAMPLING_TABLE
float[4][4] RESAMPLING_TABLE;

Used for quick resampling of the 55.125/60kHz output to 44.1/48kHz, based on Cubic Lagrange interpolation.

SUSTAIN_CONTROL_TIME_TABLE
float[63] SUSTAIN_CONTROL_TIME_TABLE;

Contains a table to calculate Sustain control values.

Structs

ChControllers
struct ChControllers

Stores channel controller values (modwheel, velocity, etc.)

Channel
struct Channel

Defines channel common parameters.

Operator
struct Operator

Implements a single operator.

Preset
struct Preset

Defines a preset.

Variables

aLFOBuf
float[] aLFOBuf;

Amplitude LFO buffer. Values are between 0.0 and 1.0

aLFOFreq
float aLFOFreq;

ALFO filter y[n-1] ALFO filter factor 0 to 1 ALFO frequency

aLFOPos
uint aLFOPos;

Stores ALFO position

aLFORate
uint aLFORate;

Stores ALFO rate

bankNum
ubyte[16] bankNum;

Bank numbers per channels.

ccLow
ubyte[64][16] ccLow;

Used as a keepsake for MIDI 1.0 control change values.

chCtrls
ChControllers[16] chCtrls;

Channel control data.

chDeleg
ChFun[16] chDeleg;

Channel update delegates

channels
Channel[16] channels;

Channel data. See rendering function on updating.

dummyBuf
float[] dummyBuf;

Dummy buffer Only used if one or more outputs haven't been defined

filterCtrl
float[8] filterCtrl;

Stores control values of the output values. Layout: [LF, LQ, RF, RQ, AF, AQ, BF, BQ]

hpf
IIRBank hpf;

High pass filter, after interpolation filter.

hpfCtrl
float[8] hpfCtrl;

Stores high-pass filter control values

initBuffers
__m128[] initBuffers;

Initial mixing buffers Output is directed there before filtering and resampling Layout is: LRAB

intBufSize
size_t intBufSize;

Internal buffer sizes

intSlmpRate
int intSlmpRate;

Internal sampling frequency

lfoWaveform
ubyte[2] lfoWaveform;

Keeps the registered/unregistered parameter positions (LSB = 1). Stores LFO waveform selection. 0: Pitch; 1: Amplitude/Ringmod (if bit 7 is set)

lpf
IIRBank lpf;

Low pass filter, before interpolation filter.

mixdownVal
float mixdownVal;

Mixdown value. Used for final mixing.

operators
Operator[32] operators;

Operator data. See rendering function on updating.

pLFOFreq
float pLFOFreq;

Current frequency of PLFO

pLFOOut
float pLFOOut;

Pitch LFO output. Values are between -1.0 and 1.0

pLFOPos
uint pLFOPos;

Stores PLFO position

pLFORate
uint pLFORate;

Stores PLFO rate

paramTemp
ubyte[4] paramTemp;

Stores temporary parameter values 0: MSB of sel unregistered param 1: LSB of sel unregistered param 2: MSB of sel registered param 3: LSB of sel registered param

presetNum
ubyte[16] presetNum;

Preset numbers per channels.

soundBank
Preset[128][8] soundBank;

Stores presets. 8 banks of 128 presets are available for a total of 1024. If a channel combination is being used, then bank pairs (0-1, 2-3, etc) will store their primary and secondary halves, and calling either will load both halves.

sysExBuf
ubyte[32] sysExBuf;

SysEx command buffer [0-30] + length [31]

wavetables
short[1024][128] wavetables;

Contains the wavetables for the operators and LFOs. Loaded from a 16 bit wave file. Full range is used for extra precision.

Inherited Members

From AudioModule

ModuleInfo
struct ModuleInfo

Contains all data related to module info.

bufferSize
size_t bufferSize;

The size of the output buffers (must kept as a constant)

sampleRate
int sampleRate;

The sample rate that the audio subsystem runs at

info
ModuleInfo info;

Basic info about the plugin

handler
ModuleManager handler;

The main audio handler, also MIDI outs can be passed there

StreamIDSet
alias StreamIDSet = SortedList!(ubyte, "a < b", false)
Undocumented in source.
enabledInputs
StreamIDSet enabledInputs;

List of enabled input channel numbers

enabledOutputs
StreamIDSet enabledOutputs;

List of enabled output channel numbers

midiOut
void delegate(UMP data0, uint data1 = 0, uint data2 = 0, uint data3 = 0) midiOut;

A delegate where MIDI messages are being routed

getInfo
ModuleInfo getInfo()

Returns the basic informations about this module.

getSamplerate
int getSamplerate()

Returns the current sample rate.

moduleSetup
void moduleSetup(ubyte[] inputs, ubyte[] outputs, int sampleRate, size_t bufferSize, ModuleManager handler)

Sets the module up.

midiReceive
void midiReceive(UMP data0, uint data1, uint data2, uint data3)

MIDI 2.0 data received here.

renderFrame
void renderFrame(float*[] input, float*[] output)

Renders the current audio frame.

waveformDataReceive
int waveformDataReceive(uint id, ubyte[] rawData, WaveFormat format)

Receives waveform data that has been loaded from disk for reading. Returns zero if successful, or a specific errorcode.

waveformSlice
int waveformSlice(uint id, uint src, uint pos, uint length)

Creates a new waveform from an existing one using slicing.

getWaveformData
const(ubyte)[] getWaveformData(uint id)

Returns the waveform data from the

getWaveformDataFormat
WaveFormat getWaveformDataFormat(uint id)

Returns the format of the selected waveform

getWaveformIDList
uint[] getWaveformIDList()

Returns the available waveform ID list

getInternalWaveformIDList
uint[] getInternalWaveformIDList()

Returns the list of internal waveform IDs if there are any.

getInternalWaveformNames
string[] getInternalWaveformNames()

Returns the names of the internal waveforms if there are any.

writeParam_int
int writeParam_int(uint presetID, uint paramID, int value)

Restores a parameter to the given preset. Returns an errorcode on failure.

writeParam_long
int writeParam_long(uint presetID, uint paramID, long value)

Restores a parameter to the given preset. Returns an errorcode on failure.

writeParam_double
int writeParam_double(uint presetID, uint paramID, double value)

Restores a parameter to the given preset. Returns an errorcode on failure.

writeParam_string
int writeParam_string(uint presetID, uint paramID, string value)

Restores a parameter to the given preset. Returns an errorcode on failure.

getParameters
MValue[] getParameters()

Returns all the possible parameters this module has.

readParam_int
int readParam_int(uint presetID, uint paramID)

Reads the given value (int).

readParam_long
long readParam_long(uint presetID, uint paramID)

Reads the given value (int).

readParam_double
double readParam_double(uint presetID, uint paramID)

Reads the given value (int).

readParam_string
string readParam_string(uint presetID, uint paramID)

Reads the given value (int).

Meta