Add files via upload
authorFrançois Grondin <Francois.Grondin2@USherbrooke.ca>
Mon, 3 Jul 2017 19:16:59 +0000 (15:16 -0400)
committerGitHub <noreply@github.com>
Mon, 3 Jul 2017 19:16:59 +0000 (15:16 -0400)
14 files changed:
src/general/format.c [new file with mode: 0644]
src/general/format.h [new file with mode: 0644]
src/general/interface.c [new file with mode: 0644]
src/general/interface.h [new file with mode: 0644]
src/general/link.c [new file with mode: 0644]
src/general/link.h [new file with mode: 0644]
src/general/mic.c [new file with mode: 0644]
src/general/mic.h [new file with mode: 0644]
src/general/samplerate.c [new file with mode: 0644]
src/general/samplerate.h [new file with mode: 0644]
src/general/soundspeed.c [new file with mode: 0644]
src/general/soundspeed.h [new file with mode: 0644]
src/general/thread.c [new file with mode: 0644]
src/general/thread.h [new file with mode: 0644]

diff --git a/src/general/format.c b/src/general/format.c
new file mode 100644 (file)
index 0000000..6586ce3
--- /dev/null
@@ -0,0 +1,140 @@
+    
+    #include "format.h"
+
+    format_obj * format_construct() {
+
+        format_obj * obj;
+
+        obj = (format_obj *) malloc(sizeof(format_obj));
+
+        obj->type = format_undefined;
+
+        return obj;
+
+    }
+
+    format_obj * format_construct_bin(const unsigned int nBits) {
+
+        format_obj * obj;
+
+        obj = (format_obj *) malloc(sizeof(format_obj));
+
+        switch(nBits) {
+
+            case 8:
+
+                obj->type = format_bin08;
+
+            break;
+
+            case 16:
+
+                obj->type = format_bin16;
+
+            break;
+
+            case 24:
+
+                obj->type = format_bin24;
+
+            break;
+
+            case 32:
+
+                obj->type = format_bin32;
+
+            break;
+
+            default:
+
+                printf("Wrong number of bits.\n");
+                exit(EXIT_FAILURE);
+
+            break;
+
+        }
+
+        return obj;
+
+    }
+
+    format_obj * format_construct_float() {
+
+        format_obj * obj;
+
+        obj = (format_obj *) malloc(sizeof(format_obj));
+
+        obj->type = format_float;
+
+        return obj;
+
+    }
+
+    format_obj * format_construct_json() {
+
+        format_obj * obj;
+
+        obj = (format_obj *) malloc(sizeof(format_obj));
+
+        obj->type = format_json;
+
+        return obj;
+
+    }
+
+    format_obj * format_clone(const format_obj * obj) {
+
+        format_obj * clone;
+
+        clone = format_construct();
+
+        clone->type = obj->type;
+
+        return clone;
+
+    }
+
+    void format_destroy(format_obj * obj) {
+
+        free((void *) obj);
+
+    }
+
+    void format_printf(const format_obj * obj) {
+
+        if (obj != NULL) {
+
+            switch(obj->type) {
+
+                case format_bin08:
+                    printf("type = bin08\n");
+                break;
+
+                case format_bin16:
+                    printf("type = bin16\n");
+                break;
+
+                case format_bin24:
+                    printf("type = bin24\n");
+                break;
+
+                case format_bin32:
+                    printf("type = bin32\n");
+                break;
+
+                case format_float:
+                    printf("type = float\n");
+                break;
+
+                case format_json:
+                    printf("type = json\n");
+                break;
+
+            }
+
+        }
+        else {
+            printf("(null)\n");
+        }
+
+    }
\ No newline at end of file
diff --git a/src/general/format.h b/src/general/format.h
new file mode 100644 (file)
index 0000000..5a15b24
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef __ODAS_GENERAL_FORMAT
+#define __ODAS_GENERAL_FORMAT
+
+    #include <stdlib.h>
+    #include <stdio.h>
+
+    typedef enum format_type { 
+        
+        format_undefined = 0,
+        format_bin08 = 8, 
+        format_bin16 = 16, 
+        format_bin24 = 24, 
+        format_bin32 = 32, 
+        format_float = 1, 
+        format_json = 2,
+
+    } format_type;
+
+    typedef struct format_obj {
+
+        format_type type;
+
+    } format_obj;
+
+    format_obj * format_construct();
+
+    format_obj * format_construct_bin(const unsigned int nBits);
+
+    format_obj * format_construct_float();    
+
+    format_obj * format_construct_json();
+
+    format_obj * format_clone(const format_obj * obj);
+
+    void format_destroy(format_obj * obj);
+
+    void format_printf(const format_obj * obj);
+
+#endif
\ No newline at end of file
diff --git a/src/general/interface.c b/src/general/interface.c
new file mode 100644 (file)
index 0000000..57fa03a
--- /dev/null
@@ -0,0 +1,251 @@
+    
+    #include "interface.h"
+
+    interface_obj * interface_construct() {
+
+        interface_obj * obj;
+
+        obj = (interface_obj *) malloc(sizeof(interface_obj));
+
+        // +----------------------------------------------------------+
+        // | Type                                                     |
+        // +----------------------------------------------------------+
+
+            obj->type = interface_undefined;
+
+        // +----------------------------------------------------------+
+        // | File                                                     |
+        // +----------------------------------------------------------+
+
+            obj->fileName = (char *) NULL;
+
+        // +----------------------------------------------------------+
+        // | Socket                                                   |
+        // +----------------------------------------------------------+
+
+            obj->ip = (char *) NULL;
+            obj->port = 0;
+
+        // +----------------------------------------------------------+
+        // | Soundcard                                                |
+        // +----------------------------------------------------------+
+
+            obj->device = 0;
+            obj->subdevice = 0;
+
+        return obj;
+
+    }
+
+    interface_obj * interface_construct_file(const char * fileName) {
+
+        interface_obj * obj;
+
+        obj = (interface_obj *) malloc(sizeof(interface_obj));
+
+        // +----------------------------------------------------------+
+        // | Type                                                     |
+        // +----------------------------------------------------------+
+
+            obj->type = interface_file;
+
+        // +----------------------------------------------------------+
+        // | File                                                     |
+        // +----------------------------------------------------------+
+
+            obj->fileName = (char *) malloc(sizeof(char) * (strlen(fileName)+1));
+            strcpy(obj->fileName, fileName);
+
+        // +----------------------------------------------------------+
+        // | Socket                                                   |
+        // +----------------------------------------------------------+
+
+            obj->ip = (char *) NULL;
+            obj->port = 0;
+
+        // +----------------------------------------------------------+
+        // | Soundcard                                                |
+        // +----------------------------------------------------------+
+
+            obj->device = 0;
+            obj->subdevice = 0;
+
+        return obj;
+
+    }
+
+    interface_obj * interface_construct_socket(const char * ip, const unsigned int port) {
+
+        interface_obj * obj;
+
+        obj = (interface_obj *) malloc(sizeof(interface_obj));
+
+        // +----------------------------------------------------------+
+        // | Type                                                     |
+        // +----------------------------------------------------------+
+
+            obj->type = interface_socket;
+
+        // +----------------------------------------------------------+
+        // | File                                                     |
+        // +----------------------------------------------------------+
+
+            obj->fileName = (char *) NULL;
+
+        // +----------------------------------------------------------+
+        // | Socket                                                   |
+        // +----------------------------------------------------------+
+
+            obj->ip = (char *) malloc(sizeof(char) * (strlen(ip)+1));
+            strcpy(obj->ip, ip);
+            obj->port = port;
+
+        // +----------------------------------------------------------+
+        // | Soundcard                                                |
+        // +----------------------------------------------------------+
+
+            obj->device = 0;
+            obj->subdevice = 0;
+
+        return obj;        
+
+    }
+
+    interface_obj * interface_construct_soundcard(const unsigned int device, const unsigned int subdevice) {
+
+        interface_obj * obj;
+
+        obj = (interface_obj *) malloc(sizeof(interface_obj));
+
+        // +----------------------------------------------------------+
+        // | Type                                                     |
+        // +----------------------------------------------------------+
+
+            obj->type = interface_soundcard;
+
+        // +----------------------------------------------------------+
+        // | File                                                     |
+        // +----------------------------------------------------------+
+
+            obj->fileName = (char *) NULL;
+
+        // +----------------------------------------------------------+
+        // | Socket                                                   |
+        // +----------------------------------------------------------+
+
+            obj->ip = (char *) NULL;
+            obj->port = 0;
+
+        // +----------------------------------------------------------+
+        // | Soundcard                                                |
+        // +----------------------------------------------------------+
+
+            obj->device = device;
+            obj->subdevice = subdevice;
+
+        return obj;
+
+    }
+
+    interface_obj * interface_clone(const interface_obj * obj) {
+
+        interface_obj * clone;
+
+        clone = interface_construct();
+
+        // +----------------------------------------------------------+
+        // | Type                                                     |
+        // +----------------------------------------------------------+
+
+            clone->type = obj->type;        
+
+        // +----------------------------------------------------------+
+        // | File                                                     |
+        // +----------------------------------------------------------+
+
+            if (obj->type == interface_file) {
+                
+                clone->fileName = (char *) malloc(sizeof(char) * (strlen(obj->fileName) + 1));
+                strcpy(clone->fileName, obj->fileName);
+
+            }
+
+        // +----------------------------------------------------------+
+        // | Socket                                                   |
+        // +----------------------------------------------------------+                
+
+            if (obj->type == interface_socket) {
+                
+                clone->ip = (char *) malloc(sizeof(char) * (strlen(obj->fileName) + 1));
+                strcpy(clone->ip, obj->ip);
+                clone->port = obj->port;
+
+            }
+
+        // +----------------------------------------------------------+
+        // | Soundcard                                                |
+        // +----------------------------------------------------------+
+
+            if (obj->type == interface_soundcard) {
+                
+                clone->device = obj->device;
+                clone->subdevice = obj->subdevice;
+
+            }
+
+        return clone;
+
+    }
+
+    void interface_destroy(interface_obj * obj) {
+
+        if (obj->fileName != NULL) {
+
+            free((void *) obj->fileName);
+
+        }
+
+        if (obj->ip != NULL) {
+
+            free((void *) obj->ip);
+
+        }
+
+        free((void *) obj);
+
+    }
+
+    void interface_printf(const interface_obj * obj) {
+
+        if (obj != NULL) {
+
+            switch(obj->type) {
+
+                case interface_file:
+
+                    printf("type = file, fileName = %s\n",obj->fileName);
+
+                break;
+
+                case interface_socket:
+
+                    printf("type = socket, ip = %s, port = %u\n",obj->ip,obj->port);
+
+                break;
+
+                case interface_soundcard:
+
+                    printf("type = soundcard, device = %u, subdevice = %u\n",obj->device,obj->subdevice);
+
+                break;
+
+            }
+
+        }
+        else {
+
+            printf("(null)\n");
+
+        }
+
+    }
\ No newline at end of file
diff --git a/src/general/interface.h b/src/general/interface.h
new file mode 100644 (file)
index 0000000..8da8b02
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef __ODAS_GENERAL_INTERFACE
+#define __ODAS_GENERAL_INTERFACE
+
+    #include <stdlib.h>
+    #include <stdio.h>
+    #include <string.h>
+
+    typedef enum interface_type { 
+        
+        interface_undefined = 0,
+        interface_file = 1,
+        interface_socket = 2, 
+        interface_soundcard = 3, 
+        
+    } interface_type;
+
+    typedef struct interface_obj {
+
+        interface_type type;
+
+        char * fileName;
+
+        char * ip;
+        unsigned int port;
+
+        unsigned int device;
+        unsigned int subdevice;
+
+    } interface_obj;
+
+    interface_obj * interface_construct();
+
+    interface_obj * interface_construct_file(const char * fileName);
+
+    interface_obj * interface_construct_socket(const char * ip, const unsigned int port);
+
+    interface_obj * interface_construct_soundcard(const unsigned int device, const unsigned int subdevice);
+
+    interface_obj * interface_clone(const interface_obj * obj);
+
+    void interface_destroy(interface_obj * obj);
+
+    void interface_printf(const interface_obj * obj);
+
+#endif
\ No newline at end of file
diff --git a/src/general/link.c b/src/general/link.c
new file mode 100644 (file)
index 0000000..d2609ad
--- /dev/null
@@ -0,0 +1,47 @@
+    
+    #include "link.h"
+
+    links_obj * links_construct_zero(const unsigned int nLinks) {
+
+        links_obj * obj;
+
+        obj = (links_obj *) malloc(sizeof(links_obj));
+
+        obj->nLinks = nLinks;
+        obj->array = (unsigned int *) malloc(sizeof(unsigned int) * nLinks);
+        memset(obj->array, 0x00, sizeof(unsigned int) * nLinks);
+
+        return obj;
+
+    }
+
+    links_obj * links_clone(const links_obj * obj) {
+
+        links_obj * clone;
+
+        clone = (links_obj *) malloc(sizeof(links_obj));
+
+        clone->nLinks = obj->nLinks;
+        clone->array = (unsigned int *) malloc(sizeof(unsigned int) * obj->nLinks);
+        memcpy(clone->array, obj->array, sizeof(unsigned int) * obj->nLinks);
+
+        return clone;
+
+    }
+
+    void links_destroy(links_obj * obj) {
+
+        free((void *) obj->array);
+        free((void *) obj);
+
+    }
+
+    void links_printf(const links_obj * obj) {
+
+        unsigned int iLink;
+
+        for (iLink = 0; iLink < obj->nLinks; iLink++) {
+            printf("(%u): %u\n",iLink,obj->array[iLink]);
+        }
+
+    }
\ No newline at end of file
diff --git a/src/general/link.h b/src/general/link.h
new file mode 100644 (file)
index 0000000..94599cc
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef __ODAS_GENERAL_LINK
+#define __ODAS_GENERAL_LINK
+
+    #include <stdlib.h>
+    #include <stdio.h>
+    #include <string.h>
+
+    typedef struct links_obj {
+
+        unsigned int * array;
+        unsigned int nLinks;
+
+    } links_obj;
+
+    links_obj * links_construct_zero(const unsigned int nLinks);
+
+    links_obj * links_clone(const links_obj * obj);
+
+    void links_destroy(links_obj * obj);
+
+    void links_printf(const links_obj * obj);
+
+#endif
\ No newline at end of file
diff --git a/src/general/mic.c b/src/general/mic.c
new file mode 100644 (file)
index 0000000..5657fac
--- /dev/null
@@ -0,0 +1,118 @@
+
+    #include "mic.h"
+
+    // +----------------------------------------------------------+
+    // | Constructor                                              |
+    // +----------------------------------------------------------+
+
+    mics_obj * mics_construct_zero(const unsigned int nChannels) {
+
+        mics_obj * obj;
+
+        obj = (mics_obj *) malloc(sizeof(mics_obj));
+
+        obj->nChannels = nChannels;
+        obj->nPairs = nChannels * (nChannels - 1) / 2;
+        obj->mu = (float *) malloc(sizeof(float) * nChannels * 3);
+        memset(obj->mu, 0x00, sizeof(float) * nChannels * 3);        
+        obj->sigma2 = (float *) malloc(sizeof(float) * nChannels * 9);
+        memset(obj->sigma2, 0x00, sizeof(float) * nChannels * 9);        
+        obj->direction = (float *) malloc(sizeof(float) * nChannels * 3);
+        memset(obj->direction, 0x00, sizeof(float) * nChannels * 3);
+        obj->thetaAllPass = (float *) malloc(sizeof(float) * nChannels);
+        memset(obj->thetaAllPass, 0x00, sizeof(float) * nChannels);
+        obj->thetaNoPass = (float *) malloc(sizeof(float) * nChannels);
+        memset(obj->thetaNoPass, 0x00, sizeof(float) * nChannels);
+
+        return obj;
+
+    }
+
+    // +----------------------------------------------------------+
+    // | Clone                                                    |
+    // +----------------------------------------------------------+
+
+    mics_obj * mics_clone(const mics_obj * obj) {
+
+        mics_obj * clone;
+
+        clone = (mics_obj *) malloc(sizeof(mics_obj));
+
+        clone->nChannels = obj->nChannels;
+        clone->nPairs = obj->nPairs;
+        clone->mu = (float *) malloc(sizeof(float) * obj->nChannels * 3);
+        memcpy(clone->mu, obj->mu, sizeof(float) * obj->nChannels * 3);
+        clone->sigma2 = (float *) malloc(sizeof(float) * obj->nChannels * 9);
+        memcpy(clone->sigma2, obj->sigma2, sizeof(float) * obj->nChannels * 9);
+        clone->direction = (float *) malloc(sizeof(float) * obj->nChannels * 3);
+        memcpy(clone->direction, obj->direction, sizeof(float) * obj->nChannels * 3);
+        clone->thetaAllPass = (float *) malloc(sizeof(float) * obj->nChannels);
+        memcpy(clone->thetaAllPass, obj->thetaAllPass, sizeof(float) * obj->nChannels);
+        clone->thetaNoPass = (float *) malloc(sizeof(float) * obj->nChannels);
+        memcpy(clone->thetaNoPass, obj->thetaNoPass, sizeof(float) * obj->nChannels);
+
+        return clone;
+
+    }
+
+    // +----------------------------------------------------------+
+    // | Destructor                                               |
+    // +----------------------------------------------------------+
+
+    void mics_destroy(mics_obj * obj) {
+
+        free((void *) obj->mu);
+        free((void *) obj->sigma2);
+        free((void *) obj->direction);
+        free((void *) obj->thetaAllPass);
+        free((void *) obj->thetaNoPass);
+
+        free((void *) obj);
+
+    }
+
+    // +----------------------------------------------------------+
+    // | Print                                                    |
+    // +----------------------------------------------------------+    
+
+    void mics_printf(const mics_obj * obj) {
+
+        unsigned int iChannel;
+
+        for (iChannel = 0; iChannel < obj->nChannels; iChannel++) {
+            
+            printf("(%02u): mu = (%+1.3f, %+1.3f, %+1.3f)\n",
+                   iChannel,
+                   obj->mu[iChannel * 3 + 0],
+                   obj->mu[iChannel * 3 + 1],
+                   obj->mu[iChannel * 3 + 2]);
+
+            printf("               / %+1.3f %+1.3f %+1.3f \\\n",
+                   obj->sigma2[iChannel * 9 + 0],
+                   obj->sigma2[iChannel * 9 + 1],
+                   obj->sigma2[iChannel * 9 + 2]);
+
+            printf("      Sigma2 = | %+1.3f %+1.3f %+1.3f |\n",
+                   obj->sigma2[iChannel * 9 + 3],
+                   obj->sigma2[iChannel * 9 + 4],
+                   obj->sigma2[iChannel * 9 + 5]);
+
+            printf("               \\ %+1.3f %+1.3f %+1.3f /\n",
+                   obj->sigma2[iChannel * 9 + 6],
+                   obj->sigma2[iChannel * 9 + 7],
+                   obj->sigma2[iChannel * 9 + 8]);    
+
+            printf("      direction = (%+1.3f, %+1.3f, %+1.3f)\n",
+                   obj->direction[iChannel * 3 + 0],
+                   obj->direction[iChannel * 3 + 1],
+                   obj->direction[iChannel * 3 + 2]);            
+
+            printf("      thetaAllPass = %+1.3f\n",
+                   obj->thetaAllPass[iChannel]);   
+
+            printf("      thetaNoPass = %+1.3f\n",
+                   obj->thetaNoPass[iChannel]);   
+
+        }
+
+    }
\ No newline at end of file
diff --git a/src/general/mic.h b/src/general/mic.h
new file mode 100644 (file)
index 0000000..ff682d9
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef __ODAS_GENERAL_MIC
+#define __ODAS_GENERAL_MIC
+
+    #include <stdlib.h>
+    #include <stdio.h>
+    #include <string.h>
+
+    typedef struct mics_obj {
+
+        unsigned int nChannels;
+        unsigned int nPairs;
+        float * mu;
+        float * sigma2;
+        float * direction;
+        float * thetaAllPass;
+        float * thetaNoPass;
+
+    } mics_obj;
+
+    mics_obj * mics_construct_zero(const unsigned int nChannels);
+
+    mics_obj * mics_clone(const mics_obj * obj);
+
+    void mics_destroy(mics_obj * obj);
+
+    void mics_printf(const mics_obj * obj);
+
+#endif
\ No newline at end of file
diff --git a/src/general/samplerate.c b/src/general/samplerate.c
new file mode 100644 (file)
index 0000000..8aac0c8
--- /dev/null
@@ -0,0 +1,57 @@
+    
+    #include "samplerate.h"
+
+    // +----------------------------------------------------------+
+    // | Constructor                                              |
+    // +----------------------------------------------------------+
+
+    samplerate_obj * samplerate_construct_zero(void) {
+
+        samplerate_obj * obj;
+
+        obj = (samplerate_obj *) malloc(sizeof(samplerate_obj));
+
+        obj->mu = 0;
+        obj->sigma2 = 0.0f;
+
+        return obj;
+
+    }
+
+    // +----------------------------------------------------------+
+    // | Clone                                                    |
+    // +----------------------------------------------------------+
+
+    samplerate_obj * samplerate_clone(const samplerate_obj * obj) {
+
+        samplerate_obj * clone;
+
+        clone = (samplerate_obj *) malloc(sizeof(samplerate_obj));
+
+        clone->mu = obj->mu;
+        clone->sigma2 = obj->sigma2;
+
+        return clone;
+
+    }
+
+    // +----------------------------------------------------------+
+    // | Destructor                                               |
+    // +----------------------------------------------------------+
+
+    void samplerate_destroy(samplerate_obj * obj) {
+
+        free((void *) obj);
+
+    }
+
+    // +----------------------------------------------------------+
+    // | Print                                                    |
+    // +----------------------------------------------------------+
+
+    void samplerate_printf(const samplerate_obj * obj) {
+
+        printf("mu = %u\n",obj->mu);
+        printf("sigma2 = %f\n",obj->sigma2);
+
+    }
\ No newline at end of file
diff --git a/src/general/samplerate.h b/src/general/samplerate.h
new file mode 100644 (file)
index 0000000..392ef15
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef __ODAS_GENERAL_SAMPLERATE
+#define __ODAS_GENERAL_SAMPLERATE
+
+    #include <stdlib.h>
+    #include <stdio.h>
+
+    typedef struct samplerate_obj {
+
+        unsigned int mu;
+        float sigma2;
+
+    } samplerate_obj;
+
+    samplerate_obj * samplerate_construct_zero(void);
+
+    samplerate_obj * samplerate_clone(const samplerate_obj * obj);
+
+    void samplerate_destroy(samplerate_obj * obj);
+
+    void samplerate_printf(const samplerate_obj * obj);
+
+#endif
\ No newline at end of file
diff --git a/src/general/soundspeed.c b/src/general/soundspeed.c
new file mode 100644 (file)
index 0000000..7619a59
--- /dev/null
@@ -0,0 +1,57 @@
+    
+    #include "soundspeed.h"
+
+    // +----------------------------------------------------------+
+    // | Constructor                                              |
+    // +----------------------------------------------------------+
+
+    soundspeed_obj * soundspeed_construct_zero(void) {
+
+        soundspeed_obj * obj;
+
+        obj = (soundspeed_obj *) malloc(sizeof(soundspeed_obj));
+
+        obj->mu = 0.0f;
+        obj->sigma2 = 0.0f;
+
+        return obj;
+
+    }
+
+    // +----------------------------------------------------------+
+    // | Clone                                                    |
+    // +----------------------------------------------------------+
+
+    soundspeed_obj * soundspeed_clone(const soundspeed_obj * obj) {
+
+        soundspeed_obj * clone;
+
+        clone = (soundspeed_obj *) malloc(sizeof(soundspeed_obj));
+
+        clone->mu = obj->mu;
+        clone->sigma2 = obj->sigma2;
+
+        return clone;
+
+    }
+
+    // +----------------------------------------------------------+
+    // | Destructor                                               |
+    // +----------------------------------------------------------+
+
+    void soundspeed_destroy(soundspeed_obj * obj) {
+
+        free((void *) obj);
+
+    }
+
+    // +----------------------------------------------------------+
+    // | Print                                                    |
+    // +----------------------------------------------------------+
+
+    void soundspeed_printf(const soundspeed_obj * obj) {
+
+        printf("mu = %f\n",obj->mu);
+        printf("sigma2 = %f\n",obj->sigma2);
+
+    }
\ No newline at end of file
diff --git a/src/general/soundspeed.h b/src/general/soundspeed.h
new file mode 100644 (file)
index 0000000..770a61e
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef __ODAS_GENERAL_SOUNDSPEED
+#define __ODAS_GENERAL_SOUNDSPEED
+
+    #include <stdlib.h>
+    #include <stdio.h>
+
+    typedef struct soundspeed_obj {
+
+        float mu;
+        float sigma2;
+
+    } soundspeed_obj;
+
+    soundspeed_obj * soundspeed_construct_zero(void);
+
+    soundspeed_obj * soundspeed_clone(const soundspeed_obj * obj);
+
+    void soundspeed_destroy(soundspeed_obj * obj);
+
+    void soundspeed_printf(const soundspeed_obj * obj);
+
+#endif
\ No newline at end of file
diff --git a/src/general/thread.c b/src/general/thread.c
new file mode 100644 (file)
index 0000000..9a5822d
--- /dev/null
@@ -0,0 +1,61 @@
+    
+    #include "thread.h"
+
+    thread_obj * thread_construct(void * (* start_routine) (void *), void * arg) {
+
+        thread_obj * obj;
+
+        obj = (thread_obj *) malloc(sizeof(thread_obj));
+
+        pthread_mutex_init(&(obj->use), NULL);
+        obj->stop = 0;
+        obj->start_routine = start_routine;
+        obj->arg = arg;
+
+        return obj;
+
+    }
+
+    void thread_destroy(thread_obj * obj) {
+
+        pthread_mutex_destroy(&(obj->use));
+
+        free((void *) obj);
+
+    }
+
+    void thread_start(thread_obj * obj) {
+
+        pthread_mutex_lock(&(obj->use));
+        obj->stop = 0;
+        pthread_create(&(obj->thread), NULL, obj->start_routine, obj->arg);
+        pthread_mutex_unlock(&(obj->use));
+
+    }
+
+    void thread_stop(thread_obj * obj) {
+
+        pthread_mutex_lock(&(obj->use));
+        obj->stop = 1;
+        pthread_mutex_unlock(&(obj->use));
+
+    }
+
+    char thread_askedToStop(thread_obj * obj) {
+
+        char rtnValue;        
+
+        pthread_mutex_lock(&(obj->use));
+        rtnValue = obj->stop;
+        pthread_mutex_unlock(&(obj->use));
+
+        return rtnValue;        
+
+    }
+
+    void thread_join(thread_obj * obj) {
+
+        pthread_join(obj->thread, NULL);
+
+    }
+    
\ No newline at end of file
diff --git a/src/general/thread.h b/src/general/thread.h
new file mode 100644 (file)
index 0000000..328c4aa
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef __ODAS_GENERAL_THREAD
+#define __ODAS_GENERAL_THREAD
+
+    #include <stdlib.h>
+    #include <stdio.h>
+    #include <pthread.h>
+
+    typedef struct thread_obj {
+
+        pthread_mutex_t use;
+        char stop;
+        pthread_t thread;   
+        void * (* start_routine) (void *);
+        void * arg;     
+
+    } thread_obj;
+
+    thread_obj * thread_construct(void * (* start_routine) (void *), void * arg);
+
+    void thread_destroy(thread_obj * obj);
+
+    void thread_start(thread_obj * obj);
+
+    void thread_stop(thread_obj * obj);
+
+    char thread_askedToStop(thread_obj * obj);
+
+    void thread_join(thread_obj * obj); 
+
+#endif
\ No newline at end of file