diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2014-09-20 14:07:32 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2014-09-20 14:07:32 +0200 |
commit | fc27389227cf30fdf7e658fc33da56f621668079 (patch) | |
tree | 77ac6e7a3876e10fa335e7bc90556678db1160d0 /src/opusencoder.cc | |
parent | 7251d0e52b8691d33e460ea81213c07aa7d30c22 (diff) |
Change to 16KHz audio input. A vague attempt at error handling (read crash prevention).
Diffstat (limited to 'src/opusencoder.cc')
-rw-r--r-- | src/opusencoder.cc | 20 |
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; |