summaryrefslogtreecommitdiffstats
path: root/src/sound.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sound.c')
-rw-r--r--src/sound.c53
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();
+}