diff options
author | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2012-12-21 08:11:53 +0400 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2012-12-21 08:11:53 +0400 |
commit | 5e0e85bcb9722de5a8a982dbcf8dbe7dc7583a5e (patch) | |
tree | 36d6d7cd47d27764f25f8198f3c988b467272a7d | |
parent | b2466175ec3b35d2e4718b331bf22e2282b73abc (diff) |
Capping lsb_depth to 16 unless using the float API of a float build
-rw-r--r-- | src/opus_encoder.c | 35 | ||||
-rw-r--r-- | src/opus_multistream_encoder.c | 18 | ||||
-rw-r--r-- | src/opus_private.h | 3 |
3 files changed, 31 insertions, 25 deletions
diff --git a/src/opus_encoder.c b/src/opus_encoder.c index 5199d664..705e57e4 100644 --- a/src/opus_encoder.c +++ b/src/opus_encoder.c @@ -534,15 +534,8 @@ static opus_int32 user_bitrate_to_bitrate(OpusEncoder *st, int frame_size, int m return st->user_bitrate_bps; } -#ifdef FIXED_POINT -#define opus_encode_native opus_encode -opus_int32 opus_encode(OpusEncoder *st, const opus_val16 *pcm, int frame_size, - unsigned char *data, opus_int32 out_data_bytes) -#else -#define opus_encode_native opus_encode_float -opus_int32 opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size, - unsigned char *data, opus_int32 out_data_bytes) -#endif +opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size, + unsigned char *data, opus_int32 out_data_bytes, int lsb_depth) { void *silk_enc; CELTEncoder *celt_enc; @@ -595,6 +588,8 @@ opus_int32 opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_s silk_enc = (char*)st+st->silk_enc_offset; celt_enc = (CELTEncoder*)((char*)st+st->celt_enc_offset); + lsb_depth = IMIN(lsb_depth, st->lsb_depth); + #ifndef FIXED_POINT perform_analysis = st->silk_mode.complexity >= 7 && frame_size >= st->Fs/100 && st->Fs==48000; #endif @@ -867,7 +862,7 @@ opus_int32 opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_s st->bandwidth = IMIN(st->bandwidth, analysis_info.opus_bandwidth); } #endif - celt_encoder_ctl(celt_enc, OPUS_SET_LSB_DEPTH(st->lsb_depth)); + celt_encoder_ctl(celt_enc, OPUS_SET_LSB_DEPTH(lsb_depth)); /* If max_data_bytes represents less than 8 kb/s, switch to CELT-only mode */ if (max_data_bytes < (frame_rate > 50 ? 12000 : 8000)*frame_size / (st->Fs * 8)) @@ -914,7 +909,7 @@ opus_int32 opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_s /* When switching from SILK/Hybrid to CELT, only ask for a switch at the last frame */ if (to_celt && i==nb_frames-1) st->user_forced_mode = MODE_CELT_ONLY; - tmp_len = opus_encode_native(st, pcm+i*(st->channels*st->Fs/50), st->Fs/50, tmp_data+i*bytes_per_frame, bytes_per_frame); + tmp_len = opus_encode_native(st, pcm+i*(st->channels*st->Fs/50), st->Fs/50, tmp_data+i*bytes_per_frame, bytes_per_frame, lsb_depth); if (tmp_len<0) { RESTORE_STACK; @@ -985,7 +980,7 @@ opus_int32 opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_s int nb_analysis_frames; nb_analysis_frames = frame_size/(st->Fs/100); for (i=0;i<nb_analysis_frames;i++) - tonality_analysis(&st->analysis, &analysis_info, celt_enc, pcm_buf+i*(st->Fs/100)*st->channels, st->channels, st->lsb_depth); + tonality_analysis(&st->analysis, &analysis_info, celt_enc, pcm_buf+i*(st->Fs/100)*st->channels, st->channels, lsb_depth); if (st->signal_type == OPUS_AUTO) st->voice_ratio = (int)floor(.5+100*(1-analysis_info.music_prob)); } else { @@ -1432,12 +1427,18 @@ opus_int32 opus_encode_float(OpusEncoder *st, const float *pcm, int frame_size, for (i=0;i<frame_size*st->channels;i++) in[i] = FLOAT2INT16(pcm[i]); - ret = opus_encode(st, in, frame_size, data, max_data_bytes); + ret = opus_encode_native(st, in, frame_size, data, max_data_bytes, 16); RESTORE_STACK; return ret; } #endif +opus_int32 opus_encode(OpusEncoder *st, const opus_int16 *pcm, int frame_size, + unsigned char *data, opus_int32 out_data_bytes) +{ + return opus_encode_native(st, pcm, frame_size, data, out_data_bytes, 16); +} + #else opus_int32 opus_encode(OpusEncoder *st, const opus_int16 *pcm, int frame_size, unsigned char *data, opus_int32 max_data_bytes) @@ -1450,10 +1451,16 @@ opus_int32 opus_encode(OpusEncoder *st, const opus_int16 *pcm, int frame_size, for (i=0;i<frame_size*st->channels;i++) in[i] = (1.0f/32768)*pcm[i]; - ret = opus_encode_float(st, in, frame_size, data, max_data_bytes); + ret = opus_encode_native(st, in, frame_size, data, max_data_bytes, 16); RESTORE_STACK; return ret; } +opus_int32 opus_encode_float(OpusEncoder *st, const float *pcm, int frame_size, + unsigned char *data, opus_int32 out_data_bytes) +{ + return opus_encode_native(st, pcm, frame_size, data, out_data_bytes, 24); + +} #endif diff --git a/src/opus_multistream_encoder.c b/src/opus_multistream_encoder.c index c5f37a0e..db9fc785 100644 --- a/src/opus_multistream_encoder.c +++ b/src/opus_multistream_encoder.c @@ -43,11 +43,6 @@ struct OpusMSEncoder { /* Encoder states go here */ }; -#ifdef FIXED_POINT -#define opus_encode_native opus_encode -#else -#define opus_encode_native opus_encode_float -#endif static int validate_encoder_layout(const ChannelLayout *layout) { @@ -185,7 +180,8 @@ static int opus_multistream_encode_native const void *pcm, int frame_size, unsigned char *data, - opus_int32 max_data_bytes + opus_int32 max_data_bytes, + int lsb_depth ) { opus_int32 Fs; @@ -250,7 +246,7 @@ static int opus_multistream_encode_native /* Reserve three bytes for the last stream and four for the others */ curr_max -= IMAX(0,4*(st->layout.nb_streams-s-1)-1); curr_max = IMIN(curr_max,MS_FRAME_TMP); - len = opus_encode_native(enc, buf, frame_size, tmp_data, curr_max); + len = opus_encode_native(enc, buf, frame_size, tmp_data, curr_max, lsb_depth); if (len<0) { RESTORE_STACK; @@ -321,7 +317,7 @@ int opus_multistream_encode( ) { return opus_multistream_encode_native(st, opus_copy_channel_in_short, - pcm, frame_size, data, max_data_bytes); + pcm, frame_size, data, max_data_bytes, 16); } #ifndef DISABLE_FLOAT_API @@ -334,7 +330,7 @@ int opus_multistream_encode_float( ) { return opus_multistream_encode_native(st, opus_copy_channel_in_float, - pcm, frame_size, data, max_data_bytes); + pcm, frame_size, data, max_data_bytes, 16); } #endif @@ -350,7 +346,7 @@ int opus_multistream_encode_float ) { return opus_multistream_encode_native(st, opus_copy_channel_in_float, - pcm, frame_size, data, max_data_bytes); + pcm, frame_size, data, max_data_bytes, 24); } int opus_multistream_encode( @@ -362,7 +358,7 @@ int opus_multistream_encode( ) { return opus_multistream_encode_native(st, opus_copy_channel_in_short, - pcm, frame_size, data, max_data_bytes); + pcm, frame_size, data, max_data_bytes, 16); } #endif diff --git a/src/opus_private.h b/src/opus_private.h index 1362073c..977f4a25 100644 --- a/src/opus_private.h +++ b/src/opus_private.h @@ -84,6 +84,9 @@ int get_mono_channel(const ChannelLayout *layout, int stream_id, int prev); int encode_size(int size, unsigned char *data); +opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size, + unsigned char *data, opus_int32 out_data_bytes, int lsb_depth); + int opus_decode_native(OpusDecoder *st, const unsigned char *data, opus_int32 len, opus_val16 *pcm, int frame_size, int decode_fec, int self_delimited, int *packet_offset); |