diff options
author | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2018-02-03 18:32:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-03 18:32:38 +0100 |
commit | 74db759ddbed32127ae763ab72be552cff2aebcc (patch) | |
tree | 123ceaaf86cf06a211d8dc29a97007f36cdaa236 /modules/l16/l16.c | |
parent | 671f293bbdf8f234a73d8c2e6fb75a8ee3d039ce (diff) |
Aucodec sample format (#352)
* aucodec: merge s16 and fmt encode/decode into one
having 2 different encode functions for s16 and other formats
turned out to be a bit impractical. better to have 1 function
where the sample format (fmt) can be specified.
* update some aucodec modules
* update test
* update codec2
* update g7221 module
Diffstat (limited to 'modules/l16/l16.c')
-rw-r--r-- | modules/l16/l16.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/modules/l16/l16.c b/modules/l16/l16.c index ce131a0..3f324c9 100644 --- a/modules/l16/l16.c +++ b/modules/l16/l16.c @@ -4,6 +4,7 @@ * Copyright (C) 2010 - 2015 Creytiv.com */ #include <re.h> +#include <rem.h> #include <baresip.h> @@ -18,9 +19,10 @@ enum {NR_CODECS = 8}; static int encode(struct auenc_state *st, uint8_t *buf, size_t *len, - const int16_t *sampv, size_t sampc) + int fmt, const void *sampv, size_t sampc) { int16_t *p = (void *)buf; + const int16_t *sampv16 = sampv; (void)st; if (!buf || !len || !sampv) @@ -29,19 +31,23 @@ static int encode(struct auenc_state *st, uint8_t *buf, size_t *len, if (*len < sampc*2) return ENOMEM; + if (fmt != AUFMT_S16LE) + return ENOTSUP; + *len = sampc*2; while (sampc--) - *p++ = htons(*sampv++); + *p++ = htons(*sampv16++); return 0; } -static int decode(struct audec_state *st, int16_t *sampv, size_t *sampc, +static int decode(struct audec_state *st, int fmt, void *sampv, size_t *sampc, const uint8_t *buf, size_t len) { int16_t *p = (void *)buf; + int16_t *sampv16 = sampv; (void)st; if (!buf || !len || !sampv) @@ -50,11 +56,14 @@ static int decode(struct audec_state *st, int16_t *sampv, size_t *sampc, if (*sampc < len/2) return ENOMEM; + if (fmt != AUFMT_S16LE) + return ENOTSUP; + *sampc = len/2; len /= 2; while (len--) - *sampv++ = ntohs(*p++); + *sampv16++ = ntohs(*p++); return 0; } @@ -62,14 +71,14 @@ static int decode(struct audec_state *st, int16_t *sampv, size_t *sampc, /* See RFC 3551 */ static struct aucodec l16v[NR_CODECS] = { -{LE_INIT, "10", "L16", 44100, 44100, 2, 0, 0, encode, 0, decode, 0, 0, 0,0,0}, -{LE_INIT, 0, "L16", 32000, 32000, 2, 0, 0, encode, 0, decode, 0, 0, 0,0,0}, -{LE_INIT, 0, "L16", 16000, 16000, 2, 0, 0, encode, 0, decode, 0, 0, 0,0,0}, -{LE_INIT, 0, "L16", 8000, 8000, 2, 0, 0, encode, 0, decode, 0, 0, 0,0,0}, -{LE_INIT, "11", "L16", 44100, 44100, 1, 0, 0, encode, 0, decode, 0, 0, 0,0,0}, -{LE_INIT, 0, "L16", 32000, 32000, 1, 0, 0, encode, 0, decode, 0, 0, 0,0,0}, -{LE_INIT, 0, "L16", 16000, 16000, 1, 0, 0, encode, 0, decode, 0, 0, 0,0,0}, -{LE_INIT, 0, "L16", 8000, 8000, 1, 0, 0, encode, 0, decode, 0, 0, 0,0,0}, +{LE_INIT, "10", "L16", 44100, 44100, 2, 0, 0, encode, 0, decode, 0, 0, 0}, +{LE_INIT, 0, "L16", 32000, 32000, 2, 0, 0, encode, 0, decode, 0, 0, 0}, +{LE_INIT, 0, "L16", 16000, 16000, 2, 0, 0, encode, 0, decode, 0, 0, 0}, +{LE_INIT, 0, "L16", 8000, 8000, 2, 0, 0, encode, 0, decode, 0, 0, 0}, +{LE_INIT, "11", "L16", 44100, 44100, 1, 0, 0, encode, 0, decode, 0, 0, 0}, +{LE_INIT, 0, "L16", 32000, 32000, 1, 0, 0, encode, 0, decode, 0, 0, 0}, +{LE_INIT, 0, "L16", 16000, 16000, 1, 0, 0, encode, 0, decode, 0, 0, 0}, +{LE_INIT, 0, "L16", 8000, 8000, 1, 0, 0, encode, 0, decode, 0, 0, 0}, }; |