summaryrefslogtreecommitdiff
path: root/modules/opus
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2018-01-06 16:20:25 +0100
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2018-01-06 16:20:25 +0100
commit96b9b6c0d94606b346bc67b5ce78bb20f2e28769 (patch)
treef4b56a89140cd593a913e1d39f2dc3822f63570c /modules/opus
parent4d6e0dfbad11b6d8f65d15ac5a1743cc8d2afc4d (diff)
audio: sample format for audio encoder/decoder
config: auenc_format s16 # s16, float audec_format s16 # s16, float modules: only opus module supports this for now. default is s16
Diffstat (limited to 'modules/opus')
-rw-r--r--modules/opus/decode.c25
-rw-r--r--modules/opus/encode.c25
-rw-r--r--modules/opus/opus.c2
-rw-r--r--modules/opus/opus.h5
4 files changed, 57 insertions, 0 deletions
diff --git a/modules/opus/decode.c b/modules/opus/decode.c
index f2d67b1..a09f2ff 100644
--- a/modules/opus/decode.c
+++ b/modules/opus/decode.c
@@ -5,6 +5,7 @@
*/
#include <re.h>
+#include <rem.h>
#include <baresip.h>
#include <opus/opus.h>
#include "opus.h"
@@ -84,6 +85,30 @@ int opus_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc,
}
+int opus_decode_format_frm(struct audec_state *ads,
+ int fmt, void *sampv, size_t *sampc,
+ const uint8_t *buf, size_t len)
+{
+ int n;
+
+ if (!ads || !sampv || !sampc || !buf)
+ return EINVAL;
+ if (fmt != AUFMT_FLOAT)
+ return ENOTSUP;
+
+ n = opus_decode_float(ads->dec, buf, (opus_int32)len,
+ sampv, (int)(*sampc/ads->ch), 0);
+ if (n < 0) {
+ warning("opus: decode error: %s\n", opus_strerror(n));
+ return EPROTO;
+ }
+
+ *sampc = n * ads->ch;
+
+ return 0;
+}
+
+
int opus_decode_pkloss(struct audec_state *ads, int16_t *sampv, size_t *sampc)
{
int n;
diff --git a/modules/opus/encode.c b/modules/opus/encode.c
index 6723ac8..7450d92 100644
--- a/modules/opus/encode.c
+++ b/modules/opus/encode.c
@@ -5,6 +5,7 @@
*/
#include <re.h>
+#include <rem.h>
#include <baresip.h>
#include <opus/opus.h>
#include "opus.h"
@@ -189,3 +190,27 @@ int opus_encode_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
return 0;
}
+
+
+int opus_encode_format_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
+ int fmt, const void *sampv, size_t sampc)
+{
+ opus_int32 n;
+
+ if (!aes || !buf || !len || !sampv)
+ return EINVAL;
+
+ if (fmt != AUFMT_FLOAT)
+ return ENOTSUP;
+
+ n = opus_encode_float(aes->enc, sampv, (int)(sampc/aes->ch),
+ buf, (opus_int32)(*len));
+ if (n < 0) {
+ warning("opus: encode error: %s\n", opus_strerror((int)n));
+ return EPROTO;
+ }
+
+ *len = n;
+
+ return 0;
+}
diff --git a/modules/opus/opus.c b/modules/opus/opus.c
index 7acccec..8346680 100644
--- a/modules/opus/opus.c
+++ b/modules/opus/opus.c
@@ -69,6 +69,8 @@ static struct aucodec opus = {
.decupdh = opus_decode_update,
.dech = opus_decode_frm,
.plch = opus_decode_pkloss,
+ .encfmth = opus_encode_format_frm,
+ .decfmth = opus_decode_format_frm,
};
diff --git a/modules/opus/opus.h b/modules/opus/opus.h
index d521652..9e79bd5 100644
--- a/modules/opus/opus.h
+++ b/modules/opus/opus.h
@@ -20,6 +20,8 @@ int opus_encode_update(struct auenc_state **aesp, const struct aucodec *ac,
struct auenc_param *prm, const char *fmtp);
int opus_encode_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
const int16_t *sampv, size_t sampc);
+int opus_encode_format_frm(struct auenc_state *aes, uint8_t *buf, size_t *len,
+ int fmt, const void *sampv, size_t sampc);
/* Decode */
@@ -27,6 +29,9 @@ int opus_decode_update(struct audec_state **adsp, const struct aucodec *ac,
const char *fmtp);
int opus_decode_frm(struct audec_state *ads, int16_t *sampv, size_t *sampc,
const uint8_t *buf, size_t len);
+int opus_decode_format_frm(struct audec_state *ads,
+ int fmt, void *sampv, size_t *sampc,
+ const uint8_t *buf, size_t len);
int opus_decode_pkloss(struct audec_state *st, int16_t *sampv, size_t *sampc);