diff options
Diffstat (limited to 'src/synth_engine.c')
-rw-r--r-- | src/synth_engine.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/synth_engine.c b/src/synth_engine.c index 56ab771..11586da 100644 --- a/src/synth_engine.c +++ b/src/synth_engine.c @@ -2,6 +2,8 @@ #include "lowpass.h" #include "filter.h" +#include <string.h> + /* 1d convolution */ void convole(float *signal, float *filter, size_t signal_size, size_t filter_size, float *out) { @@ -230,6 +232,13 @@ sound_gen(const void *inputBuffer, void *outputBuffer, return paContinue; } + +static void +StreamFinished( void* synthData ) +{ + synth_t *synth = (synth_t *) synthData; +} + void init_synth(synth_t * synth) { @@ -273,11 +282,48 @@ init_synth(synth_t * synth) LowPass_Init(); synth->fff = create_bw_low_pass_filter(2, SAMPLE_RATE, 400); synth->fff2 = create_bw_band_stop_filter(8, SAMPLE_RATE, 15000, 22000); + + Pa_Initialize(); + + int i; + const PaDeviceInfo *deviceInfo; + for( i=0; i< Pa_GetDeviceCount(); i++ ) { + deviceInfo = Pa_GetDeviceInfo( i ); + //if (!strcmp("HyperX Cloud II Wireless: USB Audio (hw:0,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; + } + + + PaStreamParameters outputParameters; + 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 */ + outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency; + outputParameters.hostApiSpecificStreamInfo = NULL; + + Pa_OpenStream(&(synth->stream), + NULL, /* no input */ + &outputParameters, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + sound_gen, + synth ); + + Pa_SetStreamFinishedCallback(synth->stream, &StreamFinished); + Pa_StartStream(synth->stream); } void free_synth(synth_t * synth) { + Pa_StopStream( synth->stream ); + Pa_CloseStream( synth->stream ); + Pa_Terminate(); + + free_bw_low_pass(synth->fff); free_bw_band_stop(synth->fff2); } |