diff options
| author | drowe67 <[email protected]> | 2023-07-14 12:36:50 +0930 |
|---|---|---|
| committer | David Rowe <[email protected]> | 2023-07-14 12:36:50 +0930 |
| commit | b86e88413d4c6ec428aaedb147f7675f28882fe4 (patch) | |
| tree | ce360925856e25d4343d59a37e2e6bac142d3752 /src/codec2_fifo.c | |
| parent | 0c2e969cfbe85548801eeb20ad8113969604892a (diff) | |
clang-format -i applied to src unittest misc
Diffstat (limited to 'src/codec2_fifo.c')
| -rw-r--r-- | src/codec2_fifo.c | 164 |
1 files changed, 78 insertions, 86 deletions
diff --git a/src/codec2_fifo.c b/src/codec2_fifo.c index 5ac667e..55d8b26 100644 --- a/src/codec2_fifo.c +++ b/src/codec2_fifo.c @@ -29,122 +29,114 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. */ +#include "codec2_fifo.h" + #include <assert.h> -#include <stdlib.h> #include <stdio.h> -#include "codec2_fifo.h" +#include <stdlib.h> struct FIFO { - short *buf; - short *pin; - short *pout; - int nshort; + short *buf; + short *pin; + short *pout; + int nshort; }; // standard create function struct FIFO *codec2_fifo_create(int nshort) { - short *buf = (short*)malloc(sizeof(short)*nshort); - assert(buf != NULL); - return codec2_fifo_create_buf(nshort, buf); + short *buf = (short *)malloc(sizeof(short) * nshort); + assert(buf != NULL); + return codec2_fifo_create_buf(nshort, buf); } // alternate create function where buffer is externally supplied -struct FIFO *codec2_fifo_create_buf(int nshort, short* buf) { - struct FIFO *fifo; - assert(buf != NULL); - fifo = (struct FIFO *)malloc(sizeof(struct FIFO)); - assert(fifo != NULL); - - fifo->buf = buf; - fifo->pin = fifo->buf; - fifo->pout = fifo->buf; - fifo->nshort = nshort; - - return fifo; +struct FIFO *codec2_fifo_create_buf(int nshort, short *buf) { + struct FIFO *fifo; + assert(buf != NULL); + fifo = (struct FIFO *)malloc(sizeof(struct FIFO)); + assert(fifo != NULL); + + fifo->buf = buf; + fifo->pin = fifo->buf; + fifo->pout = fifo->buf; + fifo->nshort = nshort; + + return fifo; } void codec2_fifo_destroy(struct FIFO *fifo) { - assert(fifo != NULL); - free(fifo->buf); - free(fifo); + assert(fifo != NULL); + free(fifo->buf); + free(fifo); } int codec2_fifo_write(struct FIFO *fifo, short data[], int n) { - int i; - short *pdata; - short *pin = fifo->pin; - - assert(fifo != NULL); - assert(data != NULL); - - if (n > codec2_fifo_free(fifo)) { - return -1; - } - else { - - /* This could be made more efficient with block copies - using memcpy */ - - pdata = data; - for(i=0; i<n; i++) { - *pin++ = *pdata++; - if (pin == (fifo->buf + fifo->nshort)) - pin = fifo->buf; - } - fifo->pin = pin; + int i; + short *pdata; + short *pin = fifo->pin; + + assert(fifo != NULL); + assert(data != NULL); + + if (n > codec2_fifo_free(fifo)) { + return -1; + } else { + /* This could be made more efficient with block copies + using memcpy */ + + pdata = data; + for (i = 0; i < n; i++) { + *pin++ = *pdata++; + if (pin == (fifo->buf + fifo->nshort)) pin = fifo->buf; } + fifo->pin = pin; + } - return 0; + return 0; } -int codec2_fifo_read(struct FIFO *fifo, short data[], int n) -{ - int i; - short *pdata; - short *pout = fifo->pout; +int codec2_fifo_read(struct FIFO *fifo, short data[], int n) { + int i; + short *pdata; + short *pout = fifo->pout; - assert(fifo != NULL); - assert(data != NULL); + assert(fifo != NULL); + assert(data != NULL); - if (n > codec2_fifo_used(fifo)) { - return -1; - } - else { - - /* This could be made more efficient with block copies - using memcpy */ - - pdata = data; - for(i=0; i<n; i++) { - *pdata++ = *pout++; - if (pout == (fifo->buf + fifo->nshort)) - pout = fifo->buf; - } - fifo->pout = pout; + if (n > codec2_fifo_used(fifo)) { + return -1; + } else { + /* This could be made more efficient with block copies + using memcpy */ + + pdata = data; + for (i = 0; i < n; i++) { + *pdata++ = *pout++; + if (pout == (fifo->buf + fifo->nshort)) pout = fifo->buf; } + fifo->pout = pout; + } - return 0; + return 0; } -int codec2_fifo_used(const struct FIFO * const fifo) -{ - short *pin = fifo->pin; - short *pout = fifo->pout; - unsigned int used; +int codec2_fifo_used(const struct FIFO *const fifo) { + short *pin = fifo->pin; + short *pout = fifo->pout; + unsigned int used; - assert(fifo != NULL); - if (pin >= pout) - used = pin - pout; - else - used = fifo->nshort + (unsigned int)(pin - pout); + assert(fifo != NULL); + if (pin >= pout) + used = pin - pout; + else + used = fifo->nshort + (unsigned int)(pin - pout); - return used; + return used; } -int codec2_fifo_free(const struct FIFO * const fifo) -{ - // available storage is one less than nshort as prd == pwr - // is reserved for empty rather than full +int codec2_fifo_free(const struct FIFO *const fifo) { + // available storage is one less than nshort as prd == pwr + // is reserved for empty rather than full - return fifo->nshort - codec2_fifo_used(fifo) - 1; + return fifo->nshort - codec2_fifo_used(fifo) - 1; } |
