From aa2abb16afdceab924e627326708ee88c94df8d5 Mon Sep 17 00:00:00 2001 From: rfeldhans Date: Fri, 23 Mar 2018 16:56:49 +0100 Subject: [PATCH] adjustments to codestyle; streamlined code a bit; reading from custom alsa device now working --- demo/parameters.c | 2 +- include/odas/general/interface.h | 6 +- src/general/interface.c | 127 ++++--------------------------- src/source/src_hops.c | 16 +--- 4 files changed, 21 insertions(+), 130 deletions(-) diff --git a/demo/parameters.c b/demo/parameters.c index 6e51fdf..1ca06f9 100644 --- a/demo/parameters.c +++ b/demo/parameters.c @@ -202,7 +202,7 @@ tmpStr2 = parameters_lookup_string(fileConfig, "raw.interface.devicename"); - cfg->interface = interface_construct_soundcard_name(tmpStr2); + cfg->interface = interface_construct_soundcard_by_name(tmpStr2); } else { diff --git a/include/odas/general/interface.h b/include/odas/general/interface.h index 4f396ee..349ca1e 100644 --- a/include/odas/general/interface.h +++ b/include/odas/general/interface.h @@ -35,7 +35,6 @@ interface_socket = 3, interface_soundcard = 4, interface_terminal = 5, - interface_soundcard_name = 6, } interface_type; @@ -48,9 +47,6 @@ char * ip; unsigned int port; - unsigned int card; - unsigned int device; - char * deviceName; } interface_obj; @@ -65,7 +61,7 @@ interface_obj * interface_construct_soundcard(const unsigned int card, const unsigned int device); - interface_obj * interface_construct_soundcard_name(char * deviceName); + interface_obj * interface_construct_soundcard_by_name(char * deviceName); interface_obj * interface_construct_terminal(void); diff --git a/src/general/interface.c b/src/general/interface.c index 1fe68a0..c01a628 100644 --- a/src/general/interface.c +++ b/src/general/interface.c @@ -56,13 +56,6 @@ // +----------------------------------------------------------+ // | Soundcard | - // +----------------------------------------------------------+ - - obj->card = 0; - obj->device = 0; - - // +----------------------------------------------------------+ - // | Soundcard Name | // +----------------------------------------------------------+ obj->deviceName = (char *) NULL; @@ -110,13 +103,6 @@ // +----------------------------------------------------------+ // | Soundcard | - // +----------------------------------------------------------+ - - obj->card = 0; - obj->device = 0; - - // +----------------------------------------------------------+ - // | Soundcard Name | // +----------------------------------------------------------+ obj->deviceName = (char *) NULL; @@ -165,13 +151,6 @@ // +----------------------------------------------------------+ // | Soundcard | - // +----------------------------------------------------------+ - - obj->card = 0; - obj->device = 0; - - // +----------------------------------------------------------+ - // | Soundcard Name | // +----------------------------------------------------------+ obj->deviceName = (char *) NULL; @@ -220,13 +199,6 @@ // +----------------------------------------------------------+ // | Soundcard | - // +----------------------------------------------------------+ - - obj->card = 0; - obj->device = 0; - - // +----------------------------------------------------------+ - // | Soundcard Name | // +----------------------------------------------------------+ obj->deviceName = (char *) NULL; @@ -243,59 +215,15 @@ interface_obj * interface_construct_soundcard(const unsigned int card, const unsigned int device) { - interface_obj * obj; + char * deviceName = (char *) malloc(sizeof(char) * 1024); - obj = (interface_obj *) malloc(sizeof(interface_obj)); + sprintf(deviceName, "hw:%u,%u", card, device); - // +----------------------------------------------------------+ - // | Type | - // +----------------------------------------------------------+ - - obj->type = interface_soundcard; - - // +----------------------------------------------------------+ - // | Blackhole | - // +----------------------------------------------------------+ - - // (Empty) - - // +----------------------------------------------------------+ - // | File | - // +----------------------------------------------------------+ - - obj->fileName = (char *) NULL; - - // +----------------------------------------------------------+ - // | Socket | - // +----------------------------------------------------------+ - - obj->ip = (char *) NULL; - obj->port = 0; - - // +----------------------------------------------------------+ - // | Soundcard | - // +----------------------------------------------------------+ - - obj->card = card; - obj->device = device; - - // +----------------------------------------------------------+ - // | Soundcard Name | - // +----------------------------------------------------------+ - - sprintf(obj->deviceName, "hw:%u,%u", card, device); - - // +----------------------------------------------------------+ - // | Terminal | - // +----------------------------------------------------------+ - - // (Empty) - - return obj; + return interface_construct_soundcard_by_name(deviceName); } - interface_obj * interface_construct_soundcard_name(char * deviceName) { + interface_obj * interface_construct_soundcard_by_name(char * deviceName) { interface_obj * obj; @@ -305,7 +233,7 @@ // | Type | // +----------------------------------------------------------+ - obj->type = interface_soundcard_name; + obj->type = interface_soundcard; // +----------------------------------------------------------+ // | Blackhole | @@ -330,13 +258,6 @@ // | Soundcard | // +----------------------------------------------------------+ - obj->card = 0; - obj->device = 0; - - // +----------------------------------------------------------+ - // | Soundcard Name | - // +----------------------------------------------------------+ - obj->deviceName = deviceName; // +----------------------------------------------------------+ @@ -384,13 +305,6 @@ // | Soundcard | // +----------------------------------------------------------+ - obj->card = 0; - obj->device = 0; - - // +----------------------------------------------------------+ - // | Soundcard Name | - // +----------------------------------------------------------+ - obj->deviceName = (char *) NULL; // +----------------------------------------------------------+ @@ -448,20 +362,9 @@ // | Soundcard | // +----------------------------------------------------------+ - if (obj->type == interface_soundcard) { - - clone->card = obj->card; - clone->device = obj->device; - - } - - // +----------------------------------------------------------+ - // | Soundcard Name | - // +----------------------------------------------------------+ - - if (obj->type == interface_soundcard) { - clone->deviceName = obj->deviceName; - } + if (obj->type == interface_soundcard) { + clone->deviceName = obj->deviceName; + } // +----------------------------------------------------------+ // | Terminal | @@ -481,6 +384,14 @@ } + /* Will propably be freed somewhere else. Which is a bit ugly. + if (obj->deviceName != NULL) { + + free((void *) obj->deviceName); + + } + */ + if (obj->ip != NULL) { free((void *) obj->ip); @@ -517,12 +428,6 @@ case interface_soundcard: - printf("type = soundcard, card = %u, device = %u\n",obj->card,obj->device); - - break; - - case interface_soundcard_name: - printf("type = soundcard_name, devicename = %s\n",obj->deviceName); break; diff --git a/src/source/src_hops.c b/src/source/src_hops.c index 74cc695..8c2081f 100644 --- a/src/source/src_hops.c +++ b/src/source/src_hops.c @@ -48,11 +48,7 @@ ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int08)) || ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int16)) || ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int24)) || - ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int32)) || - ((obj->interface->type == interface_soundcard_name) && (obj->format->type == format_binary_int08)) || - ((obj->interface->type == interface_soundcard_name) && (obj->format->type == format_binary_int16)) || - ((obj->interface->type == interface_soundcard_name) && (obj->format->type == format_binary_int24)) || - ((obj->interface->type == interface_soundcard_name) && (obj->format->type == format_binary_int32)))) { + ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int32)))) { printf("Source hops: Invalid interface and/or format.\n"); exit(EXIT_FAILURE); @@ -142,7 +138,6 @@ snd_pcm_hw_params_t * hw_params; snd_pcm_format_t format; int err; - char * tmpStr; switch (obj->format->type) { @@ -179,17 +174,12 @@ } - tmpStr = (char *) malloc(sizeof(char) * 1024); - tmpStr = obj->interface->deviceName; - //sprintf(tmpStr, "hw:%u,%u", obj->interface->card, obj->interface->device); - if ((err = snd_pcm_open(&(obj->ch), tmpStr, SND_PCM_STREAM_CAPTURE, 0)) < 0) { - printf("Source hops: Cannot open audio device %s: %s\n",tmpStr, snd_strerror(err)); + if ((err = snd_pcm_open(&(obj->ch), obj->interface->deviceName, SND_PCM_STREAM_CAPTURE, 0)) < 0) { + printf("Source hops: Cannot open audio device %s: %s\n",obj->interface->deviceName, snd_strerror(err)); exit(EXIT_FAILURE); } - free((void *) tmpStr); - if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0) { printf("Source hops: Cannot allocate hardware parameter structure: %s\n", snd_strerror(err)); exit(EXIT_FAILURE); -- 2.34.1