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 @@ -175,6 +175,8 @@ extern "C" {
/*#define OPUS_GET_DNN_BLOB_REQUEST 4053 */
#define OPUS_SET_OSCE_BWE_REQUEST 4054
#define OPUS_GET_OSCE_BWE_REQUEST 4055
#define OPUS_SET_DC_FILTER_REQUEST 4056
#define OPUS_GET_DC_FILTER_REQUEST 4057

/** Defines for the presence of extended APIs. */
#define OPUS_HAVE_OPUS_PROJECTION_H
Expand Down Expand Up @@ -650,6 +652,14 @@ extern "C" {
* @hideinitializer */
#define OPUS_SET_DNN_BLOB(data, len) OPUS_SET_DNN_BLOB_REQUEST, __opus_check_void_ptr(data), __opus_check_int(len)

/** 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)


/**@}*/

Expand Down
8 changes: 8 additions & 0 deletions src/opus_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,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 @@ -380,6 +381,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 @@ -512,6 +514,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 @@ -526,6 +529,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 @@ -751,6 +758,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
27 changes: 26 additions & 1 deletion src/opus_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,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 @@ -287,6 +288,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 @@ -1896,8 +1898,11 @@ static opus_int32 opus_encode_frame_native(OpusEncoder *st, const opus_res *pcm,
}
}
#endif
} else {
} else if (st->dc_filter) {
dc_reject(pcm, 3, &pcm_buf[total_buffer*st->channels], st->hp_mem, frame_size, st->channels, st->Fs);
} else {
for (i=0;i<frame_size*st->channels;i++)
pcm_buf[total_buffer*st->channels + i] = pcm[i];
}
#ifndef FIXED_POINT
if (float_api)
Expand Down Expand Up @@ -2868,6 +2873,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