forked from sjlongland/atinysynth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
waveform.h
74 lines (66 loc) · 1.99 KB
/
waveform.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*!
* Polyphonic synthesizer for microcontrollers. Voice waveform generator.
* (C) 2017 Stuart Longland
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#ifndef _WAVEFORM_H
#define _WAVEFORM_H
#include <stdint.h>
#include "sequencer.h"
/*!
* Waveform generator state. 12 bytes.
*/
struct voice_wf_gen_t {
union {
// For square gen, 8-bit sample is enough
struct {
/*! Waveform output sample */
int8_t int_sample;
/*! Amplitude sample */
int8_t int_amplitude;
};
};
/*! Samples to next waveform period (12.4 fixed point) */
uint16_t period_remain;
/*!
* Period duration in samples (12.4 fixed point).
* (Half period for SQUARE and TRIANGLE)
*/
uint16_t period;
};
/**
* The Waveform definition. 4 bytes.
*/
struct voice_wf_def_t {
/*! Waveform amplitude (7-bit) */
int8_t amplitude;
/*! Waveform full period as `sample_freq / frequency`, or zero for pauses */
uint16_t period;
};
/* Compute frequency period of a generic wave */
uint16_t voice_wf_freq_to_period(uint16_t frequency);
/*!
* Configure the generator using waveform type and common parameters
*/
void voice_wf_set(struct seq_frame_t* const frame);
/*!
* Retrieve the next sample from the generator.
*/
int8_t voice_wf_next();
/*! Setup def */
int8_t voice_wf_setup_def(struct seq_frame_t* frame, uint16_t frequency, int8_t amplitude);
#endif