Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/opus_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ extern "C" {
#define OPUS_GET_QEXT_REQUEST 4057
#define OPUS_SET_IGNORE_EXTENSIONS_REQUEST 4058
#define OPUS_GET_IGNORE_EXTENSIONS_REQUEST 4059
#define OPUS_SET_DC_FILTER_REQUEST 4060
#define OPUS_GET_DC_FILTER_REQUEST 4061

/** Defines for the presence of extended APIs. */
#define OPUS_HAVE_OPUS_PROJECTION_H
Expand Down Expand Up @@ -662,6 +664,14 @@ extern "C" {
* @hideinitializer */
#define OPUS_GET_QEXT(x) OPUS_GET_QEXT_REQUEST, __opus_check_int_ptr(x)

/** Configures the encoder's use of dc_reject filter.
* @hideinitializer */
#define OPUS_SET_DC_FILTER(x) OPUS_SET_DC_FILTER_REQUEST, __opus_check_int(x)
/** Gets the encoder's configured dc_reject filter status.
* @hideinitializer */
#define OPUS_GET_DC_FILTER(x) OPUS_GET_DC_FILTER_REQUEST, __opus_check_int(x)


/**@}*/

/** @defgroup opus_genericctls Generic CTLs
Expand Down
8 changes: 8 additions & 0 deletions src/opus_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ void print_usage( char* argv[] )
fprintf(stderr, "-d : only runs the decoder (reads the bit-stream as input)\n" );
fprintf(stderr, "-cbr : enable constant bitrate; default: variable bitrate\n" );
fprintf(stderr, "-cvbr : enable constrained variable bitrate; default: unconstrained\n" );
fprintf(stderr, "-dc_filter : enable dc reject filter; default: false\n" );
fprintf(stderr, "-delayed-decision : use look-ahead for speech/music detection (experts only); default: disabled\n" );
fprintf(stderr, "-bandwidth <NB|MB|WB|SWB|FB> : audio bandwidth (from narrowband to fullband); default: sampling rate\n" );
fprintf(stderr, "-framesize <2.5|5|10|20|40|60|80|100|120> : frame size in ms; default: 20 \n" );
Expand Down Expand Up @@ -389,6 +390,7 @@ int main(int argc, char *argv[])
unsigned char *fbytes=NULL;
opus_int32 sampling_rate;
int use_vbr;
int dc_filter;
int max_payload_bytes;
int complexity;
int dec_complexity;
Expand Down Expand Up @@ -533,6 +535,7 @@ int main(int argc, char *argv[])

/* defaults: */
use_vbr = 1;
dc_filter = 0;
max_payload_bytes = MAX_PACKET;
complexity = 10;
dec_complexity = 0;
Expand All @@ -547,6 +550,10 @@ int main(int argc, char *argv[])
check_encoder_option(decode_only, "-cbr");
use_vbr = 0;
args++;
} else if ( strcmp( argv[ args ], "-dc_filter" ) == 0 ) {
check_encoder_option(decode_only, "-dc_filter");
dc_filter = 1;
++args;
} else if( strcmp( argv[ args ], "-bandwidth" ) == 0 ) {
check_encoder_option(decode_only, "-bandwidth");
if (strcmp(argv[ args + 1 ], "NB")==0)
Expand Down Expand Up @@ -782,6 +789,7 @@ int main(int argc, char *argv[])
opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate_bps));
opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(bandwidth));
opus_encoder_ctl(enc, OPUS_SET_VBR(use_vbr));
opus_encoder_ctl(enc, OPUS_SET_DC_FILTER(dc_filter));
opus_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(cvbr));
opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity));
opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC(use_inbandfec));
Expand Down
33 changes: 29 additions & 4 deletions src/opus_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ struct OpusEncoder {
#endif
int nonfinal_frame; /* current frame is not the final in a packet */
opus_uint32 rangeFinal;
int dc_filter;
};

/* Transition tables for the voice and music. First column is the
Expand Down Expand Up @@ -298,6 +299,7 @@ int opus_encoder_init(OpusEncoder* st, opus_int32 Fs, int channels, int applicat
st->first = 1;
st->mode = MODE_HYBRID;
st->bandwidth = OPUS_BANDWIDTH_FULLBAND;
st->dc_filter = 0;

#ifndef DISABLE_FLOAT_API
tonality_analysis_init(&st->analysis, st->Fs);
Expand Down Expand Up @@ -1923,13 +1925,16 @@ static opus_int32 opus_encode_frame_native(OpusEncoder *st, const opus_res *pcm,
}
}
#endif
} else {
#ifdef ENABLE_QEXT
/* FIXME: Avoid glitching when we switch qext on/off dynamically. */
if (st->enable_qext) OPUS_COPY(&pcm_buf[total_buffer*st->channels], pcm, frame_size*st->channels);
else
/* FIXME: Avoid glitching when we switch qext on/off dynamically. */
} else if (st->dc_filter && !st->enable_qext) {
#else
/* FIXME: Avoid glitching when we switch dc_filter on/off dynamically. */
} else if (st->dc_filter) {
#endif
dc_reject(pcm, 3, &pcm_buf[total_buffer*st->channels], st->hp_mem, frame_size, st->channels, st->Fs);
} else {
OPUS_COPY(&pcm_buf[total_buffer*st->channels], pcm, frame_size*st->channels);
}
#ifndef FIXED_POINT
if (float_api)
Expand Down Expand Up @@ -2920,6 +2925,26 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
*value = st->use_vbr;
}
break;
case OPUS_SET_DC_FILTER_REQUEST:
{
opus_int32 value = va_arg(ap, opus_int32);
if(value<0 || value>1)
{
goto bad_arg;
}
st->dc_filter = value;
}
break;
case OPUS_GET_DC_FILTER_REQUEST:
{
opus_int32 *value = va_arg(ap, opus_int32*);
if (!value)
{
goto bad_arg;
}
*value = st->dc_filter;
}
break;
case OPUS_SET_VOICE_RATIO_REQUEST:
{
opus_int32 value = va_arg(ap, opus_int32);
Expand Down
2 changes: 2 additions & 0 deletions src/opus_multistream_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,7 @@ int opus_multistream_encoder_ctl_va_list(OpusMSEncoder *st, int request,
case OPUS_GET_PREDICTION_DISABLED_REQUEST:
case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST:
case OPUS_GET_QEXT_REQUEST:
case OPUS_GET_DC_FILTER_REQUEST:
{
OpusEncoder *enc;
/* For int32* GET params, just query the first stream */
Expand Down Expand Up @@ -1225,6 +1226,7 @@ int opus_multistream_encoder_ctl_va_list(OpusMSEncoder *st, int request,
case OPUS_SET_PREDICTION_DISABLED_REQUEST:
case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST:
case OPUS_SET_QEXT_REQUEST:
case OPUS_SET_DC_FILTER_REQUEST:
{
int s;
/* This works for int32 params */
Expand Down