From 663a7fe938b3e211ecef57966a14df0d1c9a03f5 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Tue, 6 Sep 2011 14:05:19 -0400 Subject: [PATCH] Defining OPUS_BITRATE_MAX and moving some defines to opus_defines.h --- libcelt/celt.c | 8 ++++---- libcelt/opus_defines.h | 19 ++++++++++++++++++- src/opus.h | 15 --------------- src/opus_encoder.c | 6 ++++-- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/libcelt/celt.c b/libcelt/celt.c index eab5e64c7..28fc03ba0 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -250,7 +250,7 @@ int opus_custom_encoder_init(CELTEncoder *st, const CELTMode *mode, int channels st->constrained_vbr = 1; st->clip = 1; - st->bitrate = -1; + st->bitrate = OPUS_BITRATE_MAX; st->vbr = 0; st->vbr_offset = 0; st->force_intra = 0; @@ -970,7 +970,7 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f nbCompressedBytes = IMIN(nbCompressedBytes,1275); nbAvailableBytes = nbCompressedBytes - nbFilledBytes; - if (st->vbr && st->bitrate!=-1) + if (st->vbr && st->bitrate!=OPUS_BITRATE_MAX) { opus_int32 den=st->mode->Fs>>BITRES; vbr_rate=(st->bitrate*frame_size+(den>>1))/den; @@ -983,7 +983,7 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f tmp = st->bitrate*frame_size; if (tell>1) tmp += tell; - if (st->bitrate!=-1) + if (st->bitrate!=OPUS_BITRATE_MAX) nbCompressedBytes = IMAX(2, IMIN(nbCompressedBytes, (tmp+4*st->mode->Fs)/(8*st->mode->Fs)-!!st->signalling)); effectiveBytes = nbCompressedBytes; @@ -1783,7 +1783,7 @@ int opus_custom_encoder_ctl(CELTEncoder * restrict st, int request, ...) case OPUS_SET_BITRATE_REQUEST: { opus_int32 value = va_arg(ap, opus_int32); - if (value<=500 && value!=-1) + if (value<=500 && value!=OPUS_BITRATE_MAX) goto bad_arg; value = IMIN(value, 260000*st->channels); st->bitrate = value; diff --git a/libcelt/opus_defines.h b/libcelt/opus_defines.h index 1c0726236..21c9e4d6c 100644 --- a/libcelt/opus_defines.h +++ b/libcelt/opus_defines.h @@ -75,6 +75,23 @@ extern "C" { #define OPUS_ALLOC_FAIL -7 +#define OPUS_BITRATE_AUTO -2 +#define OPUS_BITRATE_MAX -1 + +#define OPUS_APPLICATION_VOIP 2000 +#define OPUS_APPLICATION_AUDIO 2001 + +#define OPUS_SIGNAL_AUTO 3000 +#define OPUS_SIGNAL_VOICE 3001 +#define OPUS_SIGNAL_MUSIC 3002 + +#define OPUS_BANDWIDTH_AUTO 1100 +#define OPUS_BANDWIDTH_NARROWBAND 1101 +#define OPUS_BANDWIDTH_MEDIUMBAND 1102 +#define OPUS_BANDWIDTH_WIDEBAND 1103 +#define OPUS_BANDWIDTH_SUPERWIDEBAND 1104 +#define OPUS_BANDWIDTH_FULLBAND 1105 + /* OPUS_APPLICATION_VOIP or OPUS_APPLICATION_AUDIO */ #define OPUS_SET_APPLICATION_REQUEST 4000 @@ -146,7 +163,7 @@ extern "C" { /* For testing purposes: the encoder and decoder state should always be identical after coding a payload */ -#define OPUS_GET_FINAL_RANGE_REQUEST 29 +#define OPUS_GET_FINAL_RANGE_REQUEST 4031 #define OPUS_GET_FINAL_RANGE(x) OPUS_GET_FINAL_RANGE_REQUEST, __opus_check_uint_ptr(x) diff --git a/src/opus.h b/src/opus.h index 810a88f2f..38418b414 100644 --- a/src/opus.h +++ b/src/opus.h @@ -36,21 +36,6 @@ extern "C" { #endif -#define OPUS_BITRATE_AUTO -1 - -#define OPUS_APPLICATION_VOIP 2000 -#define OPUS_APPLICATION_AUDIO 2001 - -#define OPUS_SIGNAL_AUTO 3000 -#define OPUS_SIGNAL_VOICE 3001 -#define OPUS_SIGNAL_MUSIC 3002 - -#define OPUS_BANDWIDTH_AUTO 1100 -#define OPUS_BANDWIDTH_NARROWBAND 1101 -#define OPUS_BANDWIDTH_MEDIUMBAND 1102 -#define OPUS_BANDWIDTH_WIDEBAND 1103 -#define OPUS_BANDWIDTH_SUPERWIDEBAND 1104 -#define OPUS_BANDWIDTH_FULLBAND 1105 diff --git a/src/opus_encoder.c b/src/opus_encoder.c index 00f8a1cd8..6b4702da4 100644 --- a/src/opus_encoder.c +++ b/src/opus_encoder.c @@ -383,6 +383,8 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size, if (st->user_bitrate_bps==OPUS_BITRATE_AUTO) st->bitrate_bps = 60*st->Fs/frame_size + st->Fs*st->channels; + else if (st->user_bitrate_bps==OPUS_BITRATE_MAX) + st->bitrate_bps = max_data_bytes*8*st->Fs/frame_size; else st->bitrate_bps = st->user_bitrate_bps; @@ -718,7 +720,7 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size, if (st->mode != MODE_SILK_ONLY) { celt_encoder_ctl(celt_enc, OPUS_SET_VBR(0)); - celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(-1)); + celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(OPUS_BITRATE_MAX)); if (st->prev_mode == MODE_SILK_ONLY) { unsigned char dummy[10]; @@ -948,7 +950,7 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...) case OPUS_SET_BITRATE_REQUEST: { opus_int32 value = va_arg(ap, opus_int32); - if (value != OPUS_BITRATE_AUTO) + if (value != OPUS_BITRATE_AUTO && value != OPUS_BITRATE_MAX) { if (value <= 0) goto bad_arg; -- GitLab