summaryrefslogtreecommitdiff
path: root/src/opusencoder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/opusencoder.cc')
-rw-r--r--src/opusencoder.cc20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/opusencoder.cc b/src/opusencoder.cc
index b5c343a..27bdb90 100644
--- a/src/opusencoder.cc
+++ b/src/opusencoder.cc
@@ -29,19 +29,21 @@
#include <string.h>
#include <stdio.h>
+// 500 to 512000
#define OPUS_BITRATE 64000
+// Frame size 10ms
+#define OPUS_FRAME_SIZE 10
+
OpusEncoder::OpusEncoder()
: cache(5760 * 10)
{
- int error = 0;
- encoder =
- opus_encoder_create(48000, 1, OPUS_APPLICATION_AUDIO, &error);
- if(!encoder || error != OPUS_OK) {
- printf("opus_encoder_create: %d\n", error);
+ int err = 0;
+ encoder = opus_encoder_create(16000, 1, OPUS_APPLICATION_AUDIO, &err);
+ if(!encoder || err != OPUS_OK) {
+ printf("opus_encoder_create: %d\n", err);
}
- // 500 to 512000
opus_encoder_ctl(encoder, OPUS_SET_BITRATE(OPUS_BITRATE));
// [0-10] with 10 representing the highest complexity.
@@ -55,7 +57,7 @@ OpusEncoder::~OpusEncoder()
unsigned int OpusEncoder::framesize()
{
- return 48000 / 1000 * OPUS_FRAME_SIZE; // 10ms audio data
+ return 16000 / 1000 * OPUS_FRAME_SIZE; // 10ms audio data
}
framelist_t OpusEncoder::encode(const char *pcm, size_t size)
@@ -67,7 +69,7 @@ framelist_t OpusEncoder::encode(const char *pcm, size_t size)
printf("encoder == NULL\n");
}
- size_t bytes_per_packet = ((OPUS_BITRATE *framesize())/48000+4)/8;
+ size_t bytes_per_packet = ((OPUS_BITRATE *framesize())/16000+4)/8;
cache.addSamples((short*)pcm, size / sizeof(short));
@@ -82,7 +84,7 @@ framelist_t OpusEncoder::encode(const char *pcm, size_t size)
(unsigned char *)frame->data, (opus_int32)frame->size);
if(n < 0) {
- printf("n < 0\n");
+ printf("opus_encode: %d\n", n);
}
frame->size = n;