47 lines
1.0 KiB
C
47 lines
1.0 KiB
C
#ifndef SYNTH_H
|
|
#define SYNTH_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#define VOICE_COUNT 16
|
|
|
|
typedef enum {
|
|
WAVE_SINE,
|
|
WAVE_TRIANGLE,
|
|
WAVE_SAW,
|
|
WAVE_RAMP,
|
|
WAVE_PULSE,
|
|
WAVE_NOISE,
|
|
WAVE_COUNT // handy for the modulo wrap on waveform switching
|
|
} Waveform;
|
|
|
|
typedef struct {
|
|
float phase;
|
|
float freqHz;
|
|
float amp;
|
|
float targetAmp;
|
|
int active;
|
|
int midiNote;
|
|
} Voice;
|
|
|
|
typedef struct {
|
|
float sampleRate;
|
|
float attackSec;
|
|
float releaseSec;
|
|
float dutyCycle;
|
|
Waveform waveform;
|
|
Voice voices[VOICE_COUNT];
|
|
int lastStolenVoice;
|
|
float pitchBend; // -1.0 to +1.0, normalized from raw MIDI value
|
|
float pitchBendRange; // semitones, e.g. 2.0f
|
|
} Synth;
|
|
|
|
void synthInit(Synth *s, float sampleRate);
|
|
void synthNoteOn(Synth *s, int midiNote);
|
|
void synthNoteOff(Synth *s, int midiNote);
|
|
void synthFillBuffer(Synth *s, int16_t *out, int frames);
|
|
float waveformSample(Waveform w, float phase, float dutyCycle);
|
|
const char *waveformName(Waveform w);
|
|
|
|
#endif
|