summaryrefslogtreecommitdiffstats
path: root/src/sound.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sound.c')
-rw-r--r--src/sound.c85
1 files changed, 70 insertions, 15 deletions
diff --git a/src/sound.c b/src/sound.c
index 57baa6b..04b3f9b 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -1,27 +1,77 @@
#include "sound.h"
+#include <portaudio.h>
static void
StreamFinished( void* synthData )
{
- synth_t *synth = (synth_t *) synthData;
+ (void)synthData;
}
-void
-init_sound(synth_t * synth, PaStreamCallback *streamCallback)
+int
+get_soundcard_id(const char * name)
{
Pa_Initialize();
+ int i, c=0;
+ const PaDeviceInfo *deviceInfo;
+ for( i=0; i< Pa_GetDeviceCount(); i++ ) {
+ deviceInfo = Pa_GetDeviceInfo(i);
+ if (deviceInfo->maxOutputChannels == 0) {
+ continue;
+ }
+ if (!strcmp(name, deviceInfo->name)) {
+ Pa_Terminate();
+ return c;
+ }
+ c++;
+ }
+ Pa_Terminate();
+ return -1;
+}
+char *
+get_soundcards()
+{
+ Pa_Initialize();
int i;
+ const PaDeviceInfo *deviceInfo;
+ char *ret = (char *)malloc(sizeof(char) * 4096);
+ strcpy(ret, "");
+ for( i=0; i< Pa_GetDeviceCount(); i++ ) {
+ deviceInfo = Pa_GetDeviceInfo(i);
+ if (deviceInfo->maxOutputChannels == 0) {
+ continue;
+ }
+ strcat(ret, deviceInfo->name);
+ strcat(ret, ";");
+ }
+ ret[strlen(ret) - 1] = '\0';
+ Pa_Terminate();
+
+ return ret;
+}
+
+void
+init_sound(synth_t * synth, PaStreamCallback *streamCallback, const int device_id)
+{
+ printf("Before\n");
+ Pa_Initialize();
+ printf("after init\n");
+
+ int i, c=0;
const PaDeviceInfo *deviceInfo;
for( i=0; i< Pa_GetDeviceCount(); i++ ) {
- deviceInfo = Pa_GetDeviceInfo( i );
+ deviceInfo = Pa_GetDeviceInfo(i);
+ if (deviceInfo->maxOutputChannels == 0) {
+ continue;
+ }
//if (!strcmp("HyperX Cloud II Wireless: USB Audio (hw:2,0)", deviceInfo->name)) break;
- printf("dev: %s || %f\n", deviceInfo->name, deviceInfo->defaultSampleRate);
+ printf("dev: %s || %f || %d channels\n", deviceInfo->name, deviceInfo->defaultSampleRate, deviceInfo->maxOutputChannels);
//if (!strcmp("HDA Intel PCH: ALC1220 Analog (hw:0,0)", deviceInfo->name)) break;
- if (!strcmp("pulse", deviceInfo->name)) break;
+ if (c == device_id) break;
+ c++;
}
-
+
PaStreamParameters outputParameters;
outputParameters.device = i; Pa_GetDefaultOutputDevice(); /* default output device */
@@ -31,15 +81,20 @@ init_sound(synth_t * synth, PaStreamCallback *streamCallback)
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;
- Pa_OpenStream(&(synth->stream),
- NULL, /* no input */
- &outputParameters,
- SAMPLE_RATE,
- FRAMES_PER_BUFFER,
- paClipOff | paDitherOff, /* we won't output out of range samples so don't bother clipping them */
- streamCallback,
- synth );
+ PaError err;
+ err = Pa_OpenStream(&(synth->stream),
+ NULL, /* no input */
+ &outputParameters,
+ SAMPLE_RATE,
+ FRAMES_PER_BUFFER,
+ paClipOff | paDitherOff, /* we won't output out of range samples so don't bother clipping them */
+ streamCallback,
+ synth );
+ if (err != paNoError) {
+ printf("Error opening stream with %s!!!!!", Pa_GetDeviceInfo(outputParameters.device)->name);
+ }
+
Pa_SetStreamFinishedCallback(synth->stream, &StreamFinished);
Pa_StartStream(synth->stream);