Skip to content
Snippets Groups Projects
Commit 9ba17435 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Implements OPUS_SET_MAX_BANDWIDTH()

parent 9dc0e404
No related branches found
No related tags found
No related merge requests found
......@@ -77,31 +77,34 @@ extern "C" {
/** These are the actual Encoder CTL ID numbers.
* They should not be used directly by applications. */
#define OPUS_SET_COMPLEXITY_REQUEST 4010
#define OPUS_GET_COMPLEXITY_REQUEST 4011
#define OPUS_SET_APPLICATION_REQUEST 4000
#define OPUS_GET_APPLICATION_REQUEST 4001
#define OPUS_SET_BITRATE_REQUEST 4002
#define OPUS_GET_BITRATE_REQUEST 4003
#define OPUS_SET_MAX_BANDWIDTH_REQUEST 4004
#define OPUS_GET_MAX_BANDWIDTH_REQUEST 4005
#define OPUS_SET_VBR_REQUEST 4006
#define OPUS_GET_VBR_REQUEST 4007
#define OPUS_SET_VBR_CONSTRAINT_REQUEST 4020
#define OPUS_GET_VBR_CONSTRAINT_REQUEST 4021
#define OPUS_SET_FORCE_CHANNELS_REQUEST 4022
#define OPUS_GET_FORCE_CHANNELS_REQUEST 4023
#define OPUS_SET_BANDWIDTH_REQUEST 4008
#define OPUS_GET_BANDWIDTH_REQUEST 4009
#define OPUS_SET_SIGNAL_REQUEST 4024
#define OPUS_GET_SIGNAL_REQUEST 4025
#define OPUS_SET_VOICE_RATIO_REQUEST 4018
#define OPUS_GET_VOICE_RATIO_REQUEST 4019
#define OPUS_SET_APPLICATION_REQUEST 4000
#define OPUS_GET_APPLICATION_REQUEST 4001
#define OPUS_GET_LOOKAHEAD_REQUEST 4027
#define OPUS_SET_COMPLEXITY_REQUEST 4010
#define OPUS_GET_COMPLEXITY_REQUEST 4011
#define OPUS_SET_INBAND_FEC_REQUEST 4012
#define OPUS_GET_INBAND_FEC_REQUEST 4013
#define OPUS_SET_PACKET_LOSS_PERC_REQUEST 4014
#define OPUS_GET_PACKET_LOSS_PERC_REQUEST 4015
#define OPUS_SET_DTX_REQUEST 4016
#define OPUS_GET_DTX_REQUEST 4017
#define OPUS_SET_VOICE_RATIO_REQUEST 4018
#define OPUS_GET_VOICE_RATIO_REQUEST 4019
#define OPUS_SET_VBR_CONSTRAINT_REQUEST 4020
#define OPUS_GET_VBR_CONSTRAINT_REQUEST 4021
#define OPUS_SET_FORCE_CHANNELS_REQUEST 4022
#define OPUS_GET_FORCE_CHANNELS_REQUEST 4023
#define OPUS_SET_SIGNAL_REQUEST 4024
#define OPUS_GET_SIGNAL_REQUEST 4025
#define OPUS_GET_LOOKAHEAD_REQUEST 4027
/* #define OPUS_RESET_STATE 4028 */
#define OPUS_GET_FINAL_RANGE_REQUEST 4031
#define OPUS_GET_PITCH_REQUEST 4033
......
......@@ -60,6 +60,7 @@ struct OpusEncoder {
int force_channels;
int signal_type;
int user_bandwidth;
int max_bandwidth;
int user_forced_mode;
int voice_ratio;
opus_int32 Fs;
......@@ -202,6 +203,7 @@ int opus_encoder_init(OpusEncoder* st, opus_int32 Fs, int channels, int applicat
st->application = application;
st->signal_type = OPUS_AUTO;
st->user_bandwidth = OPUS_AUTO;
st->max_bandwidth = OPUS_BANDWIDTH_FULLBAND;
st->force_channels = OPUS_AUTO;
st->user_forced_mode = OPUS_AUTO;
st->voice_ratio = -1;
......@@ -673,6 +675,9 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
st->bandwidth = OPUS_BANDWIDTH_WIDEBAND;
}
if (st->bandwidth>st->max_bandwidth)
st->bandwidth = st->max_bandwidth;
if (st->user_bandwidth != OPUS_AUTO)
st->bandwidth = st->user_bandwidth;
......@@ -1268,6 +1273,27 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
*value = st->force_channels;
}
break;
case OPUS_SET_MAX_BANDWIDTH_REQUEST:
{
opus_int32 value = va_arg(ap, opus_int32);
if (value < OPUS_BANDWIDTH_NARROWBAND || value > OPUS_BANDWIDTH_FULLBAND)
return OPUS_BAD_ARG;
st->max_bandwidth = value;
if (st->max_bandwidth == OPUS_BANDWIDTH_NARROWBAND) {
st->silk_mode.maxInternalSampleRate = 8000;
} else if (st->max_bandwidth == OPUS_BANDWIDTH_MEDIUMBAND) {
st->silk_mode.maxInternalSampleRate = 12000;
} else {
st->silk_mode.maxInternalSampleRate = 16000;
}
}
break;
case OPUS_GET_MAX_BANDWIDTH_REQUEST:
{
opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->max_bandwidth;
}
break;
case OPUS_SET_BANDWIDTH_REQUEST:
{
opus_int32 value = va_arg(ap, opus_int32);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment