summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/synth_engine.c89
-rw-r--r--src/synth_engine.h7
-rw-r--r--src/synth_gui.c6
3 files changed, 53 insertions, 49 deletions
diff --git a/src/synth_engine.c b/src/synth_engine.c
index 8587001..49c3168 100644
--- a/src/synth_engine.c
+++ b/src/synth_engine.c
@@ -180,6 +180,50 @@ add_to_viz(synth_t *synth, float sample)
}
}
+void
+get_frame(void *outputBuffer, synth_t *synth, int i)
+{
+ float *out = (float*)outputBuffer + 2 * i;
+ float s = 0.0f;
+
+
+ if (!synth->active) {
+ *out++ = 0.0f;
+ *out++ = 0.0f;
+
+ add_to_viz(synth, 0.0f);
+
+ synth->lfo.elapsed = 0;
+ return;
+ }
+
+ if (!notes_active(synth)) {
+ synth->active = 0;
+ *out++ = 0.0f;
+ *out++ = 0.0f;
+ add_to_viz(synth, 0.0f);
+ return;
+ }
+
+ s = make_sample(synth->n.elapsed, synth, SAMPLE_RATE, 0);
+ *out++ = s;
+ *out++ = s;
+
+ synth->lfo.elapsed++;
+ synth->adsr.elapsed++;
+ synth->n.elapsed++;
+
+ for (int i = 0; i < MIDI_NOTES; i++) {
+ if (!synth->midi_note[i].active)
+ continue;
+
+ synth->midi_note[i].elapsed++;
+ }
+
+ // viz
+ add_to_viz(synth, s);
+}
+
int
sound_gen(const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
@@ -194,43 +238,10 @@ sound_gen(const void *inputBuffer, void *outputBuffer,
(void) statusFlags;
(void) inputBuffer;
- float s = 0.0f;
+ // get_changes();
for( unsigned long i=0; i<framesPerBuffer; i++ ) {
- if (!synth->active) {
- *out++ = 0.0f;
- *out++ = 0.0f;
-
- add_to_viz(synth, 0.0f);
-
- synth->lfo.elapsed = 0;
- continue;
- }
-
- if (!notes_active(synth)) {
- synth->active = 0;
- *out++ = 0.0f;
- *out++ = 0.0f;
- add_to_viz(synth, 0.0f);
- continue;
- }
-
- s = make_sample(synth->n.elapsed, synth, SAMPLE_RATE, 0);
- *out++ = s;
- *out++ = s;
-
- synth->lfo.elapsed++;
- synth->adsr.elapsed++;
- synth->n.elapsed++;
-
- for (int i = 0; i < MIDI_NOTES; i++) {
- if (!synth->midi_note[i].active)
- continue;
-
- synth->midi_note[i].elapsed++;
- }
-
- // viz
- add_to_viz(synth, s);
+ //interpolate_changes(i);
+ get_frame(outputBuffer, synth, i);
}
return paContinue;
@@ -308,14 +319,14 @@ init_synth(synth_t * synth)
const PaDeviceInfo *deviceInfo;
for( i=0; i< Pa_GetDeviceCount(); i++ ) {
deviceInfo = Pa_GetDeviceInfo( i );
- if (!strcmp("HyperX Cloud II Wireless: USB Audio (hw:2,0)", deviceInfo->name)) break;
+ //if (!strcmp("HyperX Cloud II Wireless: USB Audio (hw:2,0)", deviceInfo->name)) break;
printf("dev: %s || %f\n", deviceInfo->name, deviceInfo->defaultSampleRate);
- //if (!strcmp("HDA Intel PCH: ALC1220 Analog (hw:0,0)", deviceInfo->name)) break;
+ if (!strcmp("HDA Intel PCH: ALC1220 Analog (hw:0,0)", deviceInfo->name)) break;
}
PaStreamParameters outputParameters;
- outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
+ outputParameters.device = i; Pa_GetDefaultOutputDevice(); /* default output device */
printf("-------\nSelected device: %s\n-------\n", Pa_GetDeviceInfo(outputParameters.device)->name);
outputParameters.channelCount = 2; /* stereo output */
outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
diff --git a/src/synth_engine.h b/src/synth_engine.h
index a434b53..55dc04e 100644
--- a/src/synth_engine.h
+++ b/src/synth_engine.h
@@ -91,14 +91,7 @@ typedef struct {
viz_t viz;
} synth_t;
-float make_sample(unsigned long long phase, void *synthData, unsigned int sample_rate, int viz);
void init_synth(synth_t * synth);
void free_synth(synth_t * synth);
-int sound_gen(const void *inputBuffer,
- void *outputBuffer,
- unsigned long framesPerBuffer,
- const PaStreamCallbackTimeInfo* timeInfo,
- PaStreamCallbackFlags statusFlags,
- void *synthData);
#endif /* SYNTH_ENGINE_H */
diff --git a/src/synth_gui.c b/src/synth_gui.c
index df219ba..4f9f5a3 100644
--- a/src/synth_gui.c
+++ b/src/synth_gui.c
@@ -101,21 +101,21 @@ draw_signals(synth_t * synth, int x, int y, int width, int height)
DrawCircle(i , y + height / 2 + floor(250 * synth->viz.wave[i - x]), point_radius, MAGENTA);
}
+ float adsr_duration = synth->adsr.a + synth->adsr.d + (synth->adsr.a + synth->adsr.d + synth->adsr.r) / 3.0 + synth->adsr.r;
for (int i = x; i < WIDTH - x; i++) {
for (int j = 0; j < MIDI_NOTES; j++) {
if (!synth->midi_note[j].active)
continue;
- DrawCircle(i , y + height - 1 + 4.5*floor((WIDTH / 24) * - adsr_amplitude(&synth->adsr, synth->midi_note[j].noteOn, synth->midi_note[j].noteOff, synth->midi_note[j].elapsed)), point_radius, GREEN);
+ DrawCircle(i , y + height - 1 + 4.5*floor((WIDTH / 24) * - adsr_amplitude(&synth->adsr, synth->midi_note[j].noteOn, synth->midi_note[j].noteOff, (i - x) * (adsr_duration * SAMPLE_RATE) / WIDTH)), point_radius, BLUE);
}
}
- float adsr_duration = synth->adsr.a + synth->adsr.d + (synth->adsr.a + synth->adsr.d + synth->adsr.r) / 3.0 + synth->adsr.r;
for (int i = x; i < WIDTH - x; i++) {
for (int j = 0; j < MIDI_NOTES; j++) {
if (!synth->midi_note[j].active)
continue;
- DrawCircle(i , y + height - 1 + 4.5*floor((WIDTH / 24) * - adsr_amplitude(&synth->adsr, synth->midi_note[j].noteOn, synth->midi_note[j].noteOff, (i - x) * (adsr_duration * SAMPLE_RATE) / WIDTH)), point_radius, BLUE);
+ DrawCircle(i , y + height - 1 + 4.5*floor((WIDTH / 24) * - adsr_amplitude(&synth->adsr, synth->midi_note[j].noteOn, synth->midi_note[j].noteOff, synth->midi_note[j].elapsed)), point_radius, GREEN);
}
}
}