summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjbuethe <jbuethe@amazon.de>2023-03-07 09:45:15 +0000
committerjbuethe <jbuethe@amazon.de>2023-03-07 09:45:15 +0000
commit6833de48015e73683ca771945d5ca9cc16782e8a (patch)
tree940f844ec8ac43a4883531697145df34987dc3bc
parentcba78295dc26335ecc1d72607b2969c3fee3e3ca (diff)
downloadopus-6833de48015e73683ca771945d5ca9cc16782e8a.tar.gz
added numbits and offset feature
-rw-r--r--silk/decode_core.c2
-rw-r--r--silk/decode_frame.c30
-rw-r--r--src/opus_demo.c5
-rw-r--r--src/opus_encoder.c4
4 files changed, 34 insertions, 7 deletions
diff --git a/silk/decode_core.c b/silk/decode_core.c
index b156e69a..d0499c62 100644
--- a/silk/decode_core.c
+++ b/silk/decode_core.c
@@ -54,11 +54,13 @@ void silk_decode_core(
static FILE *fgain = NULL;
static FILE *fltp = NULL;
static FILE *fperiod = NULL;
+ static FILE *foffset = NULL;
if (flpc == NULL) {flpc = fopen("features_lpc.f32", "wb");}
if (fgain == NULL) {fgain = fopen("features_gain.f32", "wb");}
if (fltp == NULL) {fltp = fopen("features_ltp.f32", "wb");}
if (fperiod == NULL) {fperiod = fopen("features_period.s16", "wb");}
+ if (foffset == NULL) {foffset = fopen("features_offset.f32", "wb");}
#endif
opus_int i, k, lag = 0, start_idx, sLTP_buf_idx, NLSF_interpolation_flag, signalType;
diff --git a/silk/decode_frame.c b/silk/decode_frame.c
index 4f36f854..fcb3cf58 100644
--- a/silk/decode_frame.c
+++ b/silk/decode_frame.c
@@ -29,6 +29,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "config.h"
#endif
+#ifdef FEATURES
+#include <stdio.h>
+#endif
+
#include "main.h"
#include "stack_alloc.h"
#include "PLC.h"
@@ -48,8 +52,19 @@ opus_int silk_decode_frame(
{
VARDECL( silk_decoder_control, psDecCtrl );
opus_int L, mv_len, ret = 0;
+#ifdef FEATURES
+ opus_int32 num_bits;
+ static float num_bits_smooth = -1;
+ static FILE* f_numbits = NULL;
+ static FILE* f_numbits_smooth = NULL;
+#endif
SAVE_STACK;
+#ifdef FEATURES
+ if(f_numbits == NULL) {f_numbits = fopen("features_num_bits.s32", "wb");}
+ if (f_numbits_smooth == NULL) {f_numbits_smooth = fopen("features_num_bits_smooth.f32", "wb");}
+#endif
+
L = psDec->frame_length;
ALLOC( psDecCtrl, 1, silk_decoder_control );
psDecCtrl->LTP_scale_Q14 = 0;
@@ -63,6 +78,10 @@ opus_int silk_decode_frame(
VARDECL( opus_int16, pulses );
ALLOC( pulses, (L + SHELL_CODEC_FRAME_LENGTH - 1) &
~(SHELL_CODEC_FRAME_LENGTH - 1), opus_int16 );
+#ifdef FEATURES
+ num_bits = ec_tell(psRangeDec);
+ printf("numbits: %d\n", num_bits);
+#endif
/*********************************************/
/* Decode quantization indices of side info */
/*********************************************/
@@ -73,6 +92,17 @@ opus_int silk_decode_frame(
/*********************************************/
silk_decode_pulses( psRangeDec, pulses, psDec->indices.signalType,
psDec->indices.quantOffsetType, psDec->frame_length );
+#ifdef FEATURES
+ num_bits = ec_tell(psRangeDec) - num_bits;
+ if (num_bits_smooth < 0) {
+ num_bits_smooth = num_bits;
+ }
+ else {
+ num_bits_smooth = 0.9 * num_bits_smooth + 0.1 * num_bits;
+ }
+ fwrite(&num_bits, sizeof(num_bits), 1, f_numbits);
+ fwrite(&num_bits_smooth, sizeof(num_bits_smooth), 1, f_numbits_smooth);
+#endif
/********************************************/
/* Decode parameters and pulse signal */
diff --git a/src/opus_demo.c b/src/opus_demo.c
index fd4c91ca..71eb13e9 100644
--- a/src/opus_demo.c
+++ b/src/opus_demo.c
@@ -307,7 +307,6 @@ int main(int argc, char *argv[])
int delayed_decision=0;
int silk_random_switching = 0;
int silk_frame_counter = 0;
- FILE *silk_bitrate_file = NULL;
int ret = EXIT_FAILURE;
OPUS_SET_FORCE_MODE(MODE_SILK_ONLY);
@@ -523,7 +522,6 @@ int main(int argc, char *argv[])
} else if( strcmp( argv[ args ], "-silk_random_switching" ) == 0 ){
silk_random_switching = atoi( argv[ args + 1 ] );
printf("switching encoding parameters every %dth frame\n", silk_random_switching);
- silk_bitrate_file = fopen("bitrate.s32", "wb");
args += 2;
} else {
printf( "Error: unrecognized setting: %s\n\n", argv[ args ] );
@@ -740,7 +738,6 @@ int main(int argc, char *argv[])
}
opus_encoder_ctl(enc, OPUS_GET_BITRATE_REQUEST, &bitrate);
- fwrite(&bitrate, sizeof(bitrate), 1, silk_bitrate_file);
}
@@ -950,8 +947,6 @@ failure:
fclose(fin);
if (fout)
fclose(fout);
- if (silk_bitrate_file)
- fclose(silk_bitrate_file);
free(in);
free(out);
free(fbytes);
diff --git a/src/opus_encoder.c b/src/opus_encoder.c
index 73cf5065..a7aa2481 100644
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -128,8 +128,8 @@ struct OpusEncoder {
middle (memoriless) threshold. The second column is the hysteresis
(difference with the middle) */
static const opus_int32 mono_voice_bandwidth_thresholds[8] = {
- 9000, 700, /* NB<->MB */
- 9000, 700, /* MB<->WB */
+ 1000, 700, /* NB<->MB */
+ 1000, 700, /* MB<->WB */
13500, 1000, /* WB<->SWB */
14000, 2000, /* SWB<->FB */
};