uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
wave.h
Go to the documentation of this file.
1 
4 /*
5  * Copyright 2012-2015 Sebastian Neuser
6  *
7  * This file is part of the uMIDI firmware.
8  *
9  * The uMIDI firmware is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * The uMIDI firmware is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with the uMIDI firmware. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef _WAVE_H
24 #define _WAVE_H
25 
26 
27 //---------------- includes ----------------//
28 #include <stdint.h>
29 
30 #include "math.h"
31 #include "midi.h"
32 
33 
34 //---------------- code macros ----------------//
35 
38 #define RANDOM_WAVE_STEP_SIZE 4
39 
41 #define STAIR_WAVE_STEPS 5
42 
44 #define WAVE_STEPS 100
45 
48 #define TAP_TEMPO_BUFFER_SIZE 3
49 
52 #define TAP_TEMPO_TASK_FREQUENCY F_TASK_SLOW
53 
54 
55 //---------------- data types ----------------//
56 
59 {
62 };
63 
66 {
75 };
76 
81 {
86 };
87 
90 struct wave_state
91 {
92  uint16_t speed_prescaler;
93  uint16_t speed_counter;
94  uint8_t step_counter;
95  enum direction step_direction;
96 };
97 
101 struct wave
102 {
103  struct wave_settings settings;
104  struct wave_state state;
105 };
106 
107 
108 //---------------- functions and procedures ----------------//
109 
114 void configure_tap_tempo_wave(struct wave * const wave);
115 
129 void init_wave(struct wave* wave, enum waveform waveform, midi_value_t speed,
131 
136 void register_tap(void);
137 
142 void reset_wave(struct wave * const wave);
143 
150 void set_frequency(struct wave* wave, fixed_t frequency);
151 
159 void set_speed(struct wave* wave, midi_value_t speed);
160 
166 void set_waveform(struct wave* wave, enum waveform waveform);
167 
174 void tap_tempo_task(void);
175 
183 
184 
185 //---------------- EOF ----------------//
186 #endif // _WAVE_H
Square wave.
Definition: wave.h:72
API for a small collection of mathematical functions.
uint8_t step_counter
Current step counter value.
Definition: wave.h:94
void set_speed(struct wave *wave, midi_value_t speed)
Updates the speed of a wave.
Definition: wave.c:239
uint8_t midi_value_t
Type for valid MIDI values [0..127].
Definition: midi.h:56
The settings and internal state of a wave.
Definition: wave.h:101
Triangle wave.
Definition: wave.h:69
direction
Step counter direction.
Definition: wave.h:58
Random wave.
Definition: wave.h:74
enum waveform waveform
Waveform.
Definition: wave.h:82
Internal state of a wave.
Definition: wave.h:90
uint16_t speed_counter
Current speed counter value.
Definition: wave.h:93
void register_tap(void)
Registers a tempo tap event.
Definition: wave.c:220
midi_value_t offset
Static offset [0, 127].
Definition: wave.h:85
MIDI message transceiver.
void set_waveform(struct wave *wave, enum waveform waveform)
Updates the waveform of a wave.
Definition: wave.c:250
midi_value_t amplitude
Amplitude [0, 127].
Definition: wave.h:84
void set_frequency(struct wave *wave, fixed_t frequency)
Updates the frequency of a wave.
Definition: wave.c:232
The counter is counting down.
Definition: wave.h:60
Wave configuration.
Definition: wave.h:80
No waveform.
Definition: wave.h:67
Sine wave.
Definition: wave.h:68
Saw down wave.
Definition: wave.h:71
void tap_tempo_task(void)
Background task for the tap tempo function.
Definition: wave.c:258
Saw up wave.
Definition: wave.h:70
fixed_t frequency
Speed of the wave in [Hz].
Definition: wave.h:83
The counter is counting up.
Definition: wave.h:61
waveform
Enumeration of available waveforms.
Definition: wave.h:65
void init_wave(struct wave *wave, enum waveform waveform, midi_value_t speed, midi_value_t amplitude, midi_value_t offset)
Initializes a wave.
Definition: wave.c:212
void reset_wave(struct wave *const wave)
Resets a wave.
Definition: wave.c:225
midi_value_t update_wave(struct wave *wave)
Computes the current wave output value.
Definition: wave.c:312
uint32_t fixed_t
Datatype for fixed point numbers.
Definition: math.h:40
void configure_tap_tempo_wave(struct wave *const wave)
Configures a wave for tap tempo functionality.
Definition: wave.c:207
Stair wave.
Definition: wave.h:73
uint16_t speed_prescaler
Prescaler value for the speed counter.
Definition: wave.h:92