From e77d4d42cacd21bf80e4f47cba2fe85f5a5b0991 Mon Sep 17 00:00:00 2001 From: gramanas Date: Sun, 30 Apr 2023 19:37:23 +0300 Subject: Preparations for interpolating synth --- src/synth_engine.c | 89 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 39 deletions(-) (limited to 'src/synth_engine.c') 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; iactive) { - *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 */ -- cgit v1.2.3