summaryrefslogtreecommitdiffstats
path: root/src/synth_engine.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/synth_engine.c')
-rw-r--r--src/synth_engine.c89
1 files changed, 50 insertions, 39 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 */