From fc27389227cf30fdf7e658fc33da56f621668079 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 20 Sep 2014 14:07:32 +0200 Subject: Change to 16KHz audio input. A vague attempt at error handling (read crash prevention). --- src/opusencoder.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/opusencoder.cc') 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 #include +// 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; -- cgit v1.2.3