diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2023-06-27 22:37:53 +0300 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2023-06-27 22:37:53 +0300 |
commit | 60c82a72fedd719f69c1f1de896aca00784a2881 (patch) | |
tree | 3679e0886fc12aa8eeeab60260347ee7a0c5ae0e /src/sound.c | |
parent | e77d4d42cacd21bf80e4f47cba2fe85f5a5b0991 (diff) | |
download | synth-project-60c82a72fedd719f69c1f1de896aca00784a2881.tar.gz synth-project-60c82a72fedd719f69c1f1de896aca00784a2881.tar.bz2 synth-project-60c82a72fedd719f69c1f1de896aca00784a2881.zip |
Changes
Diffstat (limited to 'src/sound.c')
-rw-r--r-- | src/sound.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/sound.c b/src/sound.c new file mode 100644 index 0000000..49de899 --- /dev/null +++ b/src/sound.c @@ -0,0 +1,53 @@ +#include "sound.h" + + +static void +StreamFinished( void* synthData ) +{ + synth_t *synth = (synth_t *) synthData; +} + +void +init_sound(synth_t * synth, PaStreamCallback *streamCallback) +{ + 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: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("pulse", 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 */ + streamCallback, + synth ); + + Pa_SetStreamFinishedCallback(synth->stream, &StreamFinished); + Pa_StartStream(synth->stream); +} + +void +destroy_sound(synth_t * synth) +{ + Pa_StopStream( synth->stream ); + Pa_CloseStream( synth->stream ); + Pa_Terminate(); +} |