uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
Functions | Variables
wave.c File Reference

Waveform function generator. More...

#include <stdlib.h>
#include <avr/pgmspace.h>
#include "background_tasks.h"
#include "leds.h"
#include "lookup_tables.h"
#include "midi.h"
#include "program.h"
#include "wave.h"
Include dependency graph for wave.c:

Functions

static void advance_step_counter (struct wave *wave)
 Increments or decrements the step counter depending on its the current direction. More...
 
static midi_value_t compute_ramp (struct wave *wave)
 Derives a rising ramp from the step counter. More...
 
static midi_value_t compute_random_wave (struct wave *wave)
 Computes a random wave. More...
 
static midi_value_t compute_saw_down_wave (struct wave *wave)
 Computes a saw down wave. More...
 
static midi_value_t compute_saw_up_wave (struct wave *wave)
 Computes a saw up wave. More...
 
static midi_value_t compute_sine_wave (struct wave *wave)
 Computes a sine wave through a lookup table. More...
 
static midi_value_t compute_square_wave (struct wave *wave)
 Computes a square wave. More...
 
static midi_value_t compute_stairs_wave (struct wave *wave)
 Computes a stairs wave. More...
 
static midi_value_t compute_triangle_wave (struct wave *wave)
 Computes a triangle wave. More...
 
void configure_tap_tempo_wave (struct wave *const wave)
 Configures a wave for tap tempo functionality. More...
 
void init_wave (struct wave *const wave, enum waveform waveform, midi_value_t speed, midi_value_t amplitude, midi_value_t offset)
 Initializes a wave. More...
 
void register_tap (void)
 Registers a tempo tap event. More...
 
void reset_wave (struct wave *const wave)
 Resets a wave. More...
 
void set_frequency (struct wave *const wave, fixed_t frequency)
 Updates the frequency of a wave. More...
 
void set_speed (struct wave *const wave, midi_value_t speed)
 Updates the speed of a wave. More...
 
void set_waveform (struct wave *const wave, enum waveform waveform)
 Updates the waveform of a wave. More...
 
void tap_tempo_task (void)
 Background task for the tap tempo function. More...
 
midi_value_t update_wave (struct wave *const wave)
 Computes the current wave output value. More...
 

Variables

static bool tap_arrived = false
 This flag indicates if a tempo tap occurred. More...
 
static struct wavetap_tempo_wave = NULL
 Points to the waveform whose speed can be tapped in. More...
 

Detailed Description

Waveform function generator.

Function Documentation

◆ advance_step_counter()

static void advance_step_counter ( struct wave wave)
static

Increments or decrements the step counter depending on its the current direction.

When the top or bottom value is reached, the direction is switched automatically. The step counter consequently follows a triangle wave.

Parameters
wavethe wave

◆ compute_ramp()

static midi_value_t compute_ramp ( struct wave wave)
static

Derives a rising ramp from the step counter.

Parameters
wavethe wave
Returns
the wave output

◆ compute_random_wave()

static midi_value_t compute_random_wave ( struct wave wave)
static

Computes a random wave.

Note that this uses static variables, so only one random wave can be computed!

Parameters
wavethe wave
Returns
the wave output

◆ compute_saw_down_wave()

static midi_value_t compute_saw_down_wave ( struct wave wave)
static

Computes a saw down wave.

Parameters
wavethe wave
Returns
the wave output

◆ compute_saw_up_wave()

static midi_value_t compute_saw_up_wave ( struct wave wave)
static

Computes a saw up wave.

Parameters
wavethe wave
Returns
the wave output

◆ compute_sine_wave()

static midi_value_t compute_sine_wave ( struct wave wave)
static

Computes a sine wave through a lookup table.

Parameters
wavethe wave
Returns
the wave output

◆ compute_square_wave()

static midi_value_t compute_square_wave ( struct wave wave)
static

Computes a square wave.

Parameters
wavethe wave
Returns
the wave output

◆ compute_stairs_wave()

static midi_value_t compute_stairs_wave ( struct wave wave)
static

Computes a stairs wave.

Parameters
wavethe wave
Returns
the wave output

◆ compute_triangle_wave()

static midi_value_t compute_triangle_wave ( struct wave wave)
static

Computes a triangle wave.

Parameters
wavethe wave
Returns
the wave output

◆ configure_tap_tempo_wave()

void configure_tap_tempo_wave ( struct wave *const  wave)

Configures a wave for tap tempo functionality.

Parameters
wavethe wave to configure
See also
tap_tempo_task

◆ init_wave()

void init_wave ( struct wave wave,
enum waveform  waveform,
midi_value_t  speed,
midi_value_t  amplitude,
midi_value_t  offset 
)

Initializes a wave.

Parameters
wavethe wave to initialize
waveformthe initial waveform
speedthe initial speed
amplitudethe amplitude
offsetthe static offset
See also
wave
waveform

◆ register_tap()

void register_tap ( void  )

Registers a tempo tap event.

This function must be called whenever a tempo tap event occurrs. It sets an internal flag to inform the background task about the event.

See also
tap_tempo_task

◆ reset_wave()

void reset_wave ( struct wave *const  wave)

Resets a wave.

Re-initializes all internal counters and states of the supplied wave

Parameters
wavethe wave to reset

◆ set_frequency()

void set_frequency ( struct wave wave,
fixed_t  frequency 
)

Updates the frequency of a wave.

Parameters
wavethe wave to update
frequencythe new frequency
See also
wave

◆ set_speed()

void set_speed ( struct wave wave,
midi_value_t  speed 
)

Updates the speed of a wave.

Sets the wave frequency to the given speed in [BPM], adding an offset of 15 BPM.

Parameters
wavethe wave to update
speedthe new speed in [BPM]
See also
wave

◆ set_waveform()

void set_waveform ( struct wave wave,
enum waveform  waveform 
)

Updates the waveform of a wave.

Parameters
wavethe wave to update
waveformthe new waveform

◆ tap_tempo_task()

void tap_tempo_task ( void  )

Background task for the tap tempo function.

This function must be registered as a slow background task. It computes a frequency from an incrementing internal counter and the task frequency and updates the speed of the wave configured for tap tempo operation.

See also
configure_tap_tempo_wave
register_tap

◆ update_wave()

midi_value_t update_wave ( struct wave wave)

Computes the current wave output value.

This function must be called in a fast background task. Over time the output value follows the configured waveform.

Parameters
wavethe wave whose output should be computed
Returns
the current output value

Variable Documentation

◆ tap_arrived

bool tap_arrived = false
static

This flag indicates if a tempo tap occurred.

◆ tap_tempo_wave

struct wave* tap_tempo_wave = NULL
static

Points to the waveform whose speed can be tapped in.