fix: rename oscillator struct
This commit is contained in:
16
main.c
16
main.c
@@ -72,23 +72,23 @@ SynthSound note(int semitone, float beats) {
|
|||||||
float hz = get_hz_by_semitone(semitone);
|
float hz = get_hz_by_semitone(semitone);
|
||||||
float duration = beats * BEAT_DURATION;
|
float duration = beats * BEAT_DURATION;
|
||||||
|
|
||||||
OscillatorParameter first = {
|
Oscillator first = {
|
||||||
.osc = Square,
|
.osc = Square,
|
||||||
.freq = hz
|
.freq = hz
|
||||||
};
|
};
|
||||||
|
|
||||||
OscillatorParameter second = {
|
Oscillator second = {
|
||||||
.osc = Saw,
|
.osc = Saw,
|
||||||
.freq = hz + 0.5
|
.freq = hz + 0.5
|
||||||
};
|
};
|
||||||
|
|
||||||
OscillatorParameter third = {
|
Oscillator third = {
|
||||||
.osc = Saw,
|
.osc = Saw,
|
||||||
.freq = hz - 1.f
|
.freq = hz - 1.f
|
||||||
};
|
};
|
||||||
|
|
||||||
OscillatorParameter oscArray[] = { first/*, second, third */};
|
Oscillator oscArray[] = { first/*, second, third */};
|
||||||
OscillatorParameterList parameters = {
|
OscillatorArray parameters = {
|
||||||
.array = oscArray,
|
.array = oscArray,
|
||||||
.count = 1
|
.count = 1
|
||||||
};
|
};
|
||||||
@@ -137,6 +137,12 @@ size_t detect_note_pressed(Note* note) {
|
|||||||
return is_pressed;
|
return is_pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct Synth {
|
||||||
|
OscillatorArray oscillators;
|
||||||
|
Note current_note;
|
||||||
|
SynthSound out_signal;
|
||||||
|
} Synth;
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Main
|
// Main
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ static float sawosc(float hz, float x) {
|
|||||||
float multiosc(OscillatorGenerationParameter param) {
|
float multiosc(OscillatorGenerationParameter param) {
|
||||||
float osc_sample = 0.f;
|
float osc_sample = 0.f;
|
||||||
for (size_t i = 0; i < param.oscillators.count; i++) {
|
for (size_t i = 0; i < param.oscillators.count; i++) {
|
||||||
OscillatorParameter osc = param.oscillators.array[i];
|
Oscillator osc = param.oscillators.array[i];
|
||||||
switch (osc.osc) {
|
switch (osc.osc) {
|
||||||
case Sine:
|
case Sine:
|
||||||
osc_sample += sineosc(osc.freq, param.sample);
|
osc_sample += sineosc(osc.freq, param.sample);
|
||||||
@@ -66,7 +66,7 @@ float multiosc(OscillatorGenerationParameter param) {
|
|||||||
return osc_sample;
|
return osc_sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
SynthSound freq(float duration, OscillatorParameterList osc) {
|
SynthSound freq(float duration, OscillatorArray osc) {
|
||||||
SynthSound samples = get_init_samples(duration);
|
SynthSound samples = get_init_samples(duration);
|
||||||
// SynthSound attack = get_attack_samples();
|
// SynthSound attack = get_attack_samples();
|
||||||
|
|
||||||
|
|||||||
14
oscillator.h
14
oscillator.h
@@ -10,23 +10,23 @@ typedef enum {
|
|||||||
Square
|
Square
|
||||||
} OscillatorType;
|
} OscillatorType;
|
||||||
|
|
||||||
typedef struct OscillatorParameter {
|
typedef struct Oscillator {
|
||||||
OscillatorType osc;
|
OscillatorType osc;
|
||||||
float freq;
|
float freq;
|
||||||
} OscillatorParameter;
|
} Oscillator;
|
||||||
|
|
||||||
typedef struct OscillatorParameterList {
|
typedef struct OscillatorArray {
|
||||||
OscillatorParameter* array;
|
Oscillator* array;
|
||||||
size_t count;
|
size_t count;
|
||||||
} OscillatorParameterList;
|
} OscillatorArray;
|
||||||
|
|
||||||
typedef struct OscillatorGenerationParameter {
|
typedef struct OscillatorGenerationParameter {
|
||||||
OscillatorParameterList oscillators;
|
OscillatorArray oscillators;
|
||||||
float sample;
|
float sample;
|
||||||
} OscillatorGenerationParameter;
|
} OscillatorGenerationParameter;
|
||||||
|
|
||||||
float multiosc(OscillatorGenerationParameter param);
|
float multiosc(OscillatorGenerationParameter param);
|
||||||
SynthSound freq(float duration, OscillatorParameterList osc);
|
SynthSound freq(float duration, OscillatorArray osc);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user