From 74db759ddbed32127ae763ab72be552cff2aebcc Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sat, 3 Feb 2018 18:32:38 +0100 Subject: 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 --- modules/amr/amr.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'modules/amr') diff --git a/modules/amr/amr.c b/modules/amr/amr.c index 885a318..58343a1 100644 --- a/modules/amr/amr.c +++ b/modules/amr/amr.c @@ -16,6 +16,7 @@ #include #endif #include +#include #include #include "amr.h" @@ -205,7 +206,7 @@ static int decode_update(struct audec_state **adsp, #ifdef AMR_WB static int encode_wb(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) { int n; @@ -215,6 +216,9 @@ static int encode_wb(struct auenc_state *st, uint8_t *buf, size_t *len, if (*len < NB_SERIAL_MAX) return ENOMEM; + if (fmt != AUFMT_S16LE) + return ENOTSUP; + /* CMR value 15 indicates that no mode request is present */ buf[0] = 15 << 4; @@ -228,7 +232,8 @@ static int encode_wb(struct auenc_state *st, uint8_t *buf, size_t *len, } -static int decode_wb(struct audec_state *st, int16_t *sampv, size_t *sampc, +static int decode_wb(struct audec_state *st, + int fmt, void *sampv, size_t *sampc, const uint8_t *buf, size_t len) { if (*sampc < L_FRAME16k) @@ -236,6 +241,9 @@ static int decode_wb(struct audec_state *st, int16_t *sampv, size_t *sampc, if (len > NB_SERIAL_MAX) return EINVAL; + if (fmt != AUFMT_S16LE) + return ENOTSUP; + IF2D_IF_decode(st->dec, &buf[1], sampv, 0); *sampc = L_FRAME16k; @@ -247,7 +255,7 @@ static int decode_wb(struct audec_state *st, int16_t *sampv, size_t *sampc, #ifdef AMR_NB static int encode_nb(struct auenc_state *st, uint8_t *buf, - size_t *len, const int16_t *sampv, size_t sampc) + size_t *len, int fmt, const void *sampv, size_t sampc) { int r; @@ -256,6 +264,9 @@ static int encode_nb(struct auenc_state *st, uint8_t *buf, if (*len < NB_SERIAL_MAX) return ENOMEM; + if (fmt != AUFMT_S16LE) + return ENOTSUP; + /* CMR value 15 indicates that no mode request is present */ buf[0] = 15 << 4; @@ -269,7 +280,7 @@ static int encode_nb(struct auenc_state *st, uint8_t *buf, } -static int decode_nb(struct audec_state *st, int16_t *sampv, +static int decode_nb(struct audec_state *st, int fmt, void *sampv, size_t *sampc, const uint8_t *buf, size_t len) { if (!st || !sampv || !sampc || !buf) @@ -281,6 +292,9 @@ static int decode_nb(struct audec_state *st, int16_t *sampv, if (*sampc < L_FRAME16k) return ENOMEM; + if (fmt != AUFMT_S16LE) + return ENOTSUP; + Decoder_Interface_Decode(st->dec, &buf[1], sampv, 0); *sampc = FRAMESIZE_NB; -- cgit v1.2.3