uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
|
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"
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 wave * | tap_tempo_wave = NULL |
Points to the waveform whose speed can be tapped in. More... | |
Waveform function generator.
|
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.
wave | the wave |
|
static |
Derives a rising ramp from the step counter.
wave | the wave |
|
static |
Computes a random wave.
Note that this uses static variables, so only one random wave can be computed!
wave | the wave |
|
static |
Computes a saw down wave.
wave | the wave |
|
static |
Computes a saw up wave.
wave | the wave |
|
static |
Computes a sine wave through a lookup table.
wave | the wave |
|
static |
Computes a square wave.
wave | the wave |
|
static |
Computes a stairs wave.
wave | the wave |
|
static |
Computes a triangle wave.
wave | the wave |
void configure_tap_tempo_wave | ( | struct wave *const | wave | ) |
Configures a wave for tap tempo functionality.
wave | the wave to configure |
void init_wave | ( | struct wave * | wave, |
enum waveform | waveform, | ||
midi_value_t | speed, | ||
midi_value_t | amplitude, | ||
midi_value_t | offset | ||
) |
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.
void reset_wave | ( | struct wave *const | wave | ) |
Resets a wave.
Re-initializes all internal counters and states of the supplied wave
wave | the wave to reset |
Updates the frequency of a wave.
wave | the wave to update |
frequency | the new frequency |
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.
wave | the wave to update |
speed | the new speed in [BPM] |
Updates the waveform of a wave.
wave | the wave to update |
waveform | the new waveform |
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.
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.
wave | the wave whose output should be computed |
|
static |
This flag indicates if a tempo tap occurred.
|
static |
Points to the waveform whose speed can be tapped in.