printf("| Author: Francois Grondin |\n");
printf("| Email: francois.grondin2@usherbrooke.ca |\n");
printf("| Website: introlab.3it.usherbrooke.ca |\n");
+ printf("| Repository: github.com/introlab/odas |\n");
printf("| Version: 1.0 |\n");
printf("+----------------------------------------------------+\n");
printf("| -c Configuration file (.cfg) |\n");
int main(int argc, char* argv[])
{
+ char verbose = 0x00;
+
int server_id;
struct sockaddr_in server_address;
int connection_id;
const unsigned int nBytes = 10240;
- while ((c = getopt(argc,argv, "p:o:")) != -1) {
+ while ((c = getopt(argc,argv, "p:o:hv")) != -1) {
switch(c) {
- case 'p':
-
- portNumber = atoi(optarg);
-
- break;
+ case 'h':
+
+ printf("+----------------------------------------------------+\n");
+ printf("| ODAS (Open embeddeD Audition System) |\n");
+ printf("+----------------------------------------------------+\n");
+ printf("| Author: Francois Grondin |\n");
+ printf("| Email: francois.grondin2@usherbrooke.ca |\n");
+ printf("| Website: introlab.3it.usherbrooke.ca |\n");
+ printf("| Repository: github.com/introlab/odas |\n");
+ printf("| Version: 1.0 |\n");
+ printf("+----------------------------------------------------+\n");
+ printf("| -h Help |\n");
+ printf("| -o Output file |\n");
+ printf("| -p Port number |\n");
+ printf("| -v Verbose |\n");
+ printf("+----------------------------------------------------+\n");
+
+ exit(EXIT_SUCCESS);
case 'o':
break;
+ case 'p':
+
+ portNumber = atoi(optarg);
+
+ break;
+
+
}
}
obj->format = format_clone(snk_categories_config->format);
obj->interface = interface_clone(snk_categories_config->interface);
- switch (obj->format->type) {
+ if (!(((obj->interface->type == interface_blackhole) && (obj->format->type == format_undefined)) ||
+ ((obj->interface->type == interface_file) && (obj->format->type == format_text_json)) ||
+ ((obj->interface->type == interface_socket) && (obj->format->type == format_text_json)) ||
+ ((obj->interface->type == interface_terminal) && (obj->format->type == format_text_json)))) {
- case format_text_json: break;
- default:
-
- printf("Invalid format.\n");
- exit(EXIT_FAILURE);
-
- break;
+ printf("Sink categories: Invalid interface and/or format.\n");
+ exit(EXIT_FAILURE);
}
+ obj->buffer = (char *) malloc(sizeof(char) * 1024);
+ memset(obj->buffer, 0x00, sizeof(char) * 1024);
+ obj->bufferSize = 0;
+
obj->in = (msg_categories_obj *) NULL;
return obj;
format_destroy(obj->format);
interface_destroy(obj->interface);
+ free((void *) obj->buffer);
+
free((void *) obj);
}
}
- int snk_categories_open(snk_categories_obj * obj) {
+ void snk_categories_open(snk_categories_obj * obj) {
switch(obj->interface->type) {
case interface_blackhole:
- // Empty
+ snk_categories_open_interface_blackhole(obj);
break;
case interface_file:
- printf("Not implemented yet.\n");
- exit(EXIT_FAILURE);
+ snk_categories_open_interface_file(obj);
break;
case interface_socket:
- printf("Not implemented yet.\n");
- exit(EXIT_FAILURE);
+ snk_categories_open_interface_socket(obj);
break;
case interface_terminal:
- // Empty
+ snk_categories_open_interface_terminal(obj);
break;
default:
- printf("Invalid interface type.\n");
+ printf("Sink categories: Invalid interface type.\n");
exit(EXIT_FAILURE);
break;
}
- int snk_categories_close(snk_categories_obj * obj) {
+ void snk_categories_open_interface_blackhole(snk_categories_obj * obj) {
+
+ // Empty
+
+ }
+
+ void snk_categories_open_interface_file(snk_categories_obj * obj) {
+
+ obj->fp = fopen(obj->interface->fileName, "wb");
+
+ }
+
+ void snk_categories_open_interface_socket(snk_categories_obj * obj) {
+
+ memset(&(obj->sserver), 0x00, sizeof(struct sockaddr_in));
+
+ 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);
+
+ if ( (connect(obj->sid, (struct sockaddr *) &(obj->sserver), sizeof(obj->sserver))) < 0 ) {
+
+ printf("Sink categories: Cannot connect to server\n");
+ exit(EXIT_FAILURE);
+
+ }
+
+ }
+
+ void snk_categories_open_interface_terminal(snk_categories_obj * obj) {
+
+ // Empty
+
+ }
+
+ void snk_categories_close(snk_categories_obj * obj) {
switch(obj->interface->type) {
case interface_blackhole:
- // Empty
+ snk_categories_close_interface_blackhole(obj);
break;
case interface_file:
- printf("Not implemented yet.\n");
- exit(EXIT_FAILURE);
+ snk_categories_close_interface_file(obj);
break;
case interface_socket:
- printf("Not implemented yet.\n");
- exit(EXIT_FAILURE);
+ snk_categories_close_interface_socket(obj);
break;
case interface_terminal:
- // Empty
+ snk_categories_close_interface_terminal(obj);
break;
default:
- printf("Invalid interface type.\n");
+ printf("Sink categories: Invalid interface type.\n");
exit(EXIT_FAILURE);
break;
}
+ void snk_categories_close_interface_blackhole(snk_categories_obj * obj) {
+
+ // Empty
+
+ }
+
+ void snk_categories_close_interface_file(snk_categories_obj * obj) {
+
+ fclose(obj->fp);
+
+ }
+
+ void snk_categories_close_interface_socket(snk_categories_obj * obj) {
+
+ close(obj->sid);
+
+ }
+
+ void snk_categories_close_interface_terminal(snk_categories_obj * obj) {
+
+ // Empty
+
+ }
+
int snk_categories_process(snk_categories_obj * obj) {
int rtnValue;
- switch(obj->interface->type) {
+ if (obj->in->timeStamp != 0) {
- case interface_blackhole:
+ switch(obj->format->type) {
- rtnValue = snk_categories_process_blackhole(obj);
+ case format_text_json:
- break;
+ snk_categories_process_format_text_json(obj);
- case interface_file:
+ break;
- rtnValue = snk_categories_process_file(obj);
+ case format_undefined:
- break;
+ snk_categories_process_format_undefined(obj);
- case interface_socket:
+ break;
- rtnValue = snk_categories_process_socket(obj);
+ default:
- break;
+ printf("Sink categories: Invalid format type.\n");
+ exit(EXIT_FAILURE);
- case interface_terminal:
+ break;
- rtnValue = snk_categories_process_terminal(obj);
+ }
- break;
+ switch(obj->interface->type) {
- default:
+ case interface_blackhole:
- printf("Invalid interface type.\n");
- exit(EXIT_FAILURE);
+ snk_categories_process_interface_blackhole(obj);
- break;
+ break;
- }
+ case interface_file:
- return rtnValue;
+ snk_categories_process_interface_file(obj);
- }
+ break;
- int snk_categories_process_blackhole(snk_categories_obj * obj) {
+ case interface_socket:
- int rtnValue;
+ snk_categories_process_interface_socket(obj);
- if (obj->in->timeStamp != 0) {
+ break;
+
+ case interface_terminal:
+
+ snk_categories_process_interface_terminal(obj);
+
+ break;
+
+ default:
+
+ printf("Sink categories: Invalid interface type.\n");
+ exit(EXIT_FAILURE);
+
+ break;
+
+ }
rtnValue = 0;
}
- int snk_categories_process_file(snk_categories_obj * obj) {
+ void snk_categories_process_interface_blackhole(snk_categories_obj * obj) {
- printf("Not implemented\n");
- exit(EXIT_FAILURE);
+ // Empty
}
- int snk_categories_process_socket(snk_categories_obj * obj) {
+ void snk_categories_process_interface_file(snk_categories_obj * obj) {
- printf("Not implemented\n");
- exit(EXIT_FAILURE);
+ fwrite(obj->buffer, sizeof(char), obj->bufferSize, obj->fp);
}
- int snk_categories_process_terminal(snk_categories_obj * obj) {
+ void snk_categories_process_interface_socket(snk_categories_obj * obj) {
- int rtnValue;
- unsigned int iChannel;
+ if (send(obj->sid, obj->buffer, obj->bufferSize, 0) < 0) {
+ printf("Sink categories: Could not send message.\n");
+ exit(EXIT_FAILURE);
+ }
- if (obj->in->timeStamp != 0) {
+ }
- switch(obj->format->type) {
+ void snk_categories_process_interface_terminal(snk_categories_obj * obj) {
- case format_text_json:
+ printf("%s",obj->buffer);
- printf("{\n");
- printf(" \"timeStamp\": %llu,\n",obj->in->timeStamp);
- printf(" \"src\": [\n");
-
- for (iChannel = 0; iChannel < obj->nChannels; iChannel++) {
+ }
- switch(obj->in->categories->array[iChannel]) {
+ void snk_categories_process_format_text_json(snk_categories_obj * obj) {
- case 0x01:
+ unsigned int iChannel;
- printf(" { \"category\": \"speech\" }");
+ obj->buffer[0] = 0x00;
- break;
+ sprintf(obj->buffer,"%s{\n",obj->buffer);
+ sprintf(obj->buffer,"%s \"timeStamp\": %llu,\n",obj->buffer,obj->in->timeStamp);
+ sprintf(obj->buffer,"%s \"src\": [\n",obj->buffer);
- case 0x02:
+ for (iChannel = 0; iChannel < obj->nChannels; iChannel++) {
- printf(" { \"category\": \"nonspeech\" }");
+ switch(obj->in->categories->array[iChannel]) {
- break;
+ case 0x01:
- default:
+ sprintf(obj->buffer,"%s { \"category\": \"speech\" }",obj->buffer);
- printf(" { \"category\": \"undefined\" }");
+ break;
- break;
+ case 0x02:
- }
+ sprintf(obj->buffer,"%s { \"category\": \"nonspeech\" }",obj->buffer);
- if (iChannel != (obj->nChannels - 1)) {
+ break;
- printf(",");
+ default:
- }
+ sprintf(obj->buffer,"%s { \"category\": \"undefined\" }",obj->buffer);
- printf("\n");
+ break;
- }
-
- printf(" ]\n");
- printf("}\n");
+ }
- rtnValue = 0;
+ if (iChannel != (obj->nChannels - 1)) {
- break;
+ sprintf(obj->buffer,"%s,",obj->buffer);
}
+ sprintf(obj->buffer,"%s\n",obj->buffer);
+
}
- else {
+
+ sprintf(obj->buffer,"%s ]\n",obj->buffer);
+ sprintf(obj->buffer,"%s}\n",obj->buffer);
- rtnValue = -1;
+ obj->bufferSize = strlen(obj->buffer);
- }
+ }
+
+ void snk_categories_process_format_undefined(snk_categories_obj * obj) {
- return rtnValue;
+ obj->buffer[0] = 0x00;
+ obj->bufferSize = 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+ #include <unistd.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <arpa/inet.h>
#include "../general/format.h"
#include "../general/interface.h"
format_obj * format;
interface_obj * interface;
+ char * buffer;
+ unsigned int bufferSize;
+
FILE * fp;
- //struct sockaddr_in sserver;
- //char * smessage;
- //int sid;
+ struct sockaddr_in sserver;
+ int sid;
msg_categories_obj * in;
void snk_categories_disconnect(snk_categories_obj * obj);
- int snk_categories_open(snk_categories_obj * obj);
+ void snk_categories_open(snk_categories_obj * obj);
+
+ void snk_categories_open_interface_blackhole(snk_categories_obj * obj);
+
+ void snk_categories_open_interface_file(snk_categories_obj * obj);
+
+ void snk_categories_open_interface_socket(snk_categories_obj * obj);
+
+ void snk_categories_open_interface_terminal(snk_categories_obj * obj);
+
+ void snk_categories_close(snk_categories_obj * obj);
- int snk_categories_close(snk_categories_obj * obj);
+ void snk_categories_close_interface_blackhole(snk_categories_obj * obj);
+
+ void snk_categories_close_interface_file(snk_categories_obj * obj);
+
+ void snk_categories_close_interface_socket(snk_categories_obj * obj);
+
+ void snk_categories_close_interface_terminal(snk_categories_obj * obj);
int snk_categories_process(snk_categories_obj * obj);
- int snk_categories_process_blackhole(snk_categories_obj * obj);
+ void snk_categories_process_interface_blackhole(snk_categories_obj * obj);
+
+ void snk_categories_process_interface_file(snk_categories_obj * obj);
+
+ void snk_categories_process_interface_socket(snk_categories_obj * obj);
- int snk_categories_process_file(snk_categories_obj * obj);
+ void snk_categories_process_interface_terminal(snk_categories_obj * obj);
- int snk_categories_process_socket(snk_categories_obj * obj);
+ void snk_categories_process_format_text_json(snk_categories_obj * obj);
- int snk_categories_process_terminal(snk_categories_obj * obj);
+ void snk_categories_process_format_undefined(snk_categories_obj * obj);
snk_categories_cfg * snk_categories_cfg_construct(void);
memset(obj->bytes, 0x00, 4 * sizeof(char));
- switch (obj->format->type) {
+ if (!(((obj->interface->type == interface_blackhole) && (obj->format->type == format_undefined)) ||
+ ((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_socket) && (obj->format->type == format_binary_int08)) ||
+ ((obj->interface->type == interface_socket) && (obj->format->type == format_binary_int16)) ||
+ ((obj->interface->type == interface_socket) && (obj->format->type == format_binary_int24)) ||
+ ((obj->interface->type == interface_socket) && (obj->format->type == format_binary_int32)))) {
- case format_binary_int08: break;
- case format_binary_int16: break;
- case format_binary_int24: break;
- case format_binary_int32: break;
- default:
-
- printf("Invalid format.\n");
- exit(EXIT_FAILURE);
-
- break;
+ printf("Sink hops: Invalid interface and/or format.\n");
+ exit(EXIT_FAILURE);
}
- obj->smessage = (char *) malloc(sizeof(char) * msg_hops_config->nChannels * msg_hops_config->hopSize * 4);
- memset(obj->smessage, 0x00, sizeof(char) * msg_hops_config->nChannels * msg_hops_config->hopSize * 4);
+ obj->buffer = (char *) malloc(sizeof(char) * msg_hops_config->nChannels * msg_hops_config->hopSize * 4);
+ memset(obj->buffer, 0x00, sizeof(char) * msg_hops_config->nChannels * msg_hops_config->hopSize * 4);
+ obj->bufferSize = 0;
obj->in = (msg_hops_obj *) NULL;
format_destroy(obj->format);
interface_destroy(obj->interface);
- free((void *) obj->smessage);
+ free((void *) obj->buffer);
free((void *) obj);
}
- int snk_hops_open(snk_hops_obj * obj) {
+ void snk_hops_open(snk_hops_obj * obj) {
switch(obj->interface->type) {
case interface_blackhole:
- // Empty
+ snk_hops_open_interface_blackhole(obj);
break;
case interface_file:
- obj->fp = fopen(obj->interface->fileName, "wb");
+ snk_hops_open_interface_file(obj);
break;
case interface_socket:
- obj->sserver.sin_family = AF_INET;
- obj->sserver.sin_port = htons(obj->interface->port);
- inet_aton(obj->interface->ip, &(obj->sserver.sin_addr));
+ snk_hops_open_interface_socket(obj);
- obj->sid = socket(AF_INET, SOCK_STREAM, 0);
+ break;
- if ( (connect(obj->sid, (struct sockaddr *) &(obj->sserver), sizeof(obj->sserver))) < 0 ) {
+ default:
- printf("Cannot connect to server\n");
- exit(EXIT_FAILURE);
+ printf("Sink hops: Invalid interface type.\n");
+ exit(EXIT_FAILURE);
- }
+ break;
- break;
+ }
- case interface_soundcard:
+ }
- printf("Not implemented yet.\n");
- exit(EXIT_FAILURE);
+ void snk_hops_open_interface_blackhole(snk_hops_obj * obj) {
- break;
+ // Empty
- default:
+ }
- printf("Invalid interface type.\n");
- exit(EXIT_FAILURE);
+ void snk_hops_open_interface_file(snk_hops_obj * obj) {
- break;
+ obj->fp = fopen(obj->interface->fileName, "wb");
- }
+ }
+
+ void snk_hops_open_interface_socket(snk_hops_obj * obj) {
+
+ memset(&(obj->sserver), 0x00, sizeof(struct sockaddr_in));
+
+ 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);
+
+ if ( (connect(obj->sid, (struct sockaddr *) &(obj->sserver), sizeof(obj->sserver))) < 0 ) {
+
+ printf("Sink hops: Cannot connect to server\n");
+ exit(EXIT_FAILURE);
+
+ }
}
- int snk_hops_close(snk_hops_obj * obj) {
+ void snk_hops_close(snk_hops_obj * obj) {
switch(obj->interface->type) {
case interface_blackhole:
- // Empty
+ snk_hops_close_interface_blackhole(obj);
break;
case interface_file:
- fclose(obj->fp);
+ snk_hops_close_interface_file(obj);
break;
case interface_socket:
- close(obj->sid);
+ snk_hops_close_interface_socket(obj);
break;
- case interface_soundcard:
+ default:
- printf("Not implemented yet.\n");
+ printf("Sink hops: Invalid interface type.\n");
exit(EXIT_FAILURE);
break;
- default:
+ }
- printf("Invalid interface type.\n");
- exit(EXIT_FAILURE);
+ }
- break;
+ void snk_hops_close_interface_blackhole(snk_hops_obj * obj) {
- }
+ // Empty
+
+ }
+
+ void snk_hops_close_interface_file(snk_hops_obj * obj) {
+
+ fclose(obj->fp);
+
+ }
+
+ void snk_hops_close_interface_socket(snk_hops_obj * obj) {
+
+ close(obj->sid);
}
int rtnValue;
- switch(obj->interface->type) {
+ if (obj->in->timeStamp != 0) {
- case interface_blackhole:
+ switch(obj->format->type) {
- rtnValue = snk_hops_process_blackhole(obj);
+ case format_binary_int08:
- break;
+ snk_hops_process_format_binary_int08(obj);
- case interface_file:
+ break;
- rtnValue = snk_hops_process_file(obj);
+ case format_binary_int16:
- break;
+ snk_hops_process_format_binary_int16(obj);
- case interface_socket:
+ break;
- rtnValue = snk_hops_process_socket(obj);
+ case format_binary_int24:
- break;
+ snk_hops_process_format_binary_int24(obj);
- case interface_soundcard:
+ break;
- rtnValue = snk_hops_process_soundcard(obj);
+ case format_binary_int32:
- break;
+ snk_hops_process_format_binary_int32(obj);
- default:
+ break;
- printf("Invalid interface type.\n");
- exit(EXIT_FAILURE);
+ default:
- break;
+ printf("Sink hops: Invalid format type.\n");
+ exit(EXIT_FAILURE);
- }
+ break;
- return rtnValue;
+ }
- }
+ switch(obj->interface->type) {
- int snk_hops_process_blackhole(snk_hops_obj * obj) {
+ case interface_blackhole:
- int rtnValue;
+ snk_hops_process_interface_blackhole(obj);
- if (obj->in->timeStamp != 0) {
+ break;
+
+ case interface_file:
+
+ snk_hops_process_interface_file(obj);
+
+ break;
+
+ case interface_socket:
+
+ snk_hops_process_interface_socket(obj);
+
+ break;
+
+ default:
+
+ printf("Sink hops: Invalid interface type.\n");
+ exit(EXIT_FAILURE);
+
+ break;
+
+ }
rtnValue = 0;
}
- int snk_hops_process_file(snk_hops_obj * obj) {
+ void snk_hops_process_interface_blackhole(snk_hops_obj * obj) {
+
+ // Emtpy
+
+ }
+
+ void snk_hops_process_interface_file(snk_hops_obj * obj) {
+
+ fwrite(obj->buffer, sizeof(char), obj->bufferSize, obj->fp);
+
+ }
+
+ void snk_hops_process_interface_socket(snk_hops_obj * obj) {
+
+ if (send(obj->sid, obj->buffer, obj->bufferSize, 0) < 0) {
+ printf("Sink hops: Could not send message.\n");
+ exit(EXIT_FAILURE);
+ }
+
+ }
+
+ void snk_hops_process_format_binary_int08(snk_hops_obj * obj) {
- unsigned int iSample;
unsigned int iChannel;
+ unsigned int iSample;
float sample;
unsigned int nBytes;
- int rtnValue;
+ unsigned int nBytesTotal;
- if (obj->in->timeStamp != 0) {
+ nBytes = 1;
+ nBytesTotal = 0;
+
+ for (iSample = 0; iSample < obj->hopSize; iSample++) {
- switch (obj->format->type) {
+ for (iChannel = 0; iChannel < obj->nChannels; iChannel++) {
- case format_binary_int08: nBytes = 1; break;
- case format_binary_int16: nBytes = 2; break;
- case format_binary_int24: nBytes = 3; break;
- case format_binary_int32: nBytes = 4; break;
+ nBytesTotal += nBytes;
+
+ sample = obj->in->hops->array[iChannel][iSample];
+ pcm_normalized2signedXXbits(sample, nBytes, obj->bytes);
+ memcpy(&(obj->buffer[nBytesTotal]), &(obj->bytes[4-nBytes]), sizeof(char) * nBytes);
}
- for (iSample = 0; iSample < obj->hopSize; iSample++) {
-
- for (iChannel = 0; iChannel < obj->nChannels; iChannel++) {
+ }
- sample = obj->in->hops->array[iChannel][iSample];
- pcm_normalized2signedXXbits(sample, nBytes, obj->bytes);
- fwrite(&(obj->bytes[4-nBytes]), sizeof(char), nBytes, obj->fp);
+ obj->bufferSize = nBytesTotal;
- }
+ }
- }
+ void snk_hops_process_format_binary_int16(snk_hops_obj * obj) {
- rtnValue = 0;
+ unsigned int iChannel;
+ unsigned int iSample;
+ float sample;
+ unsigned int nBytes;
+ unsigned int nBytesTotal;
- }
- else {
+ nBytes = 2;
+ nBytesTotal = 0;
- rtnValue = -1;
+ for (iSample = 0; iSample < obj->hopSize; iSample++) {
+
+ for (iChannel = 0; iChannel < obj->nChannels; iChannel++) {
+
+ nBytesTotal += nBytes;
+
+ sample = obj->in->hops->array[iChannel][iSample];
+ pcm_normalized2signedXXbits(sample, nBytes, obj->bytes);
+ memcpy(&(obj->buffer[nBytesTotal]), &(obj->bytes[4-nBytes]), sizeof(char) * nBytes);
+
+ }
}
- return rtnValue;
+ obj->bufferSize = nBytesTotal;
}
- int snk_hops_process_socket(snk_hops_obj * obj) {
+ void snk_hops_process_format_binary_int24(snk_hops_obj * obj) {
unsigned int iChannel;
unsigned int iSample;
float sample;
unsigned int nBytes;
unsigned int nBytesTotal;
- int rtnValue;
- if (obj->in->timeStamp != 0) {
+ nBytes = 3;
+ nBytesTotal = 0;
+
+ for (iSample = 0; iSample < obj->hopSize; iSample++) {
- switch (obj->format->type) {
+ for (iChannel = 0; iChannel < obj->nChannels; iChannel++) {
- case format_binary_int08: nBytes = 1; break;
- case format_binary_int16: nBytes = 2; break;
- case format_binary_int24: nBytes = 3; break;
- case format_binary_int32: nBytes = 4; break;
+ nBytesTotal += nBytes;
+
+ sample = obj->in->hops->array[iChannel][iSample];
+ pcm_normalized2signedXXbits(sample, nBytes, obj->bytes);
+ memcpy(&(obj->buffer[nBytesTotal]), &(obj->bytes[4-nBytes]), sizeof(char) * nBytes);
}
- nBytesTotal = 0;
+ }
- for (iSample = 0; iSample < obj->hopSize; iSample++) {
+ obj->bufferSize = nBytesTotal;
- for (iChannel = 0; iChannel < obj->nChannels; iChannel++) {
+ }
- nBytesTotal += nBytes;
+ void snk_hops_process_format_binary_int32(snk_hops_obj * obj) {
- sample = obj->in->hops->array[iChannel][iSample];
- pcm_normalized2signedXXbits(sample, nBytes, obj->bytes);
- memcpy(&(obj->smessage[nBytesTotal]), &(obj->bytes[4-nBytes]), sizeof(char) * nBytes);
+ unsigned int iChannel;
+ unsigned int iSample;
+ float sample;
+ unsigned int nBytes;
+ unsigned int nBytesTotal;
- }
+ nBytes = 4;
+ nBytesTotal = 0;
- }
+ for (iSample = 0; iSample < obj->hopSize; iSample++) {
- if (send(obj->sid, obj->smessage, nBytesTotal, 0) < 0) {
- printf("Could not send message.\n");
- exit(EXIT_FAILURE);
- }
+ for (iChannel = 0; iChannel < obj->nChannels; iChannel++) {
- rtnValue = 0;
+ nBytesTotal += nBytes;
- }
- else {
+ sample = obj->in->hops->array[iChannel][iSample];
+ pcm_normalized2signedXXbits(sample, nBytes, obj->bytes);
+ memcpy(&(obj->buffer[nBytesTotal]), &(obj->bytes[4-nBytes]), sizeof(char) * nBytes);
- rtnValue = -1;
+ }
}
- return rtnValue;
+ obj->bufferSize = nBytesTotal;
}
- int snk_hops_process_soundcard(snk_hops_obj * obj) {
+ void snk_hops_process_format_undefined(snk_hops_obj * obj) {
- printf("Not implemented\n");
- exit(EXIT_FAILURE);
+ obj->buffer[0] = 0x00;
+ obj->bufferSize = 0;
}
format_obj * format;
interface_obj * interface;
+ char * buffer;
+ unsigned int bufferSize;
+
FILE * fp;
struct sockaddr_in sserver;
- char * smessage;
int sid;
char bytes[4];
void snk_hops_disconnect(snk_hops_obj * obj);
- int snk_hops_open(snk_hops_obj * obj);
+ void snk_hops_open(snk_hops_obj * obj);
+
+ void snk_hops_open_interface_blackhole(snk_hops_obj * obj);
+
+ void snk_hops_open_interface_file(snk_hops_obj * obj);
+
+ void snk_hops_open_interface_socket(snk_hops_obj * obj);
+
+ void snk_hops_close(snk_hops_obj * obj);
+
+ void snk_hops_close_interface_blackhole(snk_hops_obj * obj);
- int snk_hops_close(snk_hops_obj * obj);
+ void snk_hops_close_interface_file(snk_hops_obj * obj);
+
+ void snk_hops_close_interface_socket(snk_hops_obj * obj);
int snk_hops_process(snk_hops_obj * obj);
- int snk_hops_process_blackhole(snk_hops_obj * obj);
+ void snk_hops_process_interface_blackhole(snk_hops_obj * obj);
+
+ void snk_hops_process_interface_file(snk_hops_obj * obj);
+
+ void snk_hops_process_interface_socket(snk_hops_obj * obj);
+
+ void snk_hops_process_format_binary_int08(snk_hops_obj * obj);
+
+ void snk_hops_process_format_binary_int16(snk_hops_obj * obj);
- int snk_hops_process_file(snk_hops_obj * obj);
+ void snk_hops_process_format_binary_int24(snk_hops_obj * obj);
- int snk_hops_process_socket(snk_hops_obj * obj);
+ void snk_hops_process_format_binary_int32(snk_hops_obj * obj);
- int snk_hops_process_soundcard(snk_hops_obj * obj);
+ void snk_hops_process_format_undefined(snk_hops_obj * obj);
snk_hops_cfg * snk_hops_cfg_construct(void);
obj->format = format_clone(snk_pots_config->format);
obj->interface = interface_clone(snk_pots_config->interface);
- switch (obj->format->type) {
+ if (!(((obj->interface->type == interface_blackhole) && (obj->format->type == format_undefined)) ||
+ ((obj->interface->type == interface_file) && (obj->format->type == format_binary_float)) ||
+ ((obj->interface->type == interface_file) && (obj->format->type == format_text_json)) ||
+ ((obj->interface->type == interface_socket) && (obj->format->type == format_text_json)))) {
- case format_text_json: break;
- case format_binary_float: break;
- default:
-
- printf("Invalid format.\n");
- exit(EXIT_FAILURE);
-
- break;
+ printf("Sink pots: Invalid interface and/or format.\n");
+ exit(EXIT_FAILURE);
}
obj->fp = (FILE *) NULL;
- obj->smessage = (char *) malloc(sizeof(char) * (1024 + 1024 * msg_pots_config->nPots));
+ obj->buffer = (char *) malloc(sizeof(char) * 1024);
+ memset(obj->buffer, 0x00, sizeof(char) * 1024);
+ obj->bufferSize = 0;
obj->in = (msg_pots_obj *) NULL;
void snk_pots_destroy(snk_pots_obj * obj) {
- free((void *) obj->smessage);
+ free((void *) obj->buffer);
format_destroy(obj->format);
interface_destroy(obj->interface);
}
- int snk_pots_open(snk_pots_obj * obj) {
+ void snk_pots_open(snk_pots_obj * obj) {
switch(obj->interface->type) {
case interface_blackhole:
- // Empty
+ snk_pots_open_interface_blackhole(obj);
break;
case interface_file:
- obj->fp = fopen(obj->interface->fileName, "wb");
+ snk_pots_open_interface_file(obj);
break;
case interface_socket:
- memset(&(obj->sclient), 0x00, sizeof(struct sockaddr_in));
-
- obj->sclient.sin_family = AF_INET;
- obj->sclient.sin_addr.s_addr = inet_addr(obj->interface->ip);
- obj->sclient.sin_port = htons(obj->interface->port);
- obj->sid = socket(AF_INET, SOCK_STREAM, 0);
-
- if ( (connect(obj->sid, (struct sockaddr *) &(obj->sclient), sizeof(obj->sclient))) < 0 ) {
-
- printf("Cannot connect to server\n");
- exit(EXIT_FAILURE);
-
- }
+ snk_pots_open_interface_socket(obj);
break;
case interface_terminal:
- // Empty
+ snk_pots_open_interface_terminal(obj);
break;
default:
- printf("Invalid interface type.\n");
+ printf("Sink pots: Invalid interface type.\n");
exit(EXIT_FAILURE);
break;
}
- int snk_pots_close(snk_pots_obj * obj) {
+ void snk_pots_open_interface_blackhole(snk_pots_obj * obj) {
- switch(obj->interface->type) {
-
- case interface_blackhole:
+ // Empty
- // Empty
-
- break;
-
- case interface_file:
+ }
- fclose(obj->fp);
+ void snk_pots_open_interface_file(snk_pots_obj * obj) {
- break;
+ obj->fp = fopen(obj->interface->fileName, "wb");
- case interface_socket:
+ }
- close(obj->sid);
+ void snk_pots_open_interface_socket(snk_pots_obj * obj) {
- break;
+ memset(&(obj->sserver), 0x00, sizeof(struct sockaddr_in));
- case interface_terminal:
+ 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);
- // Empty
+ if ( (connect(obj->sid, (struct sockaddr *) &(obj->sserver), sizeof(obj->sserver))) < 0 ) {
- break;
+ printf("Sink pots: Cannot connect to server\n");
+ exit(EXIT_FAILURE);
- default:
+ }
- printf("Invalid interface type.\n");
- exit(EXIT_FAILURE);
+ }
- break;
+ void snk_pots_open_interface_terminal(snk_pots_obj * obj) {
- }
+ // Empty
}
- int snk_pots_process(snk_pots_obj * obj) {
-
- int rtnValue;
+ void snk_pots_close(snk_pots_obj * obj) {
switch(obj->interface->type) {
case interface_blackhole:
- rtnValue = snk_pots_process_blackhole(obj);
+ snk_pots_close_interface_blackhole(obj);
break;
case interface_file:
- rtnValue = snk_pots_process_file(obj);
+ snk_pots_close_interface_file(obj);
break;
case interface_socket:
- rtnValue = snk_pots_process_socket(obj);
-
+ snk_pots_close_interface_socket(obj);
+
break;
case interface_terminal:
- rtnValue = snk_pots_process_terminal(obj);
+ snk_pots_close_interface_terminal(obj);
break;
default:
- printf("Invalid interface type.\n");
+ printf("Sink pots: Invalid interface type.\n");
exit(EXIT_FAILURE);
break;
}
- return rtnValue;
+ }
+
+ void snk_pots_close_interface_blackhole(snk_pots_obj * obj) {
+
+ // Empty
}
- int snk_pots_process_blackhole(snk_pots_obj * obj) {
+ void snk_pots_close_interface_file(snk_pots_obj * obj) {
- int rtnValue;
+ fclose(obj->fp);
- if (obj->in->timeStamp != 0) {
+ }
- rtnValue = 0;
+ void snk_pots_close_interface_socket(snk_pots_obj * obj) {
- }
- else {
+ close(obj->sid);
- rtnValue = -1;
+ }
- }
+ void snk_pots_close_interface_terminal(snk_pots_obj * obj) {
- return rtnValue;
+ // Empty
}
- int snk_pots_process_file(snk_pots_obj * obj) {
+ int snk_pots_process(snk_pots_obj * obj) {
int rtnValue;
case format_binary_float:
- fwrite(obj->in->pots->array, sizeof(float), 4 * obj->in->pots->nPots, obj->fp);
+ snk_pots_process_format_binary_float(obj);
break;
- }
-
- rtnValue = 0;
+ case format_text_json:
- }
- else {
+ snk_pots_process_format_text_json(obj);
- rtnValue = -1;
+ break;
- }
+ default:
- return rtnValue;
+ printf("Sink pots: Invalid format type.\n");
+ exit(EXIT_FAILURE);
- }
+ break;
- int snk_pots_process_socket(snk_pots_obj * obj) {
+ }
- int rtnValue;
- unsigned int iPot;
+ switch(obj->interface->type) {
- if (obj->in->timeStamp != 0) {
+ case interface_blackhole:
- switch(obj->format->type) {
+ snk_pots_process_interface_blackhole(obj);
- case format_text_json:
+ break;
- obj->smessage[0] = 0x00;
+ case interface_file:
- sprintf(obj->smessage,"%s{\n",obj->smessage);
- sprintf(obj->smessage,"%s \"timeStamp\": %llu,\n",obj->smessage,obj->in->timeStamp);
- sprintf(obj->smessage,"%s \"src\": [\n",obj->smessage);
+ snk_pots_process_interface_file(obj);
- for (iPot = 0; iPot < obj->nPots; iPot++) {
+ break;
- sprintf(obj->smessage,"%s { \"x\": %1.3f, \"y\": %1.3f, \"z\": %1.3f, \"E\": %1.3f }", obj->smessage,
- obj->in->pots->array[iPot*4+0], obj->in->pots->array[iPot*4+1], obj->in->pots->array[iPot*4+2], obj->in->pots->array[iPot*4+3]);
+ case interface_socket:
- if (iPot != (obj->nPots - 1)) {
+ snk_pots_process_interface_socket(obj);
- sprintf(obj->smessage,"%s,",obj->smessage);
+ break;
- }
+ case interface_terminal:
- sprintf(obj->smessage,"%s\n",obj->smessage);
+ snk_pots_process_interface_terminal(obj);
- }
-
- sprintf(obj->smessage,"%s ]\n",obj->smessage);
- sprintf(obj->smessage,"%s}\n",obj->smessage);
+ break;
- if (send(obj->sid, obj->smessage, strlen(obj->smessage), 0) < 0) {
- printf("Could not send message.\n");
- exit(EXIT_FAILURE);
- }
+ default:
- rtnValue = 0;
+ printf("Sink pots: Invalid interface type.\n");
+ exit(EXIT_FAILURE);
- break;
+ break;
}
+ rtnValue = 0;
+
}
else {
}
- int snk_pots_process_terminal(snk_pots_obj * obj) {
+ void snk_pots_process_interface_blackhole(snk_pots_obj * obj) {
- int rtnValue;
- unsigned int iPot;
+ // Empty
- if (obj->in->timeStamp != 0) {
+ }
- switch(obj->format->type) {
+ void snk_pots_process_interface_file(snk_pots_obj * obj) {
- case format_text_json:
+ fwrite(obj->buffer, sizeof(char), obj->bufferSize, obj->fp);
- printf("{\n");
- printf(" \"timeStamp\": %llu,\n",obj->in->timeStamp);
- printf(" \"src\": [\n");
+ }
- for (iPot = 0; iPot < obj->nPots; iPot++) {
+ void snk_pots_process_interface_socket(snk_pots_obj * obj) {
- printf(" { \"x\": %1.3f, \"y\": %1.3f, \"z\": %1.3f, \"E\": %1.3f }",
- obj->in->pots->array[iPot*4+0],
- obj->in->pots->array[iPot*4+1],
- obj->in->pots->array[iPot*4+2],
- obj->in->pots->array[iPot*4+3]);
+ if (send(obj->sid, obj->buffer, obj->bufferSize, 0) < 0) {
+ printf("Sink pots: Could not send message.\n");
+ exit(EXIT_FAILURE);
+ }
- if (iPot != (obj->nPots - 1)) {
+ }
- printf(",");
+ void snk_pots_process_interface_terminal(snk_pots_obj * obj) {
- }
+ printf("%s",obj->buffer);
- printf("\n");
+ }
- }
-
- printf(" ]\n");
- printf("}\n");
+ void snk_pots_process_format_binary_float(snk_pots_obj * obj) {
- rtnValue = 0;
+ memcpy(obj->buffer, obj->in->pots->array, sizeof(float) * 4 * obj->in->pots->nPots);
+ obj->bufferSize = sizeof(float) * 4 * obj->in->pots->nPots;
- break;
+ }
- }
+ void snk_pots_process_format_text_json(snk_pots_obj * obj) {
- }
- else {
+ unsigned int iPot;
- rtnValue = -1;
+ obj->buffer[0] = 0x00;
+
+ sprintf(obj->buffer,"%s{\n",obj->buffer);
+ sprintf(obj->buffer,"%s \"timeStamp\": %llu,\n",obj->buffer,obj->in->timeStamp);
+ sprintf(obj->buffer,"%s \"src\": [\n",obj->buffer);
+
+ for (iPot = 0; iPot < obj->nPots; iPot++) {
+
+ sprintf(obj->buffer,"%s { \"x\": %1.3f, \"y\": %1.3f, \"z\": %1.3f, \"E\": %1.3f }", obj->buffer,
+ obj->in->pots->array[iPot*4+0], obj->in->pots->array[iPot*4+1], obj->in->pots->array[iPot*4+2], obj->in->pots->array[iPot*4+3]);
+
+ if (iPot != (obj->nPots - 1)) {
+
+ sprintf(obj->buffer,"%s,",obj->buffer);
+
+ }
+
+ sprintf(obj->buffer,"%s\n",obj->buffer);
}
+
+ sprintf(obj->buffer,"%s ]\n",obj->buffer);
+ sprintf(obj->buffer,"%s}\n",obj->buffer);
- return rtnValue;
+ obj->bufferSize = strlen(obj->buffer);
}
-
snk_pots_cfg * snk_pots_cfg_construct(void) {
snk_pots_cfg * cfg;
format_obj * format;
interface_obj * interface;
+ char * buffer;
+ unsigned int bufferSize;
+
FILE * fp;
- char * smessage;
- struct sockaddr_in sclient;
+ struct sockaddr_in sserver;
int sid;
msg_pots_obj * in;
void snk_pots_disconnect(snk_pots_obj * obj);
- int snk_pots_open(snk_pots_obj * obj);
+ void snk_pots_open(snk_pots_obj * obj);
+
+ void snk_pots_open_interface_blackhole(snk_pots_obj * obj);
+
+ void snk_pots_open_interface_file(snk_pots_obj * obj);
+
+ void snk_pots_open_interface_socket(snk_pots_obj * obj);
+
+ void snk_pots_open_interface_terminal(snk_pots_obj * obj);
+
+ void snk_pots_close(snk_pots_obj * obj);
- int snk_pots_close(snk_pots_obj * obj);
+ void snk_pots_close_interface_blackhole(snk_pots_obj * obj);
+
+ void snk_pots_close_interface_file(snk_pots_obj * obj);
+
+ void snk_pots_close_interface_socket(snk_pots_obj * obj);
+
+ void snk_pots_close_interface_terminal(snk_pots_obj * obj);
int snk_pots_process(snk_pots_obj * obj);
- int snk_pots_process_blackhole(snk_pots_obj * obj);
+ void snk_pots_process_interface_blackhole(snk_pots_obj * obj);
+
+ void snk_pots_process_interface_file(snk_pots_obj * obj);
+
+ void snk_pots_process_interface_socket(snk_pots_obj * obj);
- int snk_pots_process_file(snk_pots_obj * obj);
+ void snk_pots_process_interface_terminal(snk_pots_obj * obj);
- int snk_pots_process_socket(snk_pots_obj * obj);
+ void snk_pots_process_format_binary_float(snk_pots_obj * obj);
- int snk_pots_process_terminal(snk_pots_obj * obj);
+ void snk_pots_process_format_text_json(snk_pots_obj * obj);
snk_pots_cfg * snk_pots_cfg_construct(void);
obj->format = format_clone(snk_powers_config->format);
obj->interface = interface_clone(snk_powers_config->interface);
- switch (obj->format->type) {
+ if (!((obj->interface->type == interface_blackhole) && (obj->format->type == format_undefined))) {
- case format_binary_float: break;
- default:
-
- printf("Invalid format.\n");
- exit(EXIT_FAILURE);
-
- break;
+ printf("Sink powers: Invalid interface and/or format.\n");
+ exit(EXIT_FAILURE);
}
}
- int snk_powers_open(snk_powers_obj * obj) {
+ void snk_powers_open(snk_powers_obj * obj) {
switch(obj->interface->type) {
- case interface_file:
+ case interface_blackhole:
- obj->fp = fopen(obj->interface->fileName, "wb");
-
- break;
-
- case interface_socket:
-
- printf("Not implemented yet.\n");
- exit(EXIT_FAILURE);
+ snk_powers_open_interface_blackhole(obj);
break;
default:
- printf("Invalid interface type.\n");
+ printf("Sink powers: Invalid interface type.\n");
exit(EXIT_FAILURE);
- break;
+ break;
}
}
- int snk_powers_close(snk_powers_obj * obj) {
+ void snk_powers_open_interface_blackhole(snk_powers_obj * obj) {
- switch(obj->interface->type) {
+ // Empty
- case interface_file:
+ }
- fclose(obj->fp);
+ void snk_powers_close(snk_powers_obj * obj) {
- break;
+ switch(obj->interface->type) {
- case interface_socket:
+ case interface_blackhole:
- printf("Not implemented yet.\n");
- exit(EXIT_FAILURE);
+ snk_powers_close_interface_blackhole(obj);
break;
default:
- printf("Invalid interface type.\n");
+ printf("Sink powers: Invalid interface type.\n");
exit(EXIT_FAILURE);
break;
}
- int snk_powers_process(snk_powers_obj * obj) {
-
- int rtnValue;
-
- switch(obj->interface->type) {
-
- case interface_file:
+ void snk_powers_close_interface_blackhole(snk_powers_obj * obj) {
- rtnValue = snk_powers_process_file(obj);
+ // Empty
- break;
+ }
- case interface_socket:
+ int snk_powers_process(snk_powers_obj * obj) {
- rtnValue = snk_powers_process_socket(obj);
+ int rtnValue;
- break;
+ if (obj->in->timeStamp != 0) {
- default:
+ switch(obj->format->type) {
- printf("Invalid interface type.\n");
- exit(EXIT_FAILURE);
+ case format_undefined:
- break;
+ snk_powers_process_format_undefined(obj);
- }
+ break;
- return rtnValue;
+ default:
- }
+ printf("Sink powers: Invalid format type.\n");
+ exit(EXIT_FAILURE);
- int snk_powers_process_file(snk_powers_obj * obj) {
+ break;
- unsigned int iSample;
- unsigned int iChannel;
- float samplePower;
- int rtnValue;
-
- if (obj->in->timeStamp != 0) {
+ }
- for (iSample = 0; iSample < obj->halfFrameSize; iSample++) {
-
- for (iChannel = 0; iChannel < obj->nChannels; iChannel++) {
+ switch(obj->interface->type) {
- samplePower = obj->in->envs->array[iChannel][iSample];
+ case interface_blackhole:
- switch (obj->format->type) {
-
- case format_binary_float:
+ snk_powers_process_interface_blackhole(obj);
- fwrite(&samplePower, sizeof(float), 1, obj->fp);
+ break;
- break;
+ default:
- }
+ printf("Sink powers: Invalid interface type.\n");
+ exit(EXIT_FAILURE);
- }
+ break;
}
}
- int snk_powers_process_socket(snk_powers_obj * obj) {
+ void snk_powers_process_interface_blackhole(snk_powers_obj * obj) {
+
+ // Empty
+
+ }
+
+ void snk_powers_process_format_undefined(snk_powers_obj * obj) {
- printf("Not implemented\n");
- exit(EXIT_FAILURE);
+ // Empty
}
format_obj * format;
interface_obj * interface;
+ char * buffer;
+ unsigned int bufferSize;
+
FILE * fp;
msg_powers_obj * in;
void snk_powers_disconnect(snk_powers_obj * obj);
- int snk_powers_open(snk_powers_obj * obj);
+ void snk_powers_open(snk_powers_obj * obj);
+
+ void snk_powers_open_interface_blackhole(snk_powers_obj * obj);
+
+ void snk_powers_close(snk_powers_obj * obj);
- int snk_powers_close(snk_powers_obj * obj);
+ void snk_powers_close_interface_blackhole(snk_powers_obj * obj);
int snk_powers_process(snk_powers_obj * obj);
- int snk_powers_process_file(snk_powers_obj * obj);
+ void snk_powers_process_interface_blackhole(snk_powers_obj * obj);
- int snk_powers_process_socket(snk_powers_obj * obj);
+ void snk_powers_process_format_undefined(snk_powers_obj * obj);
snk_powers_cfg * snk_powers_cfg_construct(void);
}
- int snk_spectra_open(snk_spectra_obj * obj) {
+ void snk_spectra_open(snk_spectra_obj * obj) {
switch(obj->interface->type) {
- case interface_file:
+ case interface_blackhole:
- obj->fp = fopen(obj->interface->fileName, "wb");
+ snk_spectra_open_interface_blackhole(obj);
break;
- case interface_socket:
+ default:
- printf("Not implemented yet.\n");
+ printf("Sink spectra: Invalid interface type.\n");
exit(EXIT_FAILURE);
break;
- default:
+ }
- printf("Invalid interface type.\n");
- exit(EXIT_FAILURE);
+ }
- break;
+ void snk_spectra_open_interface_blackhole(snk_spectra_obj * obj) {
- }
+ // Empty
}
- int snk_spectra_close(snk_spectra_obj * obj) {
+ void snk_spectra_close(snk_spectra_obj * obj) {
switch(obj->interface->type) {
- case interface_file:
+ case interface_blackhole:
- fclose(obj->fp);
-
- break;
-
- case interface_socket:
-
- printf("Not implemented yet.\n");
- exit(EXIT_FAILURE);
+ snk_spectra_close_interface_blackhole(obj);
break;
default:
- printf("Invalid interface type.\n");
+ printf("Sink spectra: Invalid interface type.\n");
exit(EXIT_FAILURE);
break;
}
- int snk_spectra_process(snk_spectra_obj * obj) {
+ void snk_spectra_close_interface_blackhole(snk_spectra_obj * obj) {
- int rtnValue;
-
- switch(obj->interface->type) {
-
- case interface_file:
-
- rtnValue = snk_spectra_process_file(obj);
-
- break;
+ // Empty
- case interface_socket:
+ }
- rtnValue = snk_spectra_process_socket(obj);
+ int snk_spectra_process(snk_spectra_obj * obj) {
- break;
+ int rtnValue;
- default:
+ if (obj->in->timeStamp != 0) {
- printf("Invalid interface type.\n");
- exit(EXIT_FAILURE);
+ switch(obj->format->type) {
- break;
+ case format_undefined:
- }
+ snk_spectra_process_format_undefined(obj);
- return rtnValue;
+ break;
- }
+ default:
- int snk_spectra_process_file(snk_spectra_obj * obj) {
+ printf("Sink spectra: Invalid format type.\n");
+ exit(EXIT_FAILURE);
- unsigned int iSample;
- unsigned int iChannel;
- float sampleReal;
- float sampleImag;
- int rtnValue;
+ break;
- if (obj->in->timeStamp != 0) {
+ }
- for (iSample = 0; iSample < obj->halfFrameSize; iSample++) {
-
- for (iChannel = 0; iChannel < obj->nChannels; iChannel++) {
+ switch(obj->interface->type) {
- sampleReal = obj->in->freqs->array[iChannel][iSample*2+0];
- sampleImag = obj->in->freqs->array[iChannel][iSample*2+1];
+ case interface_blackhole:
- switch (obj->format->type) {
-
- case format_binary_float:
+ snk_spectra_process_interface_blackhole(obj);
- fwrite(&sampleReal, sizeof(float), 1, obj->fp);
- fwrite(&sampleImag, sizeof(float), 1, obj->fp);
+ break;
- break;
+ default:
- }
+ printf("Sink spectra: Invalid interface type.\n");
+ exit(EXIT_FAILURE);
- }
+ break;
}
}
- int snk_spectra_process_socket(snk_spectra_obj * obj) {
+ void snk_spectra_process_interface_blackhole(snk_spectra_obj * obj) {
+
+ // Empty
+
+ }
+
+ void snk_spectra_process_format_undefined(snk_spectra_obj * obj) {
- printf("Not implemented\n");
- exit(EXIT_FAILURE);
+ // Empty
}
void snk_spectra_disconnect(snk_spectra_obj * obj);
- int snk_spectra_open(snk_spectra_obj * obj);
+ void snk_spectra_open(snk_spectra_obj * obj);
- int snk_spectra_close(snk_spectra_obj * obj);
+ void snk_spectra_open_interface_blackhole(snk_spectra_obj * obj);
+
+ void snk_spectra_close(snk_spectra_obj * obj);
+
+ void snk_spectra_close_interface_blackhole(snk_spectra_obj * obj);
int snk_spectra_process(snk_spectra_obj * obj);
- int snk_spectra_process_file(snk_spectra_obj * obj);
+ void snk_spectra_process_interface_blackhole(snk_spectra_obj * obj);
- int snk_spectra_process_socket(snk_spectra_obj * obj);
+ void snk_spectra_process_format_undefined(snk_spectra_obj * obj);
snk_spectra_cfg * snk_spectra_cfg_construct(void);
obj->format = format_clone(snk_tracks_config->format);
obj->interface = interface_clone(snk_tracks_config->interface);
- switch (obj->format->type) {
+ if (!(((obj->interface->type == interface_blackhole) && (obj->format->type == format_undefined)) ||
+ ((obj->interface->type == interface_file) && (obj->format->type == format_text_json)) ||
+ ((obj->interface->type == interface_socket) && (obj->format->type == format_text_json)))) {
- case format_text_json: break;
- case format_binary_float: break;
- default:
-
- printf("Invalid format.\n");
- exit(EXIT_FAILURE);
-
- break;
+ printf("Sink tracks: Invalid interface and/or format.\n");
+ exit(EXIT_FAILURE);
}
obj->fp = (FILE *) NULL;
- obj->smessage = (char *) malloc(sizeof(char) * (1024 + 1024 * msg_tracks_config->nTracks));
+ obj->buffer = (char *) malloc(sizeof(char) * 1024);
+ memset(obj->buffer, 0x00, sizeof(char) * 1024);
+ obj->bufferSize = 0;
obj->in = (msg_tracks_obj *) NULL;
void snk_tracks_destroy(snk_tracks_obj * obj) {
- free((void *) obj->smessage);
+ free((void *) obj->buffer);
format_destroy(obj->format);
interface_destroy(obj->interface);
}
- int snk_tracks_open(snk_tracks_obj * obj) {
+ void snk_tracks_open(snk_tracks_obj * obj) {
switch(obj->interface->type) {
case interface_blackhole:
- // Empty
+ snk_tracks_open_interface_blackhole(obj);
break;
case interface_file:
- obj->fp = fopen(obj->interface->fileName, "wb");
+ snk_tracks_open_interface_file(obj);
break;
case interface_socket:
- memset(&(obj->sclient), 0x00, sizeof(struct sockaddr_in));
-
- obj->sclient.sin_family = AF_INET;
- obj->sclient.sin_addr.s_addr = inet_addr(obj->interface->ip);
- obj->sclient.sin_port = htons(obj->interface->port);
- obj->sid = socket(AF_INET, SOCK_STREAM, 0);
-
- if ( (connect(obj->sid, (struct sockaddr *) &(obj->sclient), sizeof(obj->sclient))) < 0 ) {
-
- printf("Cannot connect to server\n");
- exit(EXIT_FAILURE);
-
- }
+ snk_tracks_open_interface_socket(obj);
break;
case interface_terminal:
- // (Empty)
+ snk_tracks_open_interface_terminal(obj);
break;
default:
- printf("Invalid interface type.\n");
+ printf("Sink tracks: Invalid interface type.\n");
exit(EXIT_FAILURE);
break;
}
- int snk_tracks_close(snk_tracks_obj * obj) {
-
- switch(obj->interface->type) {
-
- case interface_blackhole:
+ void snk_tracks_open_interface_blackhole(snk_tracks_obj * obj) {
- // Empty
+ // Empty
- break;
+ }
- case interface_file:
+ void snk_tracks_open_interface_file(snk_tracks_obj * obj) {
- fclose(obj->fp);
+ obj->fp = fopen(obj->interface->fileName, "wb");
- break;
+ }
- case interface_socket:
+ void snk_tracks_open_interface_socket(snk_tracks_obj * obj) {
- close(obj->sid);
+ memset(&(obj->sserver), 0x00, sizeof(struct sockaddr_in));
- break;
+ 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);
- case interface_terminal:
+ if ( (connect(obj->sid, (struct sockaddr *) &(obj->sserver), sizeof(obj->sserver))) < 0 ) {
- // Empty
+ printf("Sink tracks: Cannot connect to server\n");
+ exit(EXIT_FAILURE);
- break;
+ }
- default:
+ }
- printf("Invalid interface type.\n");
- exit(EXIT_FAILURE);
+ void snk_tracks_open_interface_terminal(snk_tracks_obj * obj) {
- break;
-
- }
+ // Empty
}
- int snk_tracks_process(snk_tracks_obj * obj) {
-
- int rtnValue;
+ void snk_tracks_close(snk_tracks_obj * obj) {
switch(obj->interface->type) {
case interface_blackhole:
- rtnValue = snk_tracks_process_blackhole(obj);
+ snk_tracks_close_interface_blackhole(obj);
break;
case interface_file:
- rtnValue = snk_tracks_process_file(obj);
+ snk_tracks_close_interface_file(obj);
break;
case interface_socket:
- rtnValue = snk_tracks_process_socket(obj);
+ snk_tracks_close_interface_socket(obj);
break;
case interface_terminal:
- rtnValue = snk_tracks_process_terminal(obj);
+ snk_tracks_close_interface_terminal(obj);
break;
default:
- printf("Invalid interface type.\n");
+ printf("Sink tracks: Invalid interface type.\n");
exit(EXIT_FAILURE);
break;
}
- return rtnValue;
+ }
+
+ void snk_tracks_close_interface_blackhole(snk_tracks_obj * obj) {
+
+ // Empty
}
- int snk_tracks_process_blackhole(snk_tracks_obj * obj) {
+ void snk_tracks_close_interface_file(snk_tracks_obj * obj) {
- int rtnValue;
+ fclose(obj->fp);
- if (obj->in->timeStamp != 0) {
+ }
- rtnValue = 0;
+ void snk_tracks_close_interface_socket(snk_tracks_obj * obj) {
- }
- else {
+ close(obj->sid);
- rtnValue = -1;
+ }
- }
+ void snk_tracks_close_interface_terminal(snk_tracks_obj * obj) {
- return rtnValue;
+ // Empty
}
- int snk_tracks_process_file(snk_tracks_obj * obj) {
+ int snk_tracks_process(snk_tracks_obj * obj) {
int rtnValue;
- unsigned int iTrack;
if (obj->in->timeStamp != 0) {
switch(obj->format->type) {
- case format_binary_float:
-
- fwrite(obj->in->tracks->ids, sizeof(unsigned long long), obj->in->tracks->nTracks, obj->fp);
- fwrite(obj->in->tracks->array, sizeof(float), 3 * obj->in->tracks->nTracks, obj->fp);
-
- break;
-
case format_text_json:
- fprintf(obj->fp,"{\n");
- fprintf(obj->fp," \"timeStamp\": %llu,\n",obj->in->timeStamp);
- fprintf(obj->fp," \"src\": [\n");
-
- for (iTrack = 0; iTrack < obj->nTracks; iTrack++) {
-
- fprintf(obj->fp," { \"id\": %llu, \"x\": %1.3f, \"y\": %1.3f, \"z\": %1.3f }",
- obj->in->tracks->ids[iTrack],
- obj->in->tracks->array[iTrack*3+0],
- obj->in->tracks->array[iTrack*3+1],
- obj->in->tracks->array[iTrack*3+2]);
+ snk_tracks_process_format_text_json(obj);
- if (iTrack != (obj->nTracks - 1)) {
-
- fprintf(obj->fp,",");
-
- }
-
- fprintf(obj->fp,"\n");
+ break;
- }
-
- fprintf(obj->fp," ]\n");
- fprintf(obj->fp,"}\n");
+ default:
- rtnValue = 0;
+ printf("Sink tracks: Invalid format type.\n");
+ exit(EXIT_FAILURE);
- break;
+ break;
}
- rtnValue = 0;
-
- }
- else {
-
- rtnValue = -1;
-
- }
-
- return rtnValue;
+ switch(obj->interface->type) {
- }
+ case interface_blackhole:
- int snk_tracks_process_socket(snk_tracks_obj * obj) {
+ snk_tracks_process_interface_blackhole(obj);
- int rtnValue;
- unsigned int iTrack;
-
- if (obj->in->timeStamp != 0) {
-
- switch(obj->format->type) {
-
- case format_text_json:
+ break;
- obj->smessage[0] = 0x00;
+ case interface_file:
- sprintf(obj->smessage,"%s{\n",obj->smessage);
- sprintf(obj->smessage,"%s \"timeStamp\": %llu,\n",obj->smessage,obj->in->timeStamp);
- sprintf(obj->smessage,"%s \"src\": [\n",obj->smessage);
+ snk_tracks_process_interface_file(obj);
- for (iTrack = 0; iTrack < obj->nTracks; iTrack++) {
+ break;
- sprintf(obj->smessage,"%s { \"id\": %llu, \"x\": %1.3f, \"y\": %1.3f, \"z\": %1.3f }", obj->smessage,
- obj->in->tracks->ids[iTrack],
- obj->in->tracks->array[iTrack*3+0],
- obj->in->tracks->array[iTrack*3+1],
- obj->in->tracks->array[iTrack*3+2]);
+ case interface_socket:
- if (iTrack != (obj->nTracks - 1)) {
+ snk_tracks_process_interface_socket(obj);
- sprintf(obj->smessage,"%s,",obj->smessage);
+ break;
- }
+ case interface_terminal:
- sprintf(obj->smessage,"%s\n",obj->smessage);
+ snk_tracks_process_interface_terminal(obj);
- }
-
- sprintf(obj->smessage,"%s ]\n",obj->smessage);
- sprintf(obj->smessage,"%s}\n",obj->smessage);
+ break;
- if (send(obj->sid, obj->smessage, strlen(obj->smessage), 0) < 0) {
- printf("Could not send message.\n");
- exit(EXIT_FAILURE);
- }
+ default:
- rtnValue = 0;
+ printf("Sink tracks: Invalid interface type.\n");
+ exit(EXIT_FAILURE);
- break;
+ break;
}
+ rtnValue = 0;
+
}
else {
}
- int snk_tracks_process_terminal(snk_tracks_obj * obj) {
+ void snk_tracks_process_interface_blackhole(snk_tracks_obj * obj) {
- int rtnValue;
- unsigned int iTrack;
+ // Empty
- if (obj->in->timeStamp != 0) {
+ }
- switch(obj->format->type) {
+ void snk_tracks_process_interface_file(snk_tracks_obj * obj) {
- case format_text_json:
+ fwrite(obj->buffer, sizeof(char), obj->bufferSize, obj->fp);
+
+ }
- printf("{\n");
- printf(" \"timeStamp\": %llu,\n",obj->in->timeStamp);
- printf(" \"src\": [\n");
+ void snk_tracks_process_interface_socket(snk_tracks_obj * obj) {
- for (iTrack = 0; iTrack < obj->nTracks; iTrack++) {
+ if (send(obj->sid, obj->buffer, obj->bufferSize, 0) < 0) {
+ printf("Sink tracks: Could not send message.\n");
+ exit(EXIT_FAILURE);
+ }
- printf(" { \"id\": %llu, \"x\": %1.3f, \"y\": %1.3f, \"z\": %1.3f }",
- obj->in->tracks->ids[iTrack],
- obj->in->tracks->array[iTrack*3+0], obj->in->tracks->array[iTrack*3+1], obj->in->tracks->array[iTrack*3+2]);
+ }
- if (iTrack != (obj->nTracks - 1)) {
+ void snk_tracks_process_interface_terminal(snk_tracks_obj * obj) {
- printf(",");
+ printf("%s",obj->buffer);
- }
+ }
- printf("\n");
+ void snk_tracks_process_format_text_json(snk_tracks_obj * obj) {
- }
-
- printf(" ]\n");
- printf("}\n");
+ unsigned int iTrack;
- rtnValue = 0;
+ obj->buffer[0] = 0x00;
- break;
+ sprintf(obj->buffer,"%s{\n",obj->buffer);
+ sprintf(obj->buffer,"%s \"timeStamp\": %llu,\n",obj->buffer,obj->in->timeStamp);
+ sprintf(obj->buffer,"%s \"src\": [\n",obj->buffer);
- }
+ for (iTrack = 0; iTrack < obj->nTracks; iTrack++) {
- }
- else {
+ sprintf(obj->buffer,"%s { \"id\": %llu, \"x\": %1.3f, \"y\": %1.3f, \"z\": %1.3f }",
+ obj->buffer,
+ obj->in->tracks->ids[iTrack],
+ obj->in->tracks->array[iTrack*3+0],
+ obj->in->tracks->array[iTrack*3+1],
+ obj->in->tracks->array[iTrack*3+2]);
- rtnValue = -1;
+ if (iTrack != (obj->nTracks - 1)) {
+
+ sprintf(obj->buffer,"%s,",obj->buffer);
+
+ }
+
+ sprintf(obj->buffer,"%s\n",obj->buffer);
}
+
+ sprintf(obj->buffer,"%s ]\n",obj->buffer);
+ sprintf(obj->buffer,"%s}\n",obj->buffer);
- return rtnValue;
+ obj->bufferSize = strlen(obj->buffer);
}
format_obj * format;
interface_obj * interface;
+ char * buffer;
+ unsigned int bufferSize;
+
FILE * fp;
- char * smessage;
- struct sockaddr_in sclient;
+ struct sockaddr_in sserver;
int sid;
msg_tracks_obj * in;
void snk_tracks_disconnect(snk_tracks_obj * obj);
- int snk_tracks_open(snk_tracks_obj * obj);
+ void snk_tracks_open(snk_tracks_obj * obj);
+
+ void snk_tracks_open_interface_blackhole(snk_tracks_obj * obj);
+
+ void snk_tracks_open_interface_file(snk_tracks_obj * obj);
+
+ void snk_tracks_open_interface_socket(snk_tracks_obj * obj);
+
+ void snk_tracks_open_interface_terminal(snk_tracks_obj * obj);
- int snk_tracks_close(snk_tracks_obj * obj);
+ void snk_tracks_close(snk_tracks_obj * obj);
+
+ void snk_tracks_close_interface_blackhole(snk_tracks_obj * obj);
+
+ void snk_tracks_close_interface_file(snk_tracks_obj * obj);
+
+ void snk_tracks_close_interface_socket(snk_tracks_obj * obj);
+
+ void snk_tracks_close_interface_terminal(snk_tracks_obj * obj);
int snk_tracks_process(snk_tracks_obj * obj);
- int snk_tracks_process_blackhole(snk_tracks_obj * obj);
+ void snk_tracks_process_interface_blackhole(snk_tracks_obj * obj);
+
+ void snk_tracks_process_interface_file(snk_tracks_obj * obj);
- int snk_tracks_process_file(snk_tracks_obj * obj);
+ void snk_tracks_process_interface_socket(snk_tracks_obj * obj);
- int snk_tracks_process_socket(snk_tracks_obj * obj);
+ void snk_tracks_process_interface_terminal(snk_tracks_obj * obj);
- int snk_tracks_process_terminal(snk_tracks_obj * obj);
+ void snk_tracks_process_format_text_json(snk_tracks_obj * obj);
snk_tracks_cfg * snk_tracks_cfg_construct(void);