#ifndef __ODAS_SOURCE_HOPS
#define __ODAS_SOURCE_HOPS
- /**
- * \file src_hops.h
- * \author François Grondin <francois.grondin2@usherbrooke.ca>
- * \version 2.0
- * \date 2018-03-18
- * \copyright
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
+/**
+ * \file src_hops.h
+ * \author François Grondin <francois.grondin2@usherbrooke.ca>
+ * \version 2.0
+ * \date 2018-03-18
+ * \copyright
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <alsa/asoundlib.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <alsa/asoundlib.h>
- #include "../general/format.h"
- #include "../general/interface.h"
- #include "../message/msg_hops.h"
- #include "../signal/hop.h"
- #include "../utils/pcm.h"
+#include "../general/format.h"
+#include "../general/interface.h"
+#include "../message/msg_hops.h"
+#include "../signal/hop.h"
+#include "../utils/pcm.h"
- typedef struct src_hops_obj {
+typedef struct src_hops_obj
+{
- unsigned long long timeStamp;
+ unsigned long long timeStamp;
- unsigned int hopSize;
- unsigned int nChannels;
- unsigned int fS;
+ unsigned int hopSize;
+ unsigned int nChannels;
+ unsigned int fS;
- format_obj * format;
- interface_obj * interface;
+ format_obj *format;
+ interface_obj *interface;
- FILE * fp;
- snd_pcm_t * ch;
+ FILE *fp;
+ snd_pcm_t *ch;
+ struct sockaddr_in sserver;
+ int sid;
- char * buffer;
- unsigned int bufferSize;
+ char *buffer;
+ unsigned int bufferSize;
- char bytes[4];
+ char bytes[4];
- msg_hops_obj * out;
+ msg_hops_obj *out;
- } src_hops_obj;
+} src_hops_obj;
- typedef struct src_hops_cfg {
+typedef struct src_hops_cfg
+{
- format_obj * format;
- interface_obj * interface;
+ format_obj *format;
+ interface_obj *interface;
- } src_hops_cfg;
+} src_hops_cfg;
- src_hops_obj * src_hops_construct(const src_hops_cfg * src_hops_config, const msg_hops_cfg * msg_hops_config);
+src_hops_obj *src_hops_construct(const src_hops_cfg *src_hops_config, const msg_hops_cfg *msg_hops_config);
- void src_hops_destroy(src_hops_obj * obj);
+void src_hops_destroy(src_hops_obj *obj);
- void src_hops_connect(src_hops_obj * obj, msg_hops_obj * out);
+void src_hops_connect(src_hops_obj *obj, msg_hops_obj *out);
- void src_hops_disconnect(src_hops_obj * obj);
+void src_hops_disconnect(src_hops_obj *obj);
- void src_hops_open(src_hops_obj * obj);
+void src_hops_open(src_hops_obj *obj);
- void src_hops_open_interface_file(src_hops_obj * obj);
+void src_hops_open_interface_file(src_hops_obj *obj);
- void src_hops_open_interface_soundcard(src_hops_obj * obj);
+void src_hops_open_interface_soundcard(src_hops_obj *obj);
- void src_hops_close(src_hops_obj * obj);
+void src_hops_open_interface_socket(src_hops_obj *obj);
- void src_hops_close_interface_file(src_hops_obj * obj);
+void src_hops_close(src_hops_obj *obj);
- void src_hops_close_interface_soundcard(src_hops_obj * obj);
+void src_hops_close_interface_file(src_hops_obj *obj);
- int src_hops_process(src_hops_obj * obj);
+void src_hops_close_interface_soundcard(src_hops_obj *obj);
- int src_hops_process_interface_file(src_hops_obj * obj);
+int src_hops_process(src_hops_obj *obj);
- int src_hops_process_interface_soundcard(src_hops_obj * obj);
+int src_hops_process_interface_file(src_hops_obj *obj);
- void src_hops_process_format_binary_int08(src_hops_obj * obj);
+int src_hops_process_interface_soundcard(src_hops_obj *obj);
- void src_hops_process_format_binary_int16(src_hops_obj * obj);
+int src_hops_process_interface_socket(src_hops_obj *obj);
- void src_hops_process_format_binary_int24(src_hops_obj * obj);
+void src_hops_process_format_binary_int08(src_hops_obj *obj);
- void src_hops_process_format_binary_int32(src_hops_obj * obj);
+void src_hops_process_format_binary_int16(src_hops_obj *obj);
- src_hops_cfg * src_hops_cfg_construct(void);
+void src_hops_process_format_binary_int24(src_hops_obj *obj);
- void src_hops_cfg_destroy(src_hops_cfg * src_hops_config);
+void src_hops_process_format_binary_int32(src_hops_obj *obj);
+
+src_hops_cfg *src_hops_cfg_construct(void);
+
+void src_hops_cfg_destroy(src_hops_cfg *src_hops_config);
#endif
\ No newline at end of file
-
- /**
- * \file src_hops.c
- * \author François Grondin <francois.grondin2@usherbrooke.ca>
- * \version 2.0
- * \date 2018-03-18
- * \copyright
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
- #include <source/src_hops.h>
-
- src_hops_obj * src_hops_construct(const src_hops_cfg * src_hops_config, const msg_hops_cfg * msg_hops_config) {
-
- src_hops_obj * obj;
- unsigned int nBytes;
-
- obj = (src_hops_obj *) malloc(sizeof(src_hops_obj));
-
- obj->timeStamp = 0;
-
- obj->hopSize = msg_hops_config->hopSize;
- obj->nChannels = msg_hops_config->nChannels;
- obj->fS = msg_hops_config->fS;
-
- obj->format = format_clone(src_hops_config->format);
- obj->interface = interface_clone(src_hops_config->interface);
-
- memset(obj->bytes, 0x00, 4 * sizeof(char));
-
- if (!(((obj->interface->type == interface_file) && (obj->format->type == format_binary_int08)) ||
- ((obj->interface->type == interface_file) && (obj->format->type == format_binary_int16)) ||
- ((obj->interface->type == interface_file) && (obj->format->type == format_binary_int24)) ||
- ((obj->interface->type == interface_file) && (obj->format->type == format_binary_int32)) ||
- ((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)))) {
-
- printf("Source hops: Invalid interface and/or format.\n");
- exit(EXIT_FAILURE);
- }
-
- obj->buffer = (char *) malloc(sizeof(char) * obj->hopSize * obj->nChannels * 4);
- memset(obj->buffer, 0x00, sizeof(char) * obj->hopSize * obj->nChannels * 4);
-
- switch (obj->format->type) {
-
- case format_binary_int08: obj->bufferSize = obj->hopSize * obj->nChannels * 1; break;
- case format_binary_int16: obj->bufferSize = obj->hopSize * obj->nChannels * 2; break;
- case format_binary_int24: obj->bufferSize = obj->hopSize * obj->nChannels * 3; break;
- case format_binary_int32: obj->bufferSize = obj->hopSize * obj->nChannels * 4; break;
-
- }
-
- obj->out = (msg_hops_obj *) NULL;
-
- return obj;
+/**
+ * \file src_hops.c
+ * \author François Grondin <francois.grondin2@usherbrooke.ca>
+ * \version 2.0
+ * \date 2018-03-18
+ * \copyright
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <source/src_hops.h>
+
+src_hops_obj *src_hops_construct(const src_hops_cfg *src_hops_config, const msg_hops_cfg *msg_hops_config)
+{
+
+ src_hops_obj *obj;
+ unsigned int nBytes;
+
+ obj = (src_hops_obj *)malloc(sizeof(src_hops_obj));
+
+ obj->timeStamp = 0;
+
+ obj->hopSize = msg_hops_config->hopSize;
+ obj->nChannels = msg_hops_config->nChannels;
+ obj->fS = msg_hops_config->fS;
+
+ obj->format = format_clone(src_hops_config->format);
+ obj->interface = interface_clone(src_hops_config->interface);
+
+ memset(obj->bytes, 0x00, 4 * sizeof(char));
+
+ if (!((obj->interface->type == interface_file ||
+ obj->interface->type == interface_soundcard ||
+ obj->interface->type == interface_socket) &&
+ (obj->format->type == format_binary_int08 ||
+ obj->format->type == format_binary_int16 ||
+ obj->format->type == format_binary_int24 ||
+ obj->format->type == format_binary_int32)))
+ {
+
+ printf("Source hops: Invalid interface and/or format.\n");
+ exit(EXIT_FAILURE);
+ }
+ obj->buffer = (char *)malloc(sizeof(char) * obj->hopSize * obj->nChannels * 4);
+ memset(obj->buffer, 0x00, sizeof(char) * obj->hopSize * obj->nChannels * 4);
+
+ switch (obj->format->type)
+ {
+
+ case format_binary_int08:
+ obj->bufferSize = obj->hopSize * obj->nChannels * 1;
+ break;
+ case format_binary_int16:
+ obj->bufferSize = obj->hopSize * obj->nChannels * 2;
+ break;
+ case format_binary_int24:
+ obj->bufferSize = obj->hopSize * obj->nChannels * 3;
+ break;
+ case format_binary_int32:
+ obj->bufferSize = obj->hopSize * obj->nChannels * 4;
+ break;
}
- void src_hops_destroy(src_hops_obj * obj) {
+ obj->out = (msg_hops_obj *)NULL;
- free((void *) obj->buffer);
- format_destroy(obj->format);
- interface_destroy(obj->interface);
+ return obj;
+}
- free((void *) obj);
+void src_hops_destroy(src_hops_obj *obj)
+{
- }
+ free((void *)obj->buffer);
+ format_destroy(obj->format);
+ interface_destroy(obj->interface);
- void src_hops_connect(src_hops_obj * obj, msg_hops_obj * out) {
+ free((void *)obj);
+}
- obj->out = out;
+void src_hops_connect(src_hops_obj *obj, msg_hops_obj *out)
+{
- }
+ obj->out = out;
+}
- void src_hops_disconnect(src_hops_obj * obj) {
+void src_hops_disconnect(src_hops_obj *obj)
+{
- obj->out = (msg_hops_obj *) NULL;
+ obj->out = (msg_hops_obj *)NULL;
+}
- }
+void src_hops_open(src_hops_obj *obj)
+{
- void src_hops_open(src_hops_obj * obj) {
+ switch (obj->interface->type)
+ {
- switch(obj->interface->type) {
+ case interface_file:
- case interface_file:
+ src_hops_open_interface_file(obj);
- src_hops_open_interface_file(obj);
+ break;
- break;
+ case interface_soundcard:
- case interface_soundcard:
+ src_hops_open_interface_soundcard(obj);
- src_hops_open_interface_soundcard(obj);
+ break;
- break;
+ case interface_socket:
- default:
+ src_hops_open_interface_socket(obj);
- printf("Source hops: Invalid interface type.\n");
- exit(EXIT_FAILURE);
+ break;
- break;
+ default:
- }
+ printf("Source hops: Invalid interface type.\n");
+ exit(EXIT_FAILURE);
+ break;
}
+}
- void src_hops_open_interface_file(src_hops_obj * obj) {
-
- obj->fp = fopen(obj->interface->fileName, "rb");
+void src_hops_open_interface_file(src_hops_obj *obj)
+{
- if (obj->fp == NULL) {
- printf("Cannot open file %s\n",obj->interface->fileName);
- exit(EXIT_FAILURE);
- }
+ obj->fp = fopen(obj->interface->fileName, "rb");
+ if (obj->fp == NULL)
+ {
+ printf("Cannot open file %s\n", obj->interface->fileName);
+ exit(EXIT_FAILURE);
}
+}
- void src_hops_open_interface_soundcard(src_hops_obj * obj) {
+void src_hops_open_interface_soundcard(src_hops_obj *obj)
+{
- snd_pcm_hw_params_t * hw_params;
- snd_pcm_format_t format;
- int err;
+ snd_pcm_hw_params_t *hw_params;
+ snd_pcm_format_t format;
+ int err;
- switch (obj->format->type) {
-
- case format_binary_int08:
+ switch (obj->format->type)
+ {
- format = SND_PCM_FORMAT_S8;
+ case format_binary_int08:
- break;
+ format = SND_PCM_FORMAT_S8;
- case format_binary_int16:
+ break;
- format = SND_PCM_FORMAT_S16_LE;
+ case format_binary_int16:
- break;
+ format = SND_PCM_FORMAT_S16_LE;
- case format_binary_int24:
+ break;
- format = SND_PCM_FORMAT_S24_LE;
+ case format_binary_int24:
- break;
-
- case format_binary_int32:
-
- format = SND_PCM_FORMAT_S32_LE;
-
- break;
+ format = SND_PCM_FORMAT_S24_LE;
- default:
+ break;
- printf("Source hops: Invalid format.\n");
- exit(EXIT_FAILURE);
+ case format_binary_int32:
- break;
+ format = SND_PCM_FORMAT_S32_LE;
- }
+ break;
+ default:
- 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);
- }
+ printf("Source hops: Invalid format.\n");
+ exit(EXIT_FAILURE);
- 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);
- }
+ break;
+ }
- if ((err = snd_pcm_hw_params_any(obj->ch, hw_params)) < 0) {
- printf("Source hops: Cannot initialize hardware parameter structure: %s\n", snd_strerror(err));
- exit(EXIT_FAILURE);
- }
+ 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);
+ }
- if ((err = snd_pcm_hw_params_set_access(obj->ch, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
- printf("Source hops: Cannot set access type: %s\n", snd_strerror(err));
- exit(EXIT_FAILURE);
- }
+ 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);
+ }
- if ((err = snd_pcm_hw_params_set_format(obj->ch, hw_params, format)) < 0) {
- printf("Source hops: Cannot set sample format: %s\n", snd_strerror(err));
- exit(EXIT_FAILURE);
- }
+ if ((err = snd_pcm_hw_params_any(obj->ch, hw_params)) < 0)
+ {
+ printf("Source hops: Cannot initialize hardware parameter structure: %s\n", snd_strerror(err));
+ exit(EXIT_FAILURE);
+ }
- if ((err = snd_pcm_hw_params_set_rate(obj->ch, hw_params, obj->fS, 0)) < 0) {
- printf("Source hops: Cannot set sample rate: %s\n", snd_strerror(err));
- exit(EXIT_FAILURE);
- }
+ if ((err = snd_pcm_hw_params_set_access(obj->ch, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
+ {
+ printf("Source hops: Cannot set access type: %s\n", snd_strerror(err));
+ exit(EXIT_FAILURE);
+ }
- if ((err = snd_pcm_hw_params_set_channels(obj->ch, hw_params, obj->nChannels)) < 0) {
- printf("Source hops: Cannot set channel count: %s\n", snd_strerror(err));
- exit(EXIT_FAILURE);
- }
+ if ((err = snd_pcm_hw_params_set_format(obj->ch, hw_params, format)) < 0)
+ {
+ printf("Source hops: Cannot set sample format: %s\n", snd_strerror(err));
+ exit(EXIT_FAILURE);
+ }
- if ((err = snd_pcm_hw_params(obj->ch, hw_params)) < 0) {
- printf("Source hops: Cannot set parameters: %s\n", snd_strerror(err));
- exit(EXIT_FAILURE);
- }
+ if ((err = snd_pcm_hw_params_set_rate(obj->ch, hw_params, obj->fS, 0)) < 0)
+ {
+ printf("Source hops: Cannot set sample rate: %s\n", snd_strerror(err));
+ exit(EXIT_FAILURE);
+ }
- snd_pcm_hw_params_free(hw_params);
+ if ((err = snd_pcm_hw_params_set_channels(obj->ch, hw_params, obj->nChannels)) < 0)
+ {
+ printf("Source hops: Cannot set channel count: %s\n", snd_strerror(err));
+ exit(EXIT_FAILURE);
+ }
- if ((err = snd_pcm_prepare(obj->ch)) < 0) {
- printf("Source hops: Cannot prepare audio interface for use: %s\n", snd_strerror(err));
- exit(EXIT_FAILURE);
- }
+ if ((err = snd_pcm_hw_params(obj->ch, hw_params)) < 0)
+ {
+ printf("Source hops: Cannot set parameters: %s\n", snd_strerror(err));
+ exit(EXIT_FAILURE);
+ }
+ snd_pcm_hw_params_free(hw_params);
+
+ if ((err = snd_pcm_prepare(obj->ch)) < 0)
+ {
+ printf("Source hops: Cannot prepare audio interface for use: %s\n", snd_strerror(err));
+ exit(EXIT_FAILURE);
}
+}
- void src_hops_close(src_hops_obj * obj) {
+void src_hops_open_interface_socket(src_hops_obj *obj)
+{
- switch(obj->interface->type) {
+ memset(&(obj->sserver), 0x00, sizeof(struct sockaddr_in));
- case interface_file:
+ obj->sserver.sin_family = AF_INET;
+ obj->sserver.sin_addr.s_addr = inet_addr(obj->interface->ip);
+ obj->sserver.sin_port = htons(obj->interface->port);
+ obj->sid = socket(AF_INET, SOCK_STREAM, 0);
- src_hops_close_interface_file(obj);
+ if ((connect(obj->sid, (struct sockaddr *)&(obj->sserver), sizeof(obj->sserver))) < 0)
+ {
- break;
+ printf("Source hops: Cannot connect to server\n");
+ exit(EXIT_FAILURE);
+ }
+}
- case interface_soundcard:
+void src_hops_close(src_hops_obj *obj)
+{
- src_hops_close_interface_soundcard(obj);
+ switch (obj->interface->type)
+ {
- break;
+ case interface_file:
- default:
+ src_hops_close_interface_file(obj);
- printf("Source hops: Invalid interface type.\n");
- exit(EXIT_FAILURE);
+ break;
- break;
+ case interface_soundcard:
- }
+ src_hops_close_interface_soundcard(obj);
- }
+ break;
- void src_hops_close_interface_file(src_hops_obj * obj) {
+ default:
- fclose(obj->fp);
+ printf("Source hops: Invalid interface type.\n");
+ exit(EXIT_FAILURE);
+ break;
}
+}
- void src_hops_close_interface_soundcard(src_hops_obj * obj) {
+void src_hops_close_interface_file(src_hops_obj *obj)
+{
- snd_pcm_close(obj->ch);
+ fclose(obj->fp);
+}
- }
+void src_hops_close_interface_soundcard(src_hops_obj *obj)
+{
- int src_hops_process(src_hops_obj * obj) {
+ snd_pcm_close(obj->ch);
+}
- int rtnValue;
+void src_hops_close_interface_socket(src_hops_obj *obj)
+{
+ close(obj->sid);
+}
- switch(obj->format->type) {
+int src_hops_process(src_hops_obj *obj)
+{
- case format_binary_int08:
+ int rtnValue;
- src_hops_process_format_binary_int08(obj);
+ switch (obj->format->type)
+ {
- break;
+ case format_binary_int08:
- case format_binary_int16:
+ src_hops_process_format_binary_int08(obj);
- src_hops_process_format_binary_int16(obj);
+ break;
- break;
+ case format_binary_int16:
- case format_binary_int24:
+ src_hops_process_format_binary_int16(obj);
- src_hops_process_format_binary_int24(obj);
+ break;
- break;
+ case format_binary_int24:
- case format_binary_int32:
+ src_hops_process_format_binary_int24(obj);
- src_hops_process_format_binary_int32(obj);
+ break;
- break;
+ case format_binary_int32:
- default:
+ src_hops_process_format_binary_int32(obj);
- printf("Source hops: Invalid format type.\n");
- exit(EXIT_FAILURE);
+ break;
- break;
+ default:
- }
+ printf("Source hops: Invalid format type.\n");
+ exit(EXIT_FAILURE);
- switch(obj->interface->type) {
+ break;
+ }
- case interface_file:
+ switch (obj->interface->type)
+ {
- rtnValue = src_hops_process_interface_file(obj);
+ case interface_file:
- break;
+ rtnValue = src_hops_process_interface_file(obj);
- case interface_soundcard:
+ break;
- rtnValue = src_hops_process_interface_soundcard(obj);
+ case interface_soundcard:
- break;
+ rtnValue = src_hops_process_interface_soundcard(obj);
- default:
+ break;
- printf("Source hops: Invalid interface type.\n");
- exit(EXIT_FAILURE);
+ case interface_socket:
- break;
+ rtnValue = src_hops_process_interface_socket(obj);
- }
+ break;
- obj->timeStamp++;
- obj->out->timeStamp = obj->timeStamp;
+ default:
- return rtnValue;
+ printf("Source hops: Invalid interface type.\n");
+ exit(EXIT_FAILURE);
+ break;
}
- int src_hops_process_interface_file(src_hops_obj * obj) {
+ obj->timeStamp++;
+ obj->out->timeStamp = obj->timeStamp;
- unsigned int nBytesTotal;
- int rtnValue;
+ return rtnValue;
+}
- nBytesTotal = fread(obj->buffer, sizeof(char), obj->bufferSize, obj->fp);
+int src_hops_process_interface_file(src_hops_obj *obj)
+{
- if (nBytesTotal == obj->bufferSize) {
-
- rtnValue = 0;
+ unsigned int nBytesTotal;
+ int rtnValue;
- }
- else {
+ nBytesTotal = fread(obj->buffer, sizeof(char), obj->bufferSize, obj->fp);
- rtnValue = -1;
+ if (nBytesTotal == obj->bufferSize)
+ {
- }
-
- return rtnValue;
+ rtnValue = 0;
+ }
+ else
+ {
+ rtnValue = -1;
}
- int src_hops_process_interface_soundcard(src_hops_obj * obj) {
+ return rtnValue;
+}
- unsigned int nSamples;
- int rtnValue;
- int err;
+int src_hops_process_interface_soundcard(src_hops_obj *obj)
+{
- if (err = snd_pcm_readi(obj->ch, obj->buffer, obj->hopSize) > 0) {
-
- rtnValue = 0;
+ unsigned int nSamples;
+ int rtnValue;
+ int err;
- }
- else {
+ if (err = snd_pcm_readi(obj->ch, obj->buffer, obj->hopSize) > 0)
+ {
- rtnValue = -1;
+ rtnValue = 0;
+ }
+ else
+ {
- }
+ rtnValue = -1;
+ }
+
+ return rtnValue;
+}
- return rtnValue;
+int src_hops_process_interface_socket(src_hops_obj *obj)
+{
+ unsigned int nBytesTotal;
+ int rtnValue;
+ // ssize_t recv(int sockfd, void *buf, size_t len, int flags);
+ nBytesTotal = recv(obj->sid, obj->buffer, obj->bufferSize, 0);
+
+ if (nBytesTotal == obj->bufferSize)
+ {
+ printf("Received %d bytes", nBytesTotal);
+ rtnValue = 0;
}
+ else
+ {
- void src_hops_process_format_binary_int08(src_hops_obj * obj) {
+ rtnValue = -1;
+ }
- unsigned int iSample;
- unsigned int iChannel;
- unsigned int nBytes;
- float sample;
+ return rtnValue;
+}
- nBytes = 1;
+void src_hops_process_format_binary_int08(src_hops_obj *obj)
+{
- for (iSample = 0; iSample < obj->hopSize; iSample++) {
+ unsigned int iSample;
+ unsigned int iChannel;
+ unsigned int nBytes;
+ float sample;
- for (iChannel = 0; iChannel < obj->nChannels; iChannel++) {
+ nBytes = 1;
- memcpy(&(obj->bytes[4-nBytes]),
- &(obj->buffer[(iSample * obj->nChannels + iChannel) * nBytes]),
- sizeof(char) * nBytes);
+ for (iSample = 0; iSample < obj->hopSize; iSample++)
+ {
- sample = pcm_signedXXbits2normalized(obj->bytes, nBytes);
+ for (iChannel = 0; iChannel < obj->nChannels; iChannel++)
+ {
- obj->out->hops->array[iChannel][iSample] = sample;
+ memcpy(&(obj->bytes[4 - nBytes]),
+ &(obj->buffer[(iSample * obj->nChannels + iChannel) * nBytes]),
+ sizeof(char) * nBytes);
- }
+ sample = pcm_signedXXbits2normalized(obj->bytes, nBytes);
+ obj->out->hops->array[iChannel][iSample] = sample;
}
-
}
+}
- void src_hops_process_format_binary_int16(src_hops_obj * obj) {
-
- unsigned int iSample;
- unsigned int iChannel;
- unsigned int nBytes;
- float sample;
+void src_hops_process_format_binary_int16(src_hops_obj *obj)
+{
- nBytes = 2;
+ unsigned int iSample;
+ unsigned int iChannel;
+ unsigned int nBytes;
+ float sample;
- for (iSample = 0; iSample < obj->hopSize; iSample++) {
+ nBytes = 2;
- for (iChannel = 0; iChannel < obj->nChannels; iChannel++) {
+ for (iSample = 0; iSample < obj->hopSize; iSample++)
+ {
- memcpy(&(obj->bytes[4-nBytes]),
- &(obj->buffer[(iSample * obj->nChannels + iChannel) * nBytes]),
- sizeof(char) * nBytes);
+ for (iChannel = 0; iChannel < obj->nChannels; iChannel++)
+ {
- sample = pcm_signedXXbits2normalized(obj->bytes, nBytes);
+ memcpy(&(obj->bytes[4 - nBytes]),
+ &(obj->buffer[(iSample * obj->nChannels + iChannel) * nBytes]),
+ sizeof(char) * nBytes);
- obj->out->hops->array[iChannel][iSample] = sample;
-
- }
+ sample = pcm_signedXXbits2normalized(obj->bytes, nBytes);
+ obj->out->hops->array[iChannel][iSample] = sample;
}
-
}
+}
- void src_hops_process_format_binary_int24(src_hops_obj * obj) {
-
- unsigned int iSample;
- unsigned int iChannel;
- unsigned int nBytes;
- float sample;
-
- nBytes = 3;
+void src_hops_process_format_binary_int24(src_hops_obj *obj)
+{
- for (iSample = 0; iSample < obj->hopSize; iSample++) {
+ unsigned int iSample;
+ unsigned int iChannel;
+ unsigned int nBytes;
+ float sample;
- for (iChannel = 0; iChannel < obj->nChannels; iChannel++) {
+ nBytes = 3;
- memcpy(&(obj->bytes[4-nBytes]),
- &(obj->buffer[(iSample * obj->nChannels + iChannel) * nBytes]),
- sizeof(char) * nBytes);
+ for (iSample = 0; iSample < obj->hopSize; iSample++)
+ {
- sample = pcm_signedXXbits2normalized(obj->bytes, nBytes);
+ for (iChannel = 0; iChannel < obj->nChannels; iChannel++)
+ {
- obj->out->hops->array[iChannel][iSample] = sample;
+ memcpy(&(obj->bytes[4 - nBytes]),
+ &(obj->buffer[(iSample * obj->nChannels + iChannel) * nBytes]),
+ sizeof(char) * nBytes);
- }
+ sample = pcm_signedXXbits2normalized(obj->bytes, nBytes);
+ obj->out->hops->array[iChannel][iSample] = sample;
}
-
}
+}
- void src_hops_process_format_binary_int32(src_hops_obj * obj) {
-
- unsigned int iSample;
- unsigned int iChannel;
- unsigned int nBytes;
- float sample;
+void src_hops_process_format_binary_int32(src_hops_obj *obj)
+{
- nBytes = 4;
+ unsigned int iSample;
+ unsigned int iChannel;
+ unsigned int nBytes;
+ float sample;
- for (iSample = 0; iSample < obj->hopSize; iSample++) {
+ nBytes = 4;
- for (iChannel = 0; iChannel < obj->nChannels; iChannel++) {
+ for (iSample = 0; iSample < obj->hopSize; iSample++)
+ {
- memcpy(&(obj->bytes[4-nBytes]),
- &(obj->buffer[(iSample * obj->nChannels + iChannel) * nBytes]),
- sizeof(char) * nBytes);
+ for (iChannel = 0; iChannel < obj->nChannels; iChannel++)
+ {
- sample = pcm_signedXXbits2normalized(obj->bytes, nBytes);
+ memcpy(&(obj->bytes[4 - nBytes]),
+ &(obj->buffer[(iSample * obj->nChannels + iChannel) * nBytes]),
+ sizeof(char) * nBytes);
- obj->out->hops->array[iChannel][iSample] = sample;
-
- }
+ sample = pcm_signedXXbits2normalized(obj->bytes, nBytes);
+ obj->out->hops->array[iChannel][iSample] = sample;
}
-
}
+}
- src_hops_cfg * src_hops_cfg_construct(void) {
+src_hops_cfg *src_hops_cfg_construct(void)
+{
- src_hops_cfg * cfg;
+ src_hops_cfg *cfg;
- cfg = (src_hops_cfg *) malloc(sizeof(src_hops_cfg));
+ cfg = (src_hops_cfg *)malloc(sizeof(src_hops_cfg));
- cfg->format = (format_obj *) NULL;
- cfg->interface = (interface_obj *) NULL;
+ cfg->format = (format_obj *)NULL;
+ cfg->interface = (interface_obj *)NULL;
- return cfg;
+ return cfg;
+}
- }
-
- void src_hops_cfg_destroy(src_hops_cfg * src_hops_config) {
-
- if (src_hops_config->format != NULL) {
- format_destroy(src_hops_config->format);
- }
- if (src_hops_config->interface != NULL) {
- interface_destroy(src_hops_config->interface);
- }
-
- free((void *) src_hops_config);
+void src_hops_cfg_destroy(src_hops_cfg *src_hops_config)
+{
+ if (src_hops_config->format != NULL)
+ {
+ format_destroy(src_hops_config->format);
}
+ if (src_hops_config->interface != NULL)
+ {
+ interface_destroy(src_hops_config->interface);
+ }
+
+ free((void *)src_hops_config);
+}