diff --git a/apps/decoder.c b/apps/decoder.c index 73ba2ab622307f2dbf519f30890a563429c572f9..14b0c19f3ba54d1a0c2bb9b62550fb9eef7141b4 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -57,6 +57,13 @@ #include "debug.h" #endif #include "render_config_reader.h" +#ifdef DEBUG_SBA +#include "ivas_cnst.h" +#include "spar_debug.h" +int16_t numTransportChannels = 1; +int16_t numOutChannels = 1; +int16_t pca_ingest_channels = 1; +#endif #define WMC_TOOL_MAN @@ -389,6 +396,15 @@ int main( } } +#ifdef DEBUG_SBA + spar_debug_t dbg_params; + dbg_params.fs = arg.output_Fs; + dbg_params.n_ch = numOutChannels; + dbg_params.n_transport = numTransportChannels; + dbg_params.pca_ingest_channels = pca_ingest_channels; + ivas_open_decoder_debug_files( &dbg_params ); +#endif + /*-----------------------------------------------------------------* * Print information about FEC *-----------------------------------------------------------------*/ @@ -570,6 +586,13 @@ cleanup: printf( "\n" ); } +#ifdef DEBUG_SBA + dbg_params.fs = arg.output_Fs; + dbg_params.n_ch = numOutChannels; + dbg_params.n_transport = numTransportChannels; + dbg_params.pca_ingest_channels = pca_ingest_channels; + ivas_close_decoder_debug_files( &dbg_params ); +#endif #ifdef DEBUGGING dbgclose(); #endif diff --git a/apps/encoder.c b/apps/encoder.c index 5443bafe43dc42f2b69f0e3f4cdf96d0a97e2ab3..8f82f3d0d665f3308321f86fd6569d8cb6493208 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -51,7 +51,7 @@ #endif #ifdef DEBUGGING #include "debug.h" -#ifdef DEBUG_SPAR_FOA +#ifdef DEBUG_SBA #include "ivas_cnst.h" #include "spar_debug.h" #endif @@ -129,7 +129,7 @@ typedef struct #ifdef DEBUG_FOA_AGC FILE *agcBitstream; /* temporary */ #endif -#ifdef DEBUG_SPAR_FOA +#ifdef DEBUG_SBA const char *dbg_file_tag; #endif @@ -218,7 +218,7 @@ int main( FILE *f_forcedModeProfile = NULL; #endif -#ifdef DEBUG_SPAR_FOA +#ifdef DEBUG_SBA spar_debug_t dbg_params; #endif #ifdef WMOPS @@ -252,18 +252,6 @@ int main( goto cleanup; } -#ifdef DEBUG_SPAR_FOA - dbg_params.agc = (int16_t) arg.agc; - dbg_params.dtx_on = (int16_t) arg.dtxConfig.enabled; - dbg_params.file_tag = arg.dbg_file_tag; - dbg_params.ivas_total_brate = arg.initBitrate; -#ifdef DEBUG_AGC - ivas_open_agc_debug_files( &dbg_params ); -#endif - ivas_open_debug_files( &dbg_params ); -#endif - - /*------------------------------------------------------------------------------------------* * Open and initialize IVAS encoder *------------------------------------------------------------------------------------------*/ @@ -570,6 +558,32 @@ int main( uint16_t bitStream[IVAS_MAX_BITS_PER_FRAME]; uint16_t numBits = 0; +#ifdef DEBUG_SBA + int16_t numInputChannels; + if ( ( error = IVAS_ENC_GetNumInputChannels( hIvasEnc, &numInputChannels ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nGetNumInputChannels failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + dbg_params.agc = (int16_t) arg.agc; + dbg_params.dtx_on = (int16_t) arg.dtxConfig.enabled; + dbg_params.file_tag = arg.dbg_file_tag; + dbg_params.ivas_total_brate = arg.initBitrate; + dbg_params.fs = arg.inputFs; + dbg_params.n_ch = numInputChannels; + int16_t numTransportChannels; + if ( ( error = getTransportChannel( hIvasEnc, &numTransportChannels ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nGetNumInputChannels failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + dbg_params.n_transport = numTransportChannels; +#ifdef DEBUG_AGC + ivas_open_agc_debug_files( &dbg_params ); +#endif + ivas_open_debug_files( &dbg_params ); +#endif + if ( !arg.quietModeEnabled ) { fprintf( stdout, "\n------ Running the encoder ------\n\n" ); @@ -832,7 +846,7 @@ cleanup: dbgclose(); #endif -#ifdef DEBUG_SPAR_FOA +#ifdef DEBUG_SBA ivas_close_remove_debug_files(); #ifdef DEBUG_AGC ivas_close_agc_debug_files( &io_params ); @@ -879,7 +893,7 @@ static void initArgStruct( EncArguments *arg ) #ifdef DEBUG_FOA_AGC arg->agcBitstream = NULL; #endif -#ifdef DEBUG_SPAR_FOA +#ifdef DEBUG_SBA arg->dbg_file_tag = NULL; #endif @@ -1434,7 +1448,7 @@ static bool parseCmdlIVAS_enc( return false; } } -#ifdef DEBUG_SPAR_FOA +#ifdef DEBUG_SBA /*-----------------------------------------------------------------* * IVAS SPAR debug files tag *-----------------------------------------------------------------*/ @@ -1637,7 +1651,7 @@ static void usage_enc( void ) fprintf( stdout, " The encoder produces TS26.445 Annex.2.6 Mime Storage Format, (not RFC4867 Mime Format).\n" ); fprintf( stdout, " default output bitstream file format is G.192\n" ); -#ifdef DEBUG_SPAR_FOA +#ifdef DEBUG_SBA fprintf( stdout, "-tag : Tag name for intermediate debug files\n" ); #endif fprintf( stdout, "-agc op : SBA Adaptive gain control, op = (0, 1), by default op is 0 or deactivated\n" ); diff --git a/lib_com/options.h b/lib_com/options.h index 34293516096cdbcceb2ca12f1009f982e6834203..5104c46ae98fbc14e631a403a148a77dd47b51cc 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -114,8 +114,10 @@ /*#define TDREND_HRTF_TABLE_METHODS*/ /* Enable HRTF lookup from tables, for testing & evaluation. Supply file in table format to use. Note that a suitable HR filter lookup method should be written if the filters sample point grids are not in the formats. */ /*#define TDREND_STANDALONE*/ /* Used when renderer is built in standalone form, without IVAS encoding/decoding (see scripts/object_renderer_standalone). This is just here to ensure this is cleaned out by prepare_instrumentation.sh */ -/*#define DEBUG_SPAR_FOA*/ /* debug SPAR in-out */ -#ifdef DEBUG_SPAR_FOA +/*#define DEBUG_SBA*/ /* debug DIRAC/SPAR in-out */ +#ifdef DEBUG_SBA +/*#define DEBUG_SBA_AUDIO_DUMP*/ /* SBA intermediate audio wav file dumping */ +/*#define DEBUG_SBA_MD_DUMP*/ /* SBA metadata and variable file dumping */ /*#define DEBUG_SPAR_MD_TARGET_TUNING*/ /* SPAR MD target bitrate tuning debug code */ /*#define DEBUG_SPAR_BYPASS_EVS_CODEC*/ /* bypass EVS coding in float precision, emulating EVS encoder/decoder delay */ /*#define DEBUG_SPAR_WRITE_OUT_COV*/ /* write covariance per frame into a text file for verification */ diff --git a/lib_debug/spar_debug.c b/lib_debug/spar_debug.c index a1dd7a9ee8cda973600de8c2feaa15871254bf5e..619365735bca50301a0028dd502d8bd967c09e9b 100644 --- a/lib_debug/spar_debug.c +++ b/lib_debug/spar_debug.c @@ -41,23 +41,22 @@ #include "spar_debug.h" #include #include "wmops.h" - +#ifdef DEBUG_SBA +#include +#include "tinywaveout_c.h" /*-------------------------------------------------------------------* * Global variables used for debugging but not under DEBUGGING flag *--------------------------------------------------------------------*/ -#ifdef DEBUG_SPAR_FOA + #define MAX_IN_FILE_LEN ( 1000 ) #define MAX_PLUG_IN_FILE_LEN ( MAX_IN_FILE_LEN ) #define MAX_DEBUG_TAG_LEN ( 50 ) #define NUM_DEBUG_FILES ( 4 ) #define MAX_TAG_LEN ( 200 ) -FILE *fEvs_enc_in; -FILE *fMd_data; -FILE *fModels_data; -FILE *fEig_iters; -FILE *fFb_out[4]; +WAVEFILEOUT *spar_foa_enc_wav[3]; +WAVEFILEOUT *spar_foa_dec_wav[4]; float max_diff = 0; int32_t dbg_frm_num; int32_t dbg_band; @@ -154,20 +153,111 @@ void ivas_open_agc_debug_files( spar_debug_t *pDebug_params ) fprintf( stdout, "Temporary gain control bitstream file %s is opened\n", agcFilename ); } } - #endif +void UpdateWave( const uint32_t sampleRate, const uint32_t numChannels, const uint32_t bps, WAVEFILEOUT *spar_wav ) +{ + uint32_t blockAlignment = 0; + uint16_t writeValue16; + uint32_t writeValue32; + + writeValue16 = LittleEndian16( (int16_t) numChannels ); + /*Fseek to number of channel writing position*/ + fseek( spar_wav->theFile, 22, SEEK_SET ); + fwrite( &writeValue16, sizeof( writeValue16 ), 1, spar_wav->theFile ); + blockAlignment = numChannels * ( bps >> 3 ); + writeValue16 = LittleEndian16( (int16_t) blockAlignment ); + fseek( spar_wav->theFile, 4, SEEK_CUR ); + writeValue32 = LittleEndian32( sampleRate * blockAlignment ); + fwrite( &writeValue32, sizeof( writeValue32 ), 1, spar_wav->theFile ); + fwrite( &writeValue16, sizeof( writeValue16 ), 1, spar_wav->theFile ); +} + +float ivas_spar_dump_signal_wav( int16_t input_frame, float data_f[][L_FRAME48k * 2], int16_t no_channel, WAVEFILEOUT *wave_file ) +{ + float tmp_value; + int16_t pcm_value, i, j, k; + int16_t debug_tmp[IVAS_SPAR_MAX_CH * L_FRAME48k * 2]; + /* Dump audio signal after pca_enc */ + k = 0; + int16_t Clipping = 0; + float largest_value = 0; + float db_value = 0; + for ( j = 0; j < input_frame; j++ ) + { + for ( i = 0; i < no_channel; i++, k++ ) + { + tmp_value = roundf( data_f[i][j] * PCM16_TO_FLT_FAC ); + if ( tmp_value > MAX16B_FLT ) + { + largest_value = (float) fabs( tmp_value ) > largest_value ? (float) fabs( tmp_value ) : largest_value; + tmp_value = MAX16B; + Clipping++; + } + else if ( tmp_value < MIN16B_FLT ) + { + largest_value = (float) fabs( tmp_value ) > largest_value ? (float) fabs( tmp_value ) : largest_value; + tmp_value = MIN16B; + Clipping++; + } + pcm_value = (int16_t) tmp_value; + /*pcm_value = (tmp_value > MAX16B_FLT) ? MAX16B : (tmp_value < MIN16B_FLT) ? MIN16B + : (short)tmp_value;*/ + debug_tmp[k] = pcm_value; + } + } + if ( Clipping ) + { + db_value = 20.f * (float) log( largest_value ); + fprintf( stderr, "%d\t Clipping detected ", Clipping ); + } + WriteWavShort( + wave_file, + debug_tmp, + ( no_channel * input_frame ) ); + + return ( db_value ); +} + +void ivas_close_decoder_debug_files( spar_debug_t *pDebug_params ) +{ + if ( spar_foa_dec_wav[0] != NULL ) + { + UpdateWave( pDebug_params->fs, pDebug_params->n_transport, 32, spar_foa_dec_wav[0] ); + CloseWav( spar_foa_dec_wav[0] ); + } + if ( spar_foa_dec_wav[1] != NULL ) + { + UpdateWave( pDebug_params->fs, pDebug_params->n_transport, 16, spar_foa_dec_wav[1] ); + CloseWav( spar_foa_dec_wav[1] ); + } + if ( spar_foa_dec_wav[2] != NULL ) + { + UpdateWave( pDebug_params->fs, pDebug_params->pca_ingest_channels, 16, spar_foa_dec_wav[2] ); + CloseWav( spar_foa_dec_wav[2] ); + } + if ( spar_foa_dec_wav[3] != NULL ) + { + UpdateWave( pDebug_params->fs, pDebug_params->n_ch, 16, spar_foa_dec_wav[3] ); + CloseWav( spar_foa_dec_wav[3] ); + } +} void ivas_close_remove_debug_files( void ) { - if ( fEvs_enc_in != NULL ) - fclose( fEvs_enc_in ); - if ( fMd_data != NULL ) - fclose( fMd_data ); - if ( fModels_data != NULL ) - fclose( fModels_data ); - if ( fEig_iters != NULL ) - fclose( fEig_iters ); + + if ( spar_foa_enc_wav[0] != NULL ) + { + CloseWav( spar_foa_enc_wav[0] ); + } + if ( spar_foa_enc_wav[1] != NULL ) + { + CloseWav( spar_foa_enc_wav[1] ); + } + if ( spar_foa_enc_wav[2] != NULL ) + { + CloseWav( spar_foa_enc_wav[2] ); + } /* Enable print max diff to a file */ @@ -184,20 +274,46 @@ void ivas_close_remove_debug_files( void ) fclose(fp); */ } -void ivas_open_debug_files( spar_debug_t *pDebug_params ) +void ivas_open_decoder_debug_files( spar_debug_t *pDebug_params ) { -#ifndef MSVS_DEBUG - int8_t evs_in_path[MAX_PLUG_IN_FILE_LEN] = "spar_foa_bs/enc/evs_pcm_in/"; - int8_t mat_md_path[MAX_PLUG_IN_FILE_LEN] = "spar_foa_bs/enc/mat_md/"; - int8_t models_data_path[MAX_PLUG_IN_FILE_LEN] = "spar_foa_bs/enc/ec_models/"; - int8_t fb_pcm_dump_path[4][MAX_PLUG_IN_FILE_LEN] = { "spar_foa_bs/fb_dumps/", "spar_foa_bs/fb_dumps/", "spar_foa_bs/fb_dumps/", "spar_foa_bs/fb_dumps/" }; -#else - int8_t evs_in_path[MAX_PLUG_IN_FILE_LEN] = "../scripts/ivas_pytests/tests/restricted/system_tests/spar_foa_bs/enc/evs_pcm_in/"; - int8_t mat_md_path[MAX_PLUG_IN_FILE_LEN] = "../scripts/ivas_pytests/tests/restricted/system_tests/spar_foa_bs/enc/mat_md/"; - int8_t models_data_path[MAX_PLUG_IN_FILE_LEN] = "../scripts/ivas_pytests/tests/restricted/system_tests/spar_foa_bs/enc/ec_models/"; - int8_t fb_pcm_dump_path[4][MAX_PLUG_IN_FILE_LEN] = { "../scripts/ivas_pytests/tests/restricted/system_tests/spar_foa_bs/fb_dumps/", "../tests/restricted/system_tests/spar_foa_bs/fb_dumps/", "../tests/restricted/system_tests/spar_foa_bs/fb_dumps/", "../tests/restricted/system_tests/spar_foa_bs/fb_dumps/" }; -#endif + int8_t fb_wav_dump_path[4][MAX_PLUG_IN_FILE_LEN] = { "", "", "", "" }; + cstrcat( (char *) fb_wav_dump_path[0], sizeof( fb_wav_dump_path[0] ), "dec_out.wav" ); + spar_foa_dec_wav[0] = CreateWav( + (const char *) fb_wav_dump_path[0], + pDebug_params->fs, + pDebug_params->n_ch, + 32 + /* const uint32_t writeWaveExt */ + ); + cstrcat( (char *) fb_wav_dump_path[1], sizeof( fb_wav_dump_path[1] ), "agc_dec_out.wav" ); + spar_foa_dec_wav[1] = CreateWav( + (const char *) fb_wav_dump_path[1], + pDebug_params->fs, + pDebug_params->n_transport, + 16 + /* const uint32_t writeWaveExt */ + ); + cstrcat( (char *) fb_wav_dump_path[2], sizeof( fb_wav_dump_path[2] ), "pca_dec.wav" ); + spar_foa_dec_wav[2] = CreateWav( + (const char *) fb_wav_dump_path[2], + pDebug_params->fs, + pDebug_params->n_transport, + 16 + /* const uint32_t writeWaveExt */ + ); + cstrcat( (char *) fb_wav_dump_path[3], sizeof( fb_wav_dump_path[3] ), "cldfbSynthesis.wav" ); + spar_foa_dec_wav[3] = CreateWav( + (const char *) fb_wav_dump_path[3], + pDebug_params->fs, + pDebug_params->n_transport, + 16 + /* const uint32_t writeWaveExt */ + ); +} +void ivas_open_debug_files( spar_debug_t *pDebug_params ) +{ + int8_t fb_wav_dump_path[3][MAX_PLUG_IN_FILE_LEN] = { "spar_foa_enc", "spar_foa_enc", "spar_foa_enc" }; if ( pDebug_params->file_tag != NULL ) { cstrcpy( (char *) file_names[0], sizeof( file_names[0] ), (const char *) pDebug_params->file_tag ); @@ -206,18 +322,33 @@ void ivas_open_debug_files( spar_debug_t *pDebug_params ) /* ivas_total_brate */ switch ( pDebug_params->ivas_total_brate ) { + case 24400: + cstrcat( (char *) file_names[0], sizeof( file_names[0] ), "_ivasbr24k" ); + break; case 32000: cstrcat( (char *) file_names[0], sizeof( file_names[0] ), "_ivasbr32k" ); break; + case 48000: + cstrcat( (char *) file_names[0], sizeof( file_names[0] ), "_ivasbr48k" ); + break; case 64000: cstrcat( (char *) file_names[0], sizeof( file_names[0] ), "_ivasbr64k" ); break; + case 80000: + cstrcat( (char *) file_names[0], sizeof( file_names[0] ), "_ivasbr80k" ); + break; case 96000: cstrcat( (char *) file_names[0], sizeof( file_names[0] ), "_ivasbr96k" ); break; + case 128000: + cstrcat( (char *) file_names[0], sizeof( file_names[0] ), "_ivasbr128k" ); + break; case 160000: cstrcat( (char *) file_names[0], sizeof( file_names[0] ), "_ivasbr160k" ); break; + case 192000: + cstrcat( (char *) file_names[0], sizeof( file_names[0] ), "_ivasbr192k" ); + break; case 256000: cstrcat( (char *) file_names[0], sizeof( file_names[0] ), "_ivasbr256k" ); break; @@ -229,9 +360,6 @@ void ivas_open_debug_files( spar_debug_t *pDebug_params ) break; } - /* fb id */ - cstrcat( (char *) file_names[0], sizeof( file_names[0] ), "_48dly" ); - /* DTX */ if ( pDebug_params->dtx_on ) { @@ -247,37 +375,33 @@ void ivas_open_debug_files( spar_debug_t *pDebug_params ) cstrcpy( (char *) file_names[3], sizeof( file_names[3] ), (const char *) file_names[0] ); cstrcat( (char *) file_names[0], sizeof( file_names[0] ), "_pcm.txt" ); - cstrcat( (char *) evs_in_path, sizeof( evs_in_path ), (const char *) file_names[0] ); - fEvs_enc_in = fopen( (const char *) evs_in_path, "rb" ); - - cstrcat( (char *) file_names[1], sizeof( file_names[1] ), ".md" ); - cstrcat( (char *) mat_md_path, sizeof( mat_md_path ), (const char *) file_names[1] ); - fMd_data = fopen( (const char *) mat_md_path, "rb" ); - - cstrcat( (char *) file_names[3], sizeof( file_names[3] ), ".txt" ); - cstrcat( (char *) models_data_path, sizeof( models_data_path ), (const char *) file_names[3] ); - fModels_data = fopen( (const char *) models_data_path, "rb" ); - - fEig_iters = NULL; - /*Enable this below to dump iteration count for each frame - fEig_iters = fopen(strcat(eig_iter_dmp_path, strcat(file_names[1], "_eig_iters.txt")), "wb"); */ - - /* Enable for fb pcm dumps */ - cstrcat( (char *) fb_pcm_dump_path[0], sizeof( fb_pcm_dump_path[0] ), (const char *) file_names[2] ); - cstrcat( (char *) fb_pcm_dump_path[0], sizeof( fb_pcm_dump_path[0] ), "/ch1.raw" ); - fFb_out[0] = fopen( (const char *) fb_pcm_dump_path[0], "wb" ); - - cstrcat( (char *) fb_pcm_dump_path[1], sizeof( fb_pcm_dump_path[1] ), (const char *) file_names[2] ); - cstrcat( (char *) fb_pcm_dump_path[1], sizeof( fb_pcm_dump_path[1] ), "/ch2.raw" ); - fFb_out[1] = fopen( (const char *) fb_pcm_dump_path[1], "wb" ); - - cstrcat( (char *) fb_pcm_dump_path[2], sizeof( fb_pcm_dump_path[2] ), (const char *) file_names[2] ); - cstrcat( (char *) fb_pcm_dump_path[2], sizeof( fb_pcm_dump_path[2] ), "/ch3.raw" ); - fFb_out[2] = fopen( (const char *) fb_pcm_dump_path[2], "wb" ); - - cstrcat( (char *) fb_pcm_dump_path[3], sizeof( fb_pcm_dump_path[3] ), (const char *) file_names[2] ); - cstrcat( (char *) fb_pcm_dump_path[3], sizeof( fb_pcm_dump_path[3] ), "/ch4.raw" ); - fFb_out[3] = fopen( (const char *) fb_pcm_dump_path[3], "wb" ); + cstrcat( (char *) fb_wav_dump_path[0], sizeof( fb_wav_dump_path[0] ), (const char *) file_names[2] ); + cstrcat( (char *) fb_wav_dump_path[0], sizeof( fb_wav_dump_path[0] ), "_pca_enc.wav" ); + spar_foa_enc_wav[0] = CreateWav( + (const char *) fb_wav_dump_path[0], + pDebug_params->fs, + pDebug_params->n_ch, + 16 + /* const uint32_t writeWaveExt */ + ); + cstrcat( (char *) fb_wav_dump_path[1], sizeof( fb_wav_dump_path[1] ), (const char *) file_names[2] ); + cstrcat( (char *) fb_wav_dump_path[1], sizeof( fb_wav_dump_path[1] ), "_fb_mixer_enc.wav" ); + spar_foa_enc_wav[1] = CreateWav( + (const char *) fb_wav_dump_path[1], + pDebug_params->fs, + pDebug_params->n_transport, + 16 + /* const uint32_t writeWaveExt */ + ); + cstrcat( (char *) fb_wav_dump_path[2], sizeof( fb_wav_dump_path[2] ), (const char *) file_names[2] ); + cstrcat( (char *) fb_wav_dump_path[2], sizeof( fb_wav_dump_path[2] ), "_agc_enc.wav" ); + spar_foa_enc_wav[2] = CreateWav( + (const char *) fb_wav_dump_path[2], + pDebug_params->fs, + pDebug_params->n_transport, + 16 + /* const uint32_t writeWaveExt */ + ); } -#endif /* DEBUG_SPAR_FOA */ +#endif /* DEBUG_SBA */ diff --git a/lib_debug/spar_debug.h b/lib_debug/spar_debug.h index 530996d81b87385ef40c213e47de39aece8fd572..8e8457e16a5076de1ba89bd6b98e8ffa5846cf95 100644 --- a/lib_debug/spar_debug.h +++ b/lib_debug/spar_debug.h @@ -36,25 +36,35 @@ #include "options.h" #include #include +#ifdef DEBUG_SBA +#include "tinywaveout_c.h" /*------------------------------------------------------------------------------------------* * Global variables used for debugging *------------------------------------------------------------------------------------------*/ -#ifdef DEBUG_SPAR_FOA + typedef struct spar_debug_t { const char *file_tag; int32_t ivas_total_brate; int16_t dtx_on; int16_t agc; + int32_t fs; + int16_t n_ch; + int16_t n_transport; + int16_t pca_ingest_channels; } spar_debug_t; #ifdef DEBUG_AGC void ivas_close_agc_debug_files( spar_debug_t *pDebug_params ); void ivas_open_agc_debug_files( spar_debug_t *pDebug_params ); #endif +float ivas_spar_dump_signal_wav( int16_t input_frame, float data_f[][L_FRAME48k * 2], int16_t no_channel, WAVEFILEOUT *wave_file ); void ivas_close_remove_debug_files( void ); void ivas_open_debug_files( spar_debug_t *pDebug_params ); +void ivas_close_decoder_debug_files( spar_debug_t *pDebug_params ); +void ivas_open_decoder_debug_files( spar_debug_t *dbg_params ); +void UpdateWave( const uint32_t sampleRate, const uint32_t numChannels, const uint32_t bps, WAVEFILEOUT *spar_wav ); #endif #endif /* SPAR_DEBUG_H */ diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index aa1687aabeb7f974b50c56be5a0610a6af87f4db..9acc451ea0a65dcf6e0df375bee54aeb07a0806a 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -42,7 +42,14 @@ #include "debug.h" #endif #include "wmops.h" - +#ifdef DEBUG_SBA_AUDIO_DUMP +#include "tinywaveout_c.h" +#include "spar_debug.h" +float data_array[IVAS_MAX_NUM_CH][L_FRAME48k * 2]; +extern WAVEFILEOUT *spar_foa_dec_wav[4]; +extern int16_t numTransportChannels; +extern int16_t numOutChannels; +#endif /*--------------------------------------------------------------------------* * ivas_dec() @@ -278,7 +285,24 @@ ivas_error ivas_dec( return error; } } - +#ifdef DEBUG_SBA_AUDIO_DUMP + float largest_value; + int16_t i, j; + numTransportChannels = st_ivas->nchan_transport; + /* Dump audio signal after core-decoding */ + for ( i = 0; i < numTransportChannels; i++ ) + { + for ( j = 0; j < output_frame; j++ ) + { + data_array[i][j] = output[i][j]; + } + } + largest_value = ivas_spar_dump_signal_wav( output_frame, data_array, numTransportChannels, spar_foa_dec_wav[0] ); + if ( largest_value ) + { + fprintf( stderr, "\t In core-decoding largest clipped sample in dB %f \n", largest_value ); + } +#endif /* TCs remapping */ nchan_remapped = st_ivas->nchan_transport; if ( st_ivas->sba_dirac_stereo_flag ) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 95a2d7d61ead739b5536a95d71cc974f93a9d096..7dbb54676018e9f0b952cd44086388e0bebdcb51 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -44,9 +44,14 @@ #include #include #include "wmops.h" - -#ifdef DEBUG_SPAR_FOA -extern FILE *fFb_pcm; +#ifdef DEBUG_SBA_AUDIO_DUMP +#include "tinywaveout_c.h" +#include "spar_debug.h" +extern WAVEFILEOUT *spar_foa_dec_wav[4]; +float data_array[IVAS_MAX_NUM_CH][L_FRAME48k * 2]; +extern int16_t numTransportChannels; +extern int16_t pca_ingest_channels; +extern int16_t numOutChannels; #endif /*-------------------------------------------------------------------* @@ -441,7 +446,7 @@ void ivas_spar_get_cldfb_gains( weights = hSpar->hFbMixer->cldfb_cross_fade; cf_cldfb_start = (int16_t) ceil( ( cf_start - decfb_delay / 2 ) / (float) stride - 0.5f ); - cf_cldfb_end = ( int16_t )( ( cf_start - decfb_delay / 2 + cf_len ) / (float) stride - 0.5f ); + cf_cldfb_end = (int16_t) ( ( cf_start - decfb_delay / 2 + cf_len ) / (float) stride - 0.5f ); num_cf_slots = cf_cldfb_end - cf_cldfb_start + 1; num_samples = num_cf_slots * stride + pt_len - stride; @@ -740,7 +745,7 @@ static float ivas_spar_get_cldfb_slot_gain( encfb_delay = IVAS_FB_ENC_DELAY_NS; decfb_delay = IVAS_FB_DEC_DELAY_NS; xfade_start_ns = pState->hFbMixer->cross_fade_start_offset / output_Fs * 1000000000.f - encfb_delay + decfb_delay * 0.5f; - xfade_delay_subframes = ( int16_t )( xfade_start_ns / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) ); + xfade_delay_subframes = (int16_t) ( xfade_start_ns / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) ); i_hist = 4 - xfade_delay_subframes; split_band = SPAR_DIRAC_SPLIT_START_BAND; @@ -913,19 +918,6 @@ void ivas_spar_dec_upmixer( numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; -#ifdef DEBUG_SPAR_FOA - if ( fFb_pcm != NULL ) - { - for ( i = 0; i < output_frame; i++ ) - { - for ( int16_t j = 0; j < nchan_transport; j++ ) - { - fscanf( fFb_pcm, "%f\n", &output[j][i] ); - } - } - } -#endif - /* by-pass EVS */ #ifdef DEBUG_SPAR_BYPASS_EVS_CODEC /*write the core coder output to a file for debugging*/ @@ -967,6 +959,24 @@ void ivas_spar_dec_upmixer( *---------------------------------------------------------------------*/ ivas_agc_dec_process( pState->hAgcDec, output, output, nchan_transport, output_frame ); +#ifdef DEBUG_SBA_AUDIO_DUMP + int16_t l; + float largest_value; + numTransportChannels = st_ivas->nchan_transport; + /* Dump audio signal after ivas_agc_dec_process */ + for ( i = 0; i < numTransportChannels; i++ ) + { + for ( l = 0; l < output_frame; l++ ) + { + data_array[i][l] = output[i][l]; + } + } + largest_value = ivas_spar_dump_signal_wav( output_frame, data_array, numTransportChannels, spar_foa_dec_wav[1] ); + if ( largest_value ) + { + fprintf( stderr, "\t In ivas_agc_dec_process() largest clipped sample in dB %f \n", largest_value ); + } +#endif /*---------------------------------------------------------------------* * TD Decorr and pcm ingest @@ -995,6 +1005,22 @@ void ivas_spar_dec_upmixer( #endif { ivas_pca_dec( pState->hPCA, output_frame, num_in_ingest, hDecoderConfig->ivas_total_brate, hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, output ); +#ifdef DEBUG_SBA_AUDIO_DUMP + pca_ingest_channels = num_in_ingest; + /* Dump audio signal after ivas_pca_dec */ + for ( i = 0; i < pca_ingest_channels; i++ ) + { + for ( l = 0; l < output_frame; l++ ) + { + data_array[i][l] = output[i][l]; + } + } + largest_value = ivas_spar_dump_signal_wav( output_frame, data_array, pca_ingest_channels, spar_foa_dec_wav[2] ); + if ( largest_value ) + { + fprintf( stderr, "\t In ivas_pca_dec() largest clipped sample in dB %f \n", largest_value ); + } +#endif } /*---------------------------------------------------------------------* @@ -1180,6 +1206,9 @@ void ivas_spar_dec_upmixer( idx_in++; } } +#ifdef DEBUG_SBA_AUDIO_DUMP + numOutChannels = outchannels; +#endif } else { @@ -1198,7 +1227,25 @@ void ivas_spar_dec_upmixer( ); } } +#ifdef DEBUG_SBA_AUDIO_DUMP + numOutChannels = numch_out_dirac; +#endif + } +#ifdef DEBUG_SBA_AUDIO_DUMP + /* Dump audio signal after cldfbSynthesis */ + for ( i = 0; i < numOutChannels; i++ ) + { + for ( l = 0; l < output_frame; l++ ) + { + data_array[i][l] = output[i][l]; + } + } + largest_value = ivas_spar_dump_signal_wav( output_frame, data_array, numOutChannels, spar_foa_dec_wav[3] ); + if ( largest_value ) + { + fprintf( stderr, "\t In cldfbSynthesis() largest clipped sample in dB %f \n", largest_value ); } +#endif split_band = SPAR_DIRAC_SPLIT_START_BAND; if ( split_band < IVAS_MAX_NUM_BANDS ) diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 291bbc56193f345ce5c27603a1fcb5e9cc350a20..412da7d5db88a60c8621955e2e314d8955d1f49d 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -42,7 +42,9 @@ #include #include "wmops.h" #include "ivas_stat_dec.h" - +#ifdef DEBUG_SBA_MD_DUMP +extern int32_t frame; +#endif /*#define ENABLE_DITHER */ /* IVAS_fmToDo: development switch */ @@ -620,6 +622,54 @@ void ivas_spar_md_dec_process( ivas_spar_br_table_consts[hMdDec->table_idx].usePlanarCoeff, st_ivas->hQMetaData->sba_inactive_mode ); +#ifdef DEBUG_SBA_MD_DUMP + { + char f_name[100]; + int16_t num_bands = nB; + int16_t num_subframes = 1, num_block_groups = 1, num_elements = 1, byte_size = sizeof( float ); + int16_t num_ch = 2 * sba_order + 2; + for ( b = 0; b < num_bands; b++ ) + { + sprintf( f_name, "spar_band_pred_coeffs_dec.bin" ); + ( b == 0 && frame == 0 ) ? dbgwrite( &num_bands, sizeof( num_bands ), 1, 1, f_name ) : false; + num_elements = num_ch - 1; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + for ( j = 0; j < num_ch - 1; j++ ) + { + dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[j], sizeof( float ), 1, 1, f_name ); + } + sprintf( f_name, "spar_band_C_coeffs_dec.bin" ); + ( b == 0 && frame == 0 ) ? dbgwrite( &num_bands, sizeof( num_bands ), 1, 1, f_name ) : false; + num_elements = ( hMdDec->spar_md_cfg.num_decorr_per_band[bw * b] - hMdDec->spar_md_cfg.num_dmx_chans_per_band[bw * b] ) * ( hMdDec->spar_md_cfg.num_dmx_chans_per_band[bw * b] - 1 ); + ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + for ( j = 0; j < ( hMdDec->spar_md_cfg.num_decorr_per_band[bw * b] - hMdDec->spar_md_cfg.num_dmx_chans_per_band[bw * b] ); j++ ) + { + for ( int16_t k = 0; k < hMdDec->spar_md_cfg.num_dmx_chans_per_band[bw * b] - 1; k++ ) + { + dbgwrite( &hMdDec->spar_md.band_coeffs[b].C_re[j][k], sizeof( float ), 1, 1, f_name ); + } + } + sprintf( f_name, "spar_band_P_coeffs_dec.bin" ); + ( b == 0 && frame == 0 ) ? dbgwrite( &num_bands, sizeof( num_bands ), 1, 1, f_name ) : false; + num_elements = num_ch - 1; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + for ( j = 0; j < num_ch - 1; j++ ) + { + dbgwrite( &hMdDec->spar_md.band_coeffs[b].P_re[j], sizeof( float ), 1, 1, f_name ); + } + } + } +#endif + /* SPAR to DirAC and DirAC to SPAR conversion */ if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 3660dec23b226c3cd5458cb26ede25a681cafb2f..05a8f83e7f0ee4f99671f672ce1f3f944d0605d5 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -43,7 +43,9 @@ #include "debug.h" #endif #include "wmops.h" - +#ifdef DEBUG_SBA_MD_DUMP +extern int32_t frame; +#endif /*------------------------------------------------------------------------- * Local function prototypes @@ -720,6 +722,64 @@ void ivas_dirac_param_est_enc( } } +#ifdef DEBUG_SBA_MD_DUMP + { + char f_name[100]; + int16_t num_subframes = 1, num_block_groups = 1, num_elements = 1, byte_size = sizeof( float ); + sprintf( f_name, "dirac_enc_diffuseness.bin" ); + ( frame == 0 ) ? dbgwrite( &hDirAC->hConfig->nbands, sizeof( hDirAC->hConfig->nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + dbgwrite( hDirAC->diffuseness_m, sizeof( float ), hDirAC->hConfig->nbands, 1, f_name ); + sprintf( f_name, "dirac_reference_power.bin" ); + ( frame == 0 ) ? dbgwrite( &hDirAC->hConfig->nbands, sizeof( hDirAC->hConfig->nbands ), 1, 1, f_name ) : false; + num_elements = hDirAC->block_grouping[1] - hDirAC->block_grouping[0]; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + num_block_groups = hDirAC->block_grouping[1]; + ( frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + for ( ts = hDirAC->block_grouping[0]; ts < hDirAC->block_grouping[1]; ts++ ) + { + dbgwrite( reference_power[ts], sizeof( float ), hDirAC->hConfig->nbands, 1, f_name ); + } + num_elements = 1; + num_subframes = MAX_PARAM_SPATIAL_SUBFRAMES; + num_block_groups = 1; + sprintf( f_name, "dirac_enc_dir0.bin" ); + ( frame == 0 ) ? dbgwrite( &hDirAC->hConfig->nbands, sizeof( hDirAC->hConfig->nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + for ( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + dbgwrite( hDirAC->direction_vector_m[0][block_m_idx], sizeof( float ), hDirAC->hConfig->nbands, 1, f_name ); + } + sprintf( f_name, "dirac_enc_dir1.bin" ); + ( frame == 0 ) ? dbgwrite( &hDirAC->hConfig->nbands, sizeof( hDirAC->hConfig->nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + for ( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + dbgwrite( hDirAC->direction_vector_m[1][block_m_idx], sizeof( float ), hDirAC->hConfig->nbands, 1, f_name ); + } + sprintf( f_name, "dirac_enc_dir2.bin" ); + ( frame == 0 ) ? dbgwrite( &hDirAC->hConfig->nbands, sizeof( hDirAC->hConfig->nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + for ( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + dbgwrite( hDirAC->direction_vector_m[2][block_m_idx], sizeof( float ), hDirAC->hConfig->nbands, 1, f_name ); + } + } +#endif #ifdef DEBUG_MODE_DIRAC { static FILE *fp_direction_vector = NULL, *fp_diffuseness = NULL, *fp_referencePower = NULL; diff --git a/lib_enc/ivas_entropy_coder.c b/lib_enc/ivas_entropy_coder.c index d43d1e4f6c8941b339a12b992186b7888208472c..1c1d1d564fa6aff9052e2ad4ba37009851db4e0f 100644 --- a/lib_enc/ivas_entropy_coder.c +++ b/lib_enc/ivas_entropy_coder.c @@ -43,11 +43,6 @@ #include #include "wmops.h" -#ifdef DEBUG_SPAR_FOA -#define MREF_BPS_TOL ( 2e-4 ) -extern FILE *fModels_data; -#endif - /*------------------------------------------------------------------------------------------* * Local constants *------------------------------------------------------------------------------------------*/ @@ -122,29 +117,6 @@ static ivas_error ivas_get_dyn_freq_model( *ppCum_freq = pArith->cum_freq[0]; } -#ifdef DEBUG_SPAR_FOA - if ( fModels_data != NULL ) - { - float ref_min_bps = 0; - int32_t ref_model_idx = 0; - fscanf( fModels_data, "%f\n", &ref_min_bps ); - fscanf( fModels_data, "%d\n", &ref_model_idx ); - - if ( fabs( curr_bps_min - ref_min_bps ) > MREF_BPS_TOL ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "SPAR model selection min BPS mismatch: %f, ref: %f, diff: %f \n", curr_bps_min, ref_min_bps, curr_bps_min - ref_min_bps ); - } - else - { - if ( model_idx != ref_model_idx ) - { - model_idx = (int16_t) ref_model_idx; - *ppCum_freq = pArith->cum_freq[model_idx]; - } - } - } -#endif - *model_index = model_idx; return error; diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 2647d96df3fcf68d60863336e09f92c52e3392f2..ae95d02d247b6cfc7bb68225274edd4ef5336f3e 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -43,6 +43,12 @@ #include #include "wmops.h" +#ifdef DEBUG_SBA_AUDIO_DUMP +#include "tinywaveout_c.h" +#include "spar_debug.h" +float data_array[IVAS_MAX_NUM_CH][L_FRAME48k * 2]; +extern WAVEFILEOUT *spar_foa_enc_wav[3]; +#endif /*-------------------------------------------------------------------* * Local function prototypes @@ -326,12 +332,6 @@ ivas_error ivas_spar_enc( return error; } -#ifdef DEBUG_SPAR_FOA -extern FILE *fEvs_enc_in; -extern FILE *fFb_out[4]; -#endif - - /*-----------------------------------------------------------------------------------------* * Function ivas_spar_enc_get_windowed_fr() * @@ -443,7 +443,7 @@ static ivas_error ivas_spar_enc_process( ivas_total_brate = hEncoderConfig->ivas_total_brate; num_del_samples = pState->hFbMixer->fb_cfg->fb_latency; - input_frame = ( int16_t )( input_Fs / FRAMES_PER_SEC ); + input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); sba_order = min( hEncoderConfig->sba_order, IVAS_MAX_SBA_ORDER ); nchan_inp = ivas_sba_get_nchan_metadata( sba_order ); assert( nchan_inp <= hEncoderConfig->nchan_inp ); @@ -741,7 +741,7 @@ static ivas_error ivas_spar_enc_process( ivas_fb_mixer_get_in_out_mapping( pState->hFbMixer->fb_cfg, nchan_transport, ENC, remix_order_set[pState->hMdEnc->spar_md_cfg.remix_unmix_order], in_out_mixer_map ); -#ifdef DEBUG_SPAR_FOA +#ifdef DEBUG_SBA_MD_DUMP { static FILE *f_mat = 0; @@ -778,6 +778,21 @@ static ivas_error ivas_spar_enc_process( #endif ivas_fb_mixer_process( pState->hFbMixer, pState->hMdEnc->mixer_mat, p_pcm_tmp, input_frame, in_out_mixer_map ); +#ifdef DEBUG_SBA_AUDIO_DUMP + float largest_value; + for ( i = 0; i < nchan_transport; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + data_array[i][j] = p_pcm_tmp[i][j]; + } + } + largest_value = ivas_spar_dump_signal_wav( input_frame, data_array, nchan_transport, spar_foa_enc_wav[1] ); + if ( largest_value ) + { + fprintf( stderr, "\t In ivas_fb_mixer_process() largest clipped sample in dB %f \n", largest_value ); + } +#endif /* move delayed W into output buffer unless activeW operation*/ if ( pState->hFbMixer->fb_cfg->active_w_mixing == 0 ) @@ -802,6 +817,20 @@ static ivas_error ivas_spar_enc_process( push_next_indice( hMetaData, PCA_MODE_INACTIVE, 1 ); } } +#ifdef DEBUG_SBA_AUDIO_DUMP + for ( i = 0; i < nchan_inp; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + data_array[i][j] = data_f[i][j]; + } + } + largest_value = ivas_spar_dump_signal_wav( input_frame, data_array, nchan_inp, spar_foa_enc_wav[0] ); + if ( largest_value ) + { + fprintf( stderr, "\t In ivas_pca_enc() largest clipped sample in dB %f \n", largest_value ); + } +#endif #ifdef SPAR_HOA_DBG @@ -833,6 +862,21 @@ static ivas_error ivas_spar_enc_process( push_next_indice( hMetaData, 0, 1 ); } } +#ifdef DEBUG_SBA_AUDIO_DUMP + /* Dump audio signal after ivas_agc_enc_process */ + for ( i = 0; i < nchan_transport; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + data_array[i][j] = p_pcm_tmp[i][j]; + } + } + largest_value = ivas_spar_dump_signal_wav( input_frame, data_array, nchan_transport, spar_foa_enc_wav[2] ); + if ( largest_value ) + { + fprintf( stderr, "\t In ivas_agc_enc_process() largest clipped sample in dB %f \n", largest_value ); + } +#endif #ifdef DEBUG_SPAR_BYPASS_EVS_CODEC { @@ -870,53 +914,6 @@ static ivas_error ivas_spar_enc_process( } #endif -#ifdef DEBUG_SPAR_FOA - float tmp; - int16_t pcm; - - for ( j = 0; j < input_frame; j++ ) - { - for ( i = 0; i < nchan_transport; i++ ) - { - tmp = roundf( p_pcm_tmp[i][j] * PCM16_TO_FLT_FAC ); - pcm = ( tmp > MAX16B_FLT ) ? MAX16B : ( tmp < MIN16B_FLT ) ? MIN16B : (short) tmp; - dbgwrite( &pcm, sizeof( int16_t ), 1, 1, "dmx.raw" ); - } - } - - /* Plug evs i/p from Matlab */ - if ( fEvs_enc_in != NULL ) - { - /*printf("evs enc in file found\n");*/ - float tmp_in = 0; - int16_t diff[FOA_CHANNELS][L_FRAME48k], tmp16; - int16_t max_diff = 0; - int16_t abs_tol = 8; - - for ( i = 0; i < input_frame; i++ ) - { - for ( j = 0; j < nchan_transport; j++ ) - { - tmp = p_pcm_tmp[j][i]; - tmp = roundf( tmp * PCM16_TO_FLT_FAC ); - tmp16 = ( tmp > MAX16B_FLT ) ? MAX16B : ( tmp < MIN16B_FLT ) ? MIN16B : (int16_t) tmp; - fscanf( fEvs_enc_in, "%f\n", &tmp_in ); - p_pcm_tmp[j][i] = tmp_in; - - tmp = roundf( tmp_in * PCM16_TO_FLT_FAC ); - pcm = ( tmp > MAX16B_FLT ) ? MAX16B : ( tmp < MIN16B_FLT ) ? MIN16B : (int16_t) tmp; - diff[j][i] = (int16_t) abs( tmp16 - pcm ); - max_diff = max( max_diff, diff[j][i] ); - } - } - - if ( max_diff > abs_tol ) - { - IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "SPAR ENC fb mixer out mismatch, max diff = %d", max_diff ); - } - } -#endif - /*-----------------------------------------------------------------------------------------* * Re-order the dmx back to ACN/SN3D format *-----------------------------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index e2e0796aa4192c5618712292b3d2eb816dde8d04..f8fdc96edb6ce3aecee54e0868e99da0ba94eb75 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -41,15 +41,8 @@ #include "ivas_rom_com.h" #include #include "wmops.h" - - -#ifdef DEBUG_SPAR_FOA -extern FILE *fMd_data; -extern float max_diff; -extern int32_t dbg_frm_num; -extern int32_t dbg_band; -extern int32_t dbg_type; -int32_t frm = 0; +#ifdef DEBUG_SBA_MD_DUMP +extern int32_t frame; #endif @@ -58,11 +51,6 @@ int32_t frm = 0; *------------------------------------------------------------------------------------------*/ #define IVAS_MAX_MD_BYTES ( 1000 ) -#ifdef DEBUG_SPAR_FOA -#define MD_TOL ( 0.00015f ) -#define MD_TOL_MAX ( 0.012f ) -#endif - static const float pr_boost_range[2] = { 0.1f, 0.4f }; typedef enum ivas_strats_t @@ -593,13 +581,6 @@ ivas_error ivas_spar_md_enc_process( float Wscale[IVAS_MAX_NUM_BANDS]; ivas_spar_md_enc_state_t *pState = hMdEnc; int16_t num_quant_strats = pState->spar_md_cfg.num_quant_strats; -#ifdef DEBUG_SPAR_FOA - int16_t count; - int16_t ii, jj; - float C_re_mat[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - float abs_diff; - frm++; -#endif sba_order = min( hEncoderConfig->sba_order, IVAS_MAX_SBA_ORDER ); num_ch = ivas_sba_get_nchan_metadata( sba_order ); @@ -688,104 +669,10 @@ ivas_error ivas_spar_md_enc_process( } } } -#ifdef DEBUG_SPAR_FOA - count = 0; -#endif for ( b = 0; b < num_bands; b++ ) { ndm = pState->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; ndec = pState->spar_md_cfg.num_decorr_per_band[b * bands_bw]; -#ifdef DEBUG_SPAR_FOA - /* Plug Matlab values */ - - /* pred values */ - if ( fMd_data != NULL ) - { - /*printf("MD file found\n");*/ - float pred_mat; - for ( ii = 0; ii < num_ch - 1; ii++ ) - { - fscanf( fMd_data, "%f\n", &pred_mat ); - count++; - if ( qsi == 0 ) - { - if ( ( pState->spar_md.band_coeffs[b].pred_re[ii] > pState->spar_md_cfg.quant_strat[0].PR.max || pState->spar_md.band_coeffs[b].pred_re[ii] < pState->spar_md_cfg.quant_strat[0].PR.min ) && ( pred_mat > pState->spar_md_cfg.quant_strat[0].PR.max || pred_mat < pState->spar_md_cfg.quant_strat[0].PR.min ) ) - { - pState->spar_md.band_coeffs[b].pred_re[ii] = pred_mat; - } - else - { - abs_diff = fabsf( pState->spar_md.band_coeffs[b].pred_re[ii] - pred_mat ); - if ( abs_diff > max_diff ) - { - max_diff = abs_diff; - dbg_frm_num = frm; - dbg_band = b; - dbg_type = 0; - } - if ( abs_diff > MD_TOL_MAX ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "ERROR: pred coefffs Matlab MD & C MD values mismatch\n\n" ); - } - else - { - pState->spar_md.band_coeffs[b].pred_re[ii] = pred_mat; - } - } - } - } - } - - /* P values */ - if ( fMd_data != NULL ) - { - float P_re_mat; - for ( jj = 0; jj < num_ch - ndm; jj++ ) - { - fscanf( fMd_data, "%f\n", &P_re_mat ); - count++; - if ( ( pState->spar_md.band_coeffs[b].P_re[jj] > pState->spar_md_cfg.quant_strat[0].P_r.max || pState->spar_md.band_coeffs[b].P_re[jj] < pState->spar_md_cfg.quant_strat[0].P_r.min ) && ( P_re_mat > pState->spar_md_cfg.quant_strat[0].P_r.max || P_re_mat < pState->spar_md_cfg.quant_strat[0].P_r.min ) ) - { - pState->spar_md.band_coeffs[b].P_re[jj] = P_re_mat; - } - else - { - abs_diff = fabsf( pState->spar_md.band_coeffs[b].P_re[jj] - P_re_mat ); - if ( abs_diff > max_diff ) - { - max_diff = abs_diff; - dbg_frm_num = frm; - dbg_band = b; - dbg_type = 1; - } - if ( abs_diff > MD_TOL_MAX ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "ERROR: P mat Matlab MD & C MD values mismatch %f\n\n", abs_diff ); - } - else - { - pState->spar_md.band_coeffs[b].P_re[jj] = P_re_mat; - } - } - } - } - - /* C values */ - if ( fMd_data != NULL && ndm != 1 && ndm != num_ch ) - { - for ( jj = 0; jj < ndm - 1; jj++ ) - { - for ( ii = 0; ii < num_ch - ndm; ii++ ) - { - fscanf( fMd_data, "%f\n", &C_re_mat[ii][jj][b] ); - count++; -#ifdef SPAR_HOA_DBG - /*fprintf(stdout, "count: %d\n", count);*/ -#endif - } - } - } -#endif if ( dtx_vad == 1 ) { @@ -935,40 +822,6 @@ ivas_error ivas_spar_md_enc_process( #endif } -#ifdef DEBUG_SPAR_FOA - if ( fMd_data != NULL ) - { - for ( jj = 0; jj < nchan_transport - 1; jj++ ) - { - for ( ii = 0; ii < num_ch - nchan_transport; ii++ ) - { - if ( ( pState->spar_md.band_coeffs[b].C_re[ii][jj] > pState->spar_md_cfg.quant_strat[0].C.max || pState->spar_md.band_coeffs[b].C_re[ii][jj] < pState->spar_md_cfg.quant_strat[0].C.min ) && ( C_re_mat[ii][jj][b] > pState->spar_md_cfg.quant_strat[0].C.max || C_re_mat[ii][jj][b] < pState->spar_md_cfg.quant_strat[0].C.min ) ) - { - pState->spar_md.band_coeffs[b].C_re[ii][jj] = C_re_mat[ii][jj][b]; - } - else - { - abs_diff = (float) fabs( pState->spar_md.band_coeffs[b].C_re[ii][jj] - C_re_mat[ii][jj][b] ); - if ( abs_diff > max_diff ) - { - max_diff = abs_diff; - dbg_frm_num = frm; - dbg_band = b; - dbg_type = 2; - } - if ( abs_diff > MD_TOL_MAX ) - { - return ( IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "\n Matlab MD & C MD values mismatch" ) ); - } - else - { - pState->spar_md.band_coeffs[b].C_re[ii][jj] = C_re_mat[ii][jj][b]; - } - } - } - } - } -#endif ivas_quant_c_per_band( &pState->spar_md.band_coeffs[b], &pState->spar_md.band_coeffs_idx[b], &pState->spar_md_cfg.quant_strat[qsi], ndec, ndm ); #ifdef SPAR_HOA_DBG @@ -1110,6 +963,102 @@ ivas_error ivas_spar_md_enc_process( } fprintf( stdout, "\n" ); #endif +#ifdef DEBUG_SBA_MD_DUMP + { + char f_name[100]; + int16_t n_bands = 1, num_subframes = 1, num_block_groups = 1, num_elements = 1, byte_size = sizeof( int16_t ); + sprintf( f_name, "spar_qsi.bin" ); + ( frame == 0 ) ? dbgwrite( &n_bands, sizeof( nB ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + dbgwrite( &qsi, sizeof( int16_t ), 1, 1, f_name ); + sprintf( f_name, "spar_strat.bin" ); + ( frame == 0 ) ? dbgwrite( &n_bands, sizeof( nB ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + dbgwrite( &strat, sizeof( int16_t ), 1, 1, f_name ); + byte_size = sizeof( float ); + for ( b = 0; b < nB; b++ ) + { + sprintf( f_name, "spar_band_pred_coeffs.bin" ); + ( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false; + num_elements = num_ch - 1; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + for ( i = 0; i < num_ch - 1; i++ ) + { + dbgwrite( &pState->spar_md.band_coeffs[b].pred_re[i], sizeof( float ), 1, 1, f_name ); + } + sprintf( f_name, "spar_band_C_coeffs.bin" ); + ( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false; + num_elements = ndec * ( ndm - 1 ); + ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + for ( i = 0; i < ndec; i++ ) + { + for ( j = 0; j < ( ndm - 1 ); j++ ) + { + dbgwrite( &pState->spar_md.band_coeffs[b].C_re[i][j], sizeof( float ), 1, 1, f_name ); + } + } + sprintf( f_name, "spar_band_P_coeffs.bin" ); + ( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false; + num_elements = num_ch - ndm; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + for ( i = 0; i < num_ch - ndm; i++ ) + { + dbgwrite( &pState->spar_md.band_coeffs[b].P_re[i], sizeof( float ), 1, 1, f_name ); + } + sprintf( f_name, "spar_band_pred_coeffs_quant.bin" ); + ( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false; + num_elements = num_ch - 1; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + for ( i = 0; i < num_ch - 1; i++ ) + { + dbgwrite( &pState->spar_md.band_coeffs[b].pred_quant_re[i], sizeof( float ), 1, 1, f_name ); + } + sprintf( f_name, "spar_band_C_coeffs_quant.bin" ); + ( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false; + num_elements = ndec * ( ndm - 1 ); + ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + for ( i = 0; i < ndec; i++ ) + { + for ( j = 0; j < ( ndm - 1 ); j++ ) + { + dbgwrite( &pState->spar_md.band_coeffs[b].C_quant_re[i][j], sizeof( float ), 1, 1, f_name ); + } + } + sprintf( f_name, "spar_band_P_coeffs_quant.bin" ); + ( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false; + num_elements = num_ch - ndm; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; + ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + for ( i = 0; i < num_ch - ndm; i++ ) + { + dbgwrite( &pState->spar_md.band_coeffs[b].P_quant_re[i], sizeof( float ), 1, 1, f_name ); + } + } + } +#endif #ifdef DEBUG_SPAR_MD_TARGET_TUNING int16_t md_bits = hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == 1 ) ) ? 1 : 0 ); FILE *fp = fopen( "spar_md_bitrate.txt", "a" ); diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index c24467b228de5a84f56ab0850d69388595cb3815..369670e47cbaa60060546725925aad6e2fa97245 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -946,6 +946,51 @@ ivas_error IVAS_ENC_GetDelay( } +#ifdef DEBUG_SBA +/*---------------------------------------------------------------------* + * IVAS_ENC_GetNumInputChannels() + * + * + *---------------------------------------------------------------------*/ + +ivas_error IVAS_ENC_GetNumInputChannels( + const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ + int16_t *numInChannels /* o : number of input channels with current */ +) +{ + if ( !hIvasEnc->isConfigured ) + { + return IVAS_ERR_NOT_CONFIGURED; + } + + if ( numInChannels == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + *numInChannels = hIvasEnc->st_ivas->hEncoderConfig->nchan_inp; + + return IVAS_ERR_OK; +} + + +/*---------------------------------------------------------------------* + * getTransportChannel() + * + * + *---------------------------------------------------------------------*/ + +ivas_error getTransportChannel( + const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ + int16_t *no_channels_Transport /* o : number of transport channels */ +) +{ + *no_channels_Transport = hIvasEnc->st_ivas->nchan_transport; + return IVAS_ERR_OK; +} +#endif + + /*---------------------------------------------------------------------* * getInputBufferSize() * diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index dce4d6a0101938a868459ec949ad68d02d06d8d5..f6f32d9baa6d4e6b5e89b2e6b1e8ebc692fbfef5 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -288,6 +288,20 @@ ivas_error IVAS_ENC_GetDelay( int16_t *delay /* o : encoder delay */ ); +#ifdef DEBUG_SBA +/*! r: encoder error code */ +ivas_error IVAS_ENC_GetNumInputChannels( + const IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + int16_t *numInChannels /* o : number of input channels with current configuration */ +); + +/*! r: encoder error code */ +ivas_error getTransportChannel( + const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ + int16_t *no_channels_Transport /* o : number of transport channels */ +); +#endif + /*! r: encoder error code */ ivas_error IVAS_ENC_GetInputBufferSize( const IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ diff --git a/lib_util/tinywaveout_c.h b/lib_util/tinywaveout_c.h index c0cdf0812908b8d965d3b9780dff948f5d3db118..bfa69199a8122d0e1e26d2d9ba5dc0a8016540c2 100644 --- a/lib_util/tinywaveout_c.h +++ b/lib_util/tinywaveout_c.h @@ -241,8 +241,13 @@ static WAVEFILEOUT *CreateWav( return CreateBWF( fileName, sampleRate, numChannels, bps ); } +#ifdef DEBUG_SBA +#define MAX_PCM16 ( 32767 ) +#define MIN_PCM16 ( -32768 ) +#else const int16_t MAX_PCM16 = 32767; const int16_t MIN_PCM16 = -32768; +#endif static __inline int32_t CLIP_PCM16( int32_t sample, uint32_t *clipcount ) @@ -266,8 +271,13 @@ static __inline int32_t CLIP_PCM16( return tmp; } +#ifdef DEBUG_SBA +#define MAX_PCM24 ( 8388607 ) +#define MIN_PCM24 ( -8388608 ) +#else const int32_t MAX_PCM24 = 8388607; const int32_t MIN_PCM24 = -8388608; +#endif static __inline int32_t CLIP_PCM24( int32_t sample, uint32_t *clipcount ) diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c index d3eff0b87d7d0c1ef87cd5c69f0a1c76794179fe..d993405b1169dc591fe242b44fe3464af11683dd 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c @@ -509,7 +509,7 @@ ivas_result_t ivas_crend_parse_io_params( int argc, char **argv, ivas_crend_io_p int optional_args = 0; int check_output_format_set = 0; -#ifdef DEBUG_SPAR_FOA +#ifdef DEBUG_SBA fprintf( stderr, "Number of cmd line args: %d\n", argc ); fprintf( stderr, "CMD: " ); while ( i < argc ) diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_dec_parse_io.h b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_dec_parse_io.h index e72e36a3f41da9bfde9161b69f918b073ff04177..fe05a96f4fe24eb63f0a2591ecfb347a67bf8daa 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_dec_parse_io.h +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_dec_parse_io.h @@ -122,7 +122,7 @@ typedef struct ivas_dec_io_params_t #ifdef DEBUG_AGC FILE *agcBitstream; /* temporary */ #endif -#ifdef DEBUG_SPAR_FOA +#ifdef DEBUG_SBA int8_t file_tag[50]; int16_t dtx_on; #endif diff --git a/scripts/plot_meta_data.py b/scripts/plot_meta_data.py new file mode 100755 index 0000000000000000000000000000000000000000..62727f46db404adfaa2b953d14dacdd950d79aca --- /dev/null +++ b/scripts/plot_meta_data.py @@ -0,0 +1,214 @@ +#!/usr/bin/env python3 + +__license__ = \ +""" + (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. +""" + +__doc__ = \ +""" +Script to plot meta data. + +USAGE : plot_meta_data.py text_file containing the data + +The following format of C code is to be used for dumping metadata to plot using this script: + +#ifdef DEBUG_SBA + { + char f_name[100]; + int16_t num_bands = 1, num_subframes = 1, num_block_groups = 1, num_elements = 1, byte_size = sizeof(float); + int16_t idx1, idx2, idx3, idx4; + float dump; + sprintf(f_name, "dump_%d_%d_%d_%d.bin", num_bands, num_subframes, num_block_groups, num_elements); + (num_frames == 0) ? dbgwrite(&num_bands, sizeof(nB), 1, 1, f_name) : false; + (num_frames == 0) ? dbgwrite(&num_elements, sizeof(num_elements), 1, 1, f_name) : false; + (num_frames == 0) ? dbgwrite(&num_subframes, sizeof(num_subframes), 1, 1, f_name) : false; + (num_frames == 0) ? dbgwrite(&num_block_groups, sizeof(num_block_groups), 1, 1, f_name) : false; + (num_frames == 0) ? dbgwrite(&byte_size, sizeof(byte_size), 1, 1, f_name) : false; + for (idx1 = 0; idx1 < num_bands; idx1++) + { + for (idx2 = 0; idx2 < num_subframes; idx2++) + { + for (idx3 = 0; idx3 < num_block_groups; idx3++) + { + for (idx4 = 0; idx4 < num_elements; idx4++) + { + // Here MD needs to be dumped + // Following is an example + dump = 0.01 * num_frames + 1 * idx4 + 1 * idx1 + 0.5 * idx2 + 0.1 * idx3; + dbgwrite(&dump, sizeof(float), 1, 1, f_name); + } + } + } + } + } +#endif +""" + +import sys +import numpy as np +from bokeh.plotting import figure, show, output_file, save +from bokeh.layouts import column +from bokeh.palettes import Set3 + + +class metadata: + def __init__(self, binary_file_name: str): + self.binary_file_name = binary_file_name + self.metadata_name = binary_file_name.rsplit(".", 1)[0] + + def get_remaining_file_size(self, fp): + old_file_position = fp.tell() + # Moving the file handle to the end of the file + fp.seek(0, 2) + size = fp.tell() + remaining_size = size - old_file_position + fp.seek(old_file_position, 0) + return remaining_size + + def plot_data(self): + output_file(filename="plot_" + self.metadata_name + ".html") + x_axis_range = self.num_frames * self.num_subframes * self.num_block_groups + x_axis = np.arange(x_axis_range) / (self.num_subframes * self.num_block_groups) + fig = [0 for i in range(self.num_bands)] + for i in range(self.num_bands): + fig[i] = figure( + x_range=(-1, self.num_frames + 1), + title=self.metadata_name + "_band_no_" + str(i), + plot_width=3000, + ) + fig[i].xaxis.axis_label = "Frames" + fig[i].yaxis.axis_label = self.metadata_name + arr_max = np.array([]) + arr_min = np.array([]) + for j in range(self.num_elements): + value_3d = np.zeros( + ( + self.num_bands, + self.num_elements, + self.num_subframes * self.num_block_groups * self.num_frames, + ) + ) + value_3d = np.reshape( + self.value_mat, + ( + self.num_bands, + self.num_elements, + self.num_subframes * self.num_block_groups * self.num_frames, + ), + ) + arr_max = np.append(arr_max, [np.amax(value_3d[i][j])]) + arr_min = np.append(arr_min, [np.amin(value_3d[i][j])]) + fig[i].line( + x_axis[:x_axis_range], + value_3d[i][j], + line_width=2, + color=Set3[max(self.num_elements, 3)][j], + ) + fig[i].hex( + x_axis[:x_axis_range], + value_3d[i][j], + size=7, + fill_color=Set3[max(self.num_elements, 3)][j], + color="red", + legend_label="Element " + str(j), + ) + fig[i].y_range.start = np.amin(arr_min) - 0.1 + fig[i].y_range.end = np.amax(arr_max) + 0.1 + fig[i].legend.location = "top_right" + fig[i].legend.title = "Legends" + show(column(fig)) + save(fig) + return + + def read_meta_data(self): + with open(self.binary_file_name, "rb") as f: + self.num_bands = int.from_bytes(f.read(2), byteorder="little") + self.num_elements = int.from_bytes(f.read(2), byteorder="little") + if self.num_elements == 0: + print("No MD is there to dump. Exiting!") + return + self.num_subframes = int.from_bytes(f.read(2), byteorder="little") + self.num_block_groups = int.from_bytes(f.read(2), byteorder="little") + self.byte_size = int.from_bytes(f.read(2), byteorder="little") + if self.byte_size == 2: + dtype = "uint16" + else: + dtype = "f" + + rem_size = self.get_remaining_file_size(f) + self.num_frames = rem_size // ( + self.num_bands + * self.num_elements + * self.num_subframes + * self.num_block_groups + * self.byte_size + ) + + # Matrix shape [ num_bands [ num_elements [ num_frames [ num_subframes [ num_block_groups ] ] ] ] ] + self.value_mat = np.zeros( + ( + self.num_bands, + self.num_elements, + self.num_frames, + self.num_subframes, + self.num_block_groups, + ) + ) + + num = np.frombuffer(f.read(self.byte_size), dtype=dtype) + for x in range(self.num_frames): + for i in range(self.num_bands): + for j in range(self.num_subframes): + for k in range(self.num_block_groups): + for l in range(self.num_elements): + self.value_mat[i][l][x][j][k] = num + num = np.frombuffer(f.read(self.byte_size), dtype=dtype) + self.plot_data() + return + + +def main(argv): + if len(argv) < 2: + print(__doc__) + return 1 + script = metadata(*argv[1:]) + script.read_meta_data() + return 0 + + +if __name__ == "__main__": + if sys.version_info[0] < 3 or sys.version_info[1] < 7: + print( + "Minimum requirement is Python 3.7, currently running Python {}.{}".format( + sys.version_info[0], sys.version_info[1] + ) + ) + exit() + sys.exit(main(sys.argv)) \ No newline at end of file