From 60c82a72fedd719f69c1f1de896aca00784a2881 Mon Sep 17 00:00:00 2001 From: gramanas Date: Tue, 27 Jun 2023 22:37:53 +0300 Subject: Changes --- src/sound.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/sound.c (limited to 'src/sound.c') 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(); +} -- cgit v1.2.3