Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
swSynth.c File Reference

Functions

void swSynthInitOscillator (synthOscillator_t *osc, oscillatorShape_t shape, uint32_t freq, uint8_t volume)
 Initialize a software synthesizer oscillator.
 
void swSynthInitOscillatorWave (synthOscillator_t *osc, waveFunc_t waveFunc, void *waveData, uint32_t freq, uint8_t volume)
 Initialize a software synthesizer oscillator.
 
void swSynthSetShape (synthOscillator_t *osc, oscillatorShape_t shape)
 Set a software synthesizer oscillator's shape.
 
void swSynthSetWaveFunc (synthOscillator_t *osc, waveFunc_t waveFunc, void *waveFuncData)
 Set the wave function of an oscillator.
 
void swSynthSetFreq (synthOscillator_t *osc, uint32_t freq)
 Set the frequency of an oscillator.
 
void swSynthSetFreqPrecise (synthOscillator_t *osc, uq16_16 freq)
 Set the frequency of an oscillator with 16 bits of decimal precision.
 
void swSynthSetVolume (synthOscillator_t *osc, uint8_t volume)
 Set the volume (amplitude) of an oscillator.
 
uint8_t swSynthMixOscillators (synthOscillator_t *oscillators[], uint16_t numOscillators)
 Increment a set of oscillators by one step each, mix together the resulting samples, and return the single mixed sample.
 
int32_t swSynthSumOscillators (synthOscillator_t *oscillators[], uint16_t numOscillators)
 Increment and mix together a set of oscillators like swSynthMixOscillators(), but returns the intermediate sample sum rather than the average, to allow mixing in other sources without losing precision.
 
int8_t swSynthSampleWave (oscillatorShape_t shape, uint8_t idx)
 

Function Documentation

◆ swSynthInitOscillator()

void swSynthInitOscillator ( synthOscillator_t * osc,
oscillatorShape_t shape,
uint32_t freq,
uint8_t volume )

Initialize a software synthesizer oscillator.

Parameters
oscThe oscillator to initialize
shapeThe shape of the wave to generate
freqThe frequency of the wave to generate, in hertz
volumeThe volume (amplitude) of the wave to generate

◆ swSynthInitOscillatorWave()

void swSynthInitOscillatorWave ( synthOscillator_t * osc,
waveFunc_t waveFunc,
void * waveData,
uint32_t freq,
uint8_t volume )

Initialize a software synthesizer oscillator.

Parameters
oscThe oscillator to initialize
waveFuncThe wave function to use
waveDataCustom data to pass into the wave function
freqThe frequency of the wave to generate, in hertz
volumeThe volume (amplitude) of the wave to generate

◆ swSynthSetShape()

void swSynthSetShape ( synthOscillator_t * osc,
oscillatorShape_t shape )

Set a software synthesizer oscillator's shape.

Parameters
oscThe oscillator to set the shape for
shapeThe shape to set (sine, square, sawtooth, triangle, or noise)

◆ swSynthSetWaveFunc()

void swSynthSetWaveFunc ( synthOscillator_t * osc,
waveFunc_t waveFunc,
void * waveFuncData )

Set the wave function of an oscillator.

Parameters
oscThe oscillator to set the wave function of
waveFuncThe wave function to use
waveFuncDataData to be passed to the wave function

◆ swSynthSetFreq()

void swSynthSetFreq ( synthOscillator_t * osc,
uint32_t freq )

Set the frequency of an oscillator.

Parameters
oscThe oscillator to set the frequency for
freqThe frequency to set

◆ swSynthSetFreqPrecise()

void swSynthSetFreqPrecise ( synthOscillator_t * osc,
uq16_16 freq )

Set the frequency of an oscillator with 16 bits of decimal precision.

Parameters
oscThe oscillator to set the frequency for
freqThe frequency to set, as a fixed-point value with 16 bits of decimal precision

◆ swSynthSetVolume()

void swSynthSetVolume ( synthOscillator_t * osc,
uint8_t volume )

Set the volume (amplitude) of an oscillator.

Parameters
oscThe oscillator to set the volume for
volumeThe volume, 255 is loudest, 0 is off

◆ swSynthMixOscillators()

uint8_t swSynthMixOscillators ( synthOscillator_t * oscillators[],
uint16_t numOscillators )

Increment a set of oscillators by one step each, mix together the resulting samples, and return the single mixed sample.

Parameters
oscillatorsAn array of pointers to oscillators to step and mix together
numOscillatorsThe number of oscillators to step and mix
Returns
The mixed unsigned 8-bit output sample

◆ swSynthSumOscillators()

int32_t swSynthSumOscillators ( synthOscillator_t * oscillators[],
uint16_t numOscillators )

Increment and mix together a set of oscillators like swSynthMixOscillators(), but returns the intermediate sample sum rather than the average, to allow mixing in other sources without losing precision.

The caller must divide this value by the number of oscillators (plus the number of other sources) then add 128 to the result to convert it to an unsigned 8-bit value.

Parameters
oscillatorsAn array of oscillator pointers
numOscillatorsThe number of members in oscillators
Returns
int32_t The signed sum of all oscillator samples

◆ swSynthSampleWave()

int8_t swSynthSampleWave ( oscillatorShape_t shape,
uint8_t idx )