uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
Data Structures | Macros | Enumerations | Functions
wave.h File Reference

Waveform function generator. More...

#include <stdint.h>
#include "math.h"
#include "midi.h"
Include dependency graph for wave.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  wave_settings
 Wave configuration. More...
 
struct  wave_state
 Internal state of a wave. More...
 
struct  wave
 The settings and internal state of a wave. More...
 

Macros

#define RANDOM_WAVE_STEP_SIZE   4
 Step size of the random wave. More...
 
#define STAIR_WAVE_STEPS   5
 Number of levels in the stair wave. More...
 
#define WAVE_STEPS   100
 Number of different output levels of waves. More...
 
#define TAP_TEMPO_BUFFER_SIZE   3
 Tap tempo buffer size. More...
 
#define TAP_TEMPO_TASK_FREQUENCY   F_TASK_SLOW
 Tap tempo background task frequency. More...
 

Enumerations

enum  direction { DIRECTION_DOWN, DIRECTION_UP }
 Step counter direction. More...
 
enum  waveform {
  WAVE_OFF, WAVE_SINE, WAVE_TRIANGLE, WAVE_SAW_UP,
  WAVE_SAW_DOWN, WAVE_SQUARE, WAVE_STAIRS, WAVE_RANDOM
}
 Enumeration of available waveforms. More...
 

Functions

void configure_tap_tempo_wave (struct wave *const wave)
 Configures a wave for tap tempo functionality. More...
 
void init_wave (struct wave *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 *wave, fixed_t frequency)
 Updates the frequency of a wave. More...
 
void set_speed (struct wave *wave, midi_value_t speed)
 Updates the speed of a wave. More...
 
void set_waveform (struct wave *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 *wave)
 Computes the current wave output value. More...
 

Detailed Description

Waveform function generator.

Macro Definition Documentation

◆ RANDOM_WAVE_STEP_SIZE

#define RANDOM_WAVE_STEP_SIZE   4

Step size of the random wave.

The output will change in a random direction by this amount

◆ STAIR_WAVE_STEPS

#define STAIR_WAVE_STEPS   5

Number of levels in the stair wave.

◆ TAP_TEMPO_BUFFER_SIZE

#define TAP_TEMPO_BUFFER_SIZE   3

Tap tempo buffer size.

The tempo is computed as an average over this many tapped tempo values.

◆ TAP_TEMPO_TASK_FREQUENCY

#define TAP_TEMPO_TASK_FREQUENCY   F_TASK_SLOW

Tap tempo background task frequency.

See also
F_TASK_SLOW

◆ WAVE_STEPS

#define WAVE_STEPS   100

Number of different output levels of waves.

Enumeration Type Documentation

◆ direction

enum direction

Step counter direction.

Enumerator
DIRECTION_DOWN 

The counter is counting down.

DIRECTION_UP 

The counter is counting up.

◆ waveform

enum waveform

Enumeration of available waveforms.

Enumerator
WAVE_OFF 

No waveform.

WAVE_SINE 

Sine wave.

WAVE_TRIANGLE 

Triangle wave.

WAVE_SAW_UP 

Saw up wave.

WAVE_SAW_DOWN 

Saw down wave.

WAVE_SQUARE 

Square wave.

WAVE_STAIRS 

Stair wave.

WAVE_RANDOM 

Random wave.

Function Documentation

◆ 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