summaryrefslogtreecommitdiffstats
path: root/src/sound.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sound.c')
-rw-r--r--src/sound.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/src/sound.c b/src/sound.c
index 9cdb75e..2b2ca12 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -11,6 +11,7 @@ StreamFinished( void* synthData )
(void)synthData;
}
+// unused
int
get_soundcard_id(const char * name)
{
@@ -19,7 +20,7 @@ get_soundcard_id(const char * name)
const PaDeviceInfo *deviceInfo;
for( i=0; i< Pa_GetDeviceCount(); i++ ) {
deviceInfo = Pa_GetDeviceInfo(i);
- if (deviceInfo->maxOutputChannels == 0) {
+ if (deviceInfo->maxOutputChannels == 0 || deviceInfo->defaultLowInputLatency < 0) {
continue;
}
if (!strcmp(name, deviceInfo->name)) {
@@ -35,54 +36,54 @@ get_soundcard_id(const char * name)
char *
get_soundcards()
{
- Pa_Initialize();
int i;
const PaDeviceInfo *deviceInfo;
char *ret = (char *)malloc(sizeof(char) * 4096);
- strcpy(ret, "");
+ strcpy(ret, "Select Output Device;");
for( i=0; i< Pa_GetDeviceCount(); i++ ) {
deviceInfo = Pa_GetDeviceInfo(i);
- if (deviceInfo->maxOutputChannels == 0) {
+ if (deviceInfo->maxOutputChannels == 0 || deviceInfo->defaultLowInputLatency < 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)
+init_sound(synth_t * synth, PaStreamCallback *streamCallback, const char* device_name)
{
- printf("Before\n");
+ printf("Will try to initialized pulseaudion device [ %s ]\n", device_name);
Pa_Initialize();
- printf("after init\n");
- int i, c=0;
+ int i=0;
const PaDeviceInfo *deviceInfo;
for( i=0; i< Pa_GetDeviceCount(); i++ ) {
deviceInfo = Pa_GetDeviceInfo(i);
- if (deviceInfo->maxOutputChannels == 0) {
+ if (deviceInfo->maxOutputChannels == 0 ||
+ deviceInfo->defaultLowInputLatency < 0) {
continue;
}
- printf("dev: %s || %f || id:%d out:%d || lil:%f lol:%f\n", deviceInfo->name,
- deviceInfo->defaultSampleRate, deviceInfo->maxInputChannels,
- deviceInfo->maxOutputChannels, deviceInfo->defaultLowInputLatency,
- deviceInfo->defaultLowOutputLatency);
+ /* printf("dev: %s || %f || id:%d out:%d || lil:%f lol:%f\n", deviceInfo->name, */
+ /* deviceInfo->defaultSampleRate, deviceInfo->maxInputChannels, */
+ /* deviceInfo->maxOutputChannels, deviceInfo->defaultLowInputLatency, */
+ /* deviceInfo->defaultLowOutputLatency); */
- if (c == device_id) break;
- c++;
+ if (!strcmp(deviceInfo->name, device_name)) break;
}
PaStreamParameters outputParameters;
- outputParameters.device = i; Pa_GetDefaultOutputDevice(); /* default output device */
- printf("-------\nSelected device: %s\n-------\n", Pa_GetDeviceInfo(outputParameters.device)->name);
+ outputParameters.device = i;// Pa_GetDefaultOutputDevice(); /* default output device */
+ printf("-------\nSelected device: dev: %s || %f || id:%d out:%d || lil:%f lol:%f\n-------\n", deviceInfo->name,
+ deviceInfo->defaultSampleRate, deviceInfo->maxInputChannels,
+ deviceInfo->maxOutputChannels, deviceInfo->defaultLowInputLatency,
+ deviceInfo->defaultLowOutputLatency);
outputParameters.channelCount = 2; /* stereo output */
outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
- outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
+ outputParameters.suggestedLatency = deviceInfo->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;
PaError err;
@@ -96,18 +97,27 @@ init_sound(synth_t * synth, PaStreamCallback *streamCallback, const int device_i
synth );
if (err != paNoError) {
- printf("Error opening stream with %s!!!!!", Pa_GetDeviceInfo(outputParameters.device)->name);
+ printf("Error opening stream with %s!!!!!\n",
+ deviceInfo->name);
+ if (strcmp(device_name, "default")) {
+ printf("Trying to use default device\n");
+ init_sound(synth, streamCallback, "default");
+ }
+ return;
}
Pa_SetStreamFinishedCallback(synth->stream, &StreamFinished);
Pa_StartStream(synth->stream);
+ printf("<3 <3 <3 <3 Portaudio stream started <3 <3 <3 <3\n");
synth->sound_active = 1;
}
void
destroy_sound(synth_t * synth)
{
+ printf(":( :( :( stopping stream </3 </3 </3\n");
+ synth->sound_active = 0;
Pa_StopStream( synth->stream );
Pa_CloseStream( synth->stream );
Pa_Terminate();