From 198d7cb3ef8b15b440605ce4be2b8b5c2319767d Mon Sep 17 00:00:00 2001 From: Lauros Pajunen Date: Wed, 22 Feb 2023 16:41:42 +0200 Subject: [PATCH 1/3] Fix of MASA audio and meta asynchrony of issue #350 --- apps/decoder.c | 22 +++++ lib_com/common_api_types.h | 4 + lib_com/delay_comp.c | 14 +++ lib_com/ivas_cnst.h | 8 ++ lib_com/options.h | 1 + lib_dec/ivas_dirac_dec.c | 91 ++++++++++++++++++ lib_dec/ivas_masa_dec.c | 156 +++++++++++++++++++++++++++++++ lib_dec/ivas_stat_dec.h | 18 ++++ lib_dec/lib_dec.c | 10 +- lib_dec/lib_dec.h | 8 +- lib_enc/ivas_masa_enc.c | 13 +++ lib_enc/ivas_stat_enc.h | 2 + lib_util/masa_file_writer.c | 177 ++++++++++++++++++++++++++++++++++-- lib_util/masa_file_writer.h | 15 ++- 14 files changed, 528 insertions(+), 11 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 1d991b8ad3..ca37696914 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1309,15 +1309,24 @@ static ivas_error initOnFirstGoodFrame( /* If outputting MASA, open output file and write metadata for initial bad frames */ else if ( *pBsFormat == IVAS_DEC_BS_MASA ) { +#ifdef FIX_350_MASA_DELAY_COMP + if ( ( error = MasaFileWriter_open( arg.outputWavFilename, arg.delayCompensationEnabled, ppMasaWriter ) ) != IVAS_ERR_OK ) +#else if ( ( error = MasaFileWriter_open( arg.outputWavFilename, ppMasaWriter ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nError: Error opening MASA decoded metadata file %s\n", MasaFileWriter_getFilePath( *ppMasaWriter ) ); return error; } /* Duplicate good first frame metadata to fill the beginning of stream. */ +#ifdef FIX_350_MASA_DELAY_COMP + MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta = NULL; + if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta ) ) != IVAS_ERR_OK ) +#else IVAS_MASA_QMETADATA_HANDLE qMetadata = NULL; if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &qMetadata ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nError in IVAS_DEC_GetMasaMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) ); return error; @@ -1325,7 +1334,11 @@ static ivas_error initOnFirstGoodFrame( for ( int16_t j = 0; j < numInitialBadFrames; ++j ) { +#ifdef FIX_350_MASA_DELAY_COMP + if ( ( error = MasaFileWriter_writeFrame( *ppMasaWriter, hMasaExtOutMeta ) ) != IVAS_ERR_OK ) +#else if ( ( error = MasaFileWriter_writeFrame( *ppMasaWriter, qMetadata ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nError writing MASA metadata to file: %s\n", MasaFileWriter_getFilePath( *ppMasaWriter ) ); return error; @@ -1546,14 +1559,23 @@ static ivas_error decodeG192( } else if ( bsFormat == IVAS_DEC_BS_MASA ) { +#ifdef FIX_350_MASA_DELAY_COMP + MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta; + if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta ) ) != IVAS_ERR_OK ) +#else IVAS_MASA_QMETADATA_HANDLE qMetadata; if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &qMetadata ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nError in IVAS_DEC_GetMasaMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } +#ifdef FIX_350_MASA_DELAY_COMP + if ( ( error = MasaFileWriter_writeFrame( masaWriter, hMasaExtOutMeta ) ) != IVAS_ERR_OK ) +#else if ( ( error = MasaFileWriter_writeFrame( masaWriter, qMetadata ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nError writing MASA metadata to file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); goto cleanup; diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index d03a0b7f81..85a730480b 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -86,7 +86,11 @@ typedef struct } IVAS_QUATERNION; typedef struct ivas_masa_metadata_frame_struct *IVAS_MASA_METADATA_HANDLE; +#ifdef FIX_350_MASA_DELAY_COMP +typedef struct ivas_masa_decoder_ext_out_meta_struct *MASA_DECODER_EXT_OUT_META_HANDLE; +#else typedef struct ivas_masa_qmetadata_frame_struct *IVAS_MASA_QMETADATA_HANDLE; +#endif typedef struct TDREND_HRFILT_FiltSet_struct *IVAS_DEC_HRTF_HANDLE; typedef struct ivas_hrtfs_crend_structure *IVAS_DEC_HRTF_CREND_HANDLE; diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index 194b4b2919..e9db7b80fc 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -69,6 +69,13 @@ int32_t get_delay( else /* IVAS */ { delay = IVAS_ENC_DELAY_NS; + +#ifdef FIX_350_MASA_DELAY_COMP + if ( ivas_format == MASA_FORMAT ) + { + delay = 0; /* All delay is compensated in the decoder with MASA */ + } +#endif } if ( ivas_format == SBA_FORMAT ) @@ -102,6 +109,13 @@ int32_t get_delay( /* compensate for binauralization delay */ delay += binaural_latency_ns; + +#ifdef FIX_350_MASA_DELAY_COMP + if ( ivas_format == MASA_FORMAT ) + { + delay += IVAS_ENC_DELAY_NS; /* Compensate also the encoder delay in the decoder with MASA */ + } +#endif } } diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 09134774c0..f839b7836a 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -935,6 +935,10 @@ typedef enum #define DELAY_DIRAC_SPAR_ENC_CMP_NS 500000L /* here we may set the 24 samples (at 48 kHz) additional delay to something else, leave as is for now*/ #define DELAY_DIRAC_PARAM_DEC_SFR 2 /* Delay to be compensation for DirAC parameters in the decoder (subframes) */ +#ifdef FIX_350_MASA_DELAY_COMP +#define DELAY_MASA_PARAM_DEC_SFR 2 /* Delay to be compensation for MASA parameters in the decoder (subframes) */ +#endif + #define DIRAC_SLOT_NS 1250000L /* time duration of a time slot, 1.25ms (==DELAY_RENERER_NS/MAX_PARAM_SPATIAL_SUBFRAMES) */ #define DIRAC_SLOT_ENC_NS 5000000L @@ -1106,7 +1110,11 @@ enum #define MASA_MAXIMUM_CODING_SUBBANDS 24 #define MASA_MAXIMUM_DIRECTIONS 2 #define MASA_MAX_TRANSPORT_CHANNELS 2 + +#ifndef FIX_350_MASA_DELAY_COMP #define MASA_ENC_DELAY_SLOTS 7 +#endif + #define MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS 5 #define MASA_DELTA_AZI_DCT0 30 diff --git a/lib_com/options.h b/lib_com/options.h index 4ccaf4bdaa..a8472eccfb 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -180,6 +180,7 @@ #define SMOOTH_WITH_TRANS_DET #endif +#define FIX_350_MASA_DELAY_COMP /* Nokia: Issue 350: MASA audio/meta delay compensation */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index f3090415ae..2aaf9d9286 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -776,10 +776,22 @@ ivas_error ivas_dirac_dec_config( hDirAC->dirac_read_idx = 0; hDirAC->spar_to_dirac_write_idx = 0; +#ifdef FIX_350_MASA_DELAY_COMP + if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + { + hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; + } + else if ( st_ivas->ivas_format == MASA_FORMAT ) + { + hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; + hDirAC->dirac_bs_md_write_idx = DELAY_MASA_PARAM_DEC_SFR; + } +#else if ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) { hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; } +#endif else { int16_t num_slots_in_subfr; @@ -1512,8 +1524,45 @@ void ivas_qmetadata_to_dirac( if ( hMasa != NULL && ivas_total_brate > IVAS_SID_5k2 ) { +#ifdef FIX_350_MASA_DELAY_COMP + int16_t meta_write_index; band_mapping = hMasa->data.band_mapping; + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) + { + meta_write_index = ( hDirAC->dirac_bs_md_write_idx + block ) % hDirAC->dirac_md_buffer_length; + + for ( band = 0; band < hMasa->config.numCodingBands; ++band ) + { + for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) + { + hDirAC->azimuth[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block]; + hDirAC->elevation[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block]; + hDirAC->energy_ratio1[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block]; + hDirAC->diffuseness_vector[meta_write_index][b] = 1.0f - q_direction->band_data[band].energy_ratio[block]; + + if ( q_direction->coherence_band_data != NULL ) + { + hDirAC->spreadCoherence[meta_write_index][b] = q_direction->coherence_band_data[band].spread_coherence[block] / 255.0f; + } + else + { + hDirAC->spreadCoherence[meta_write_index][b] = 0.0f; + } + + if ( hQMetaData->surcoh_band_data != NULL ) + { + hDirAC->surroundingCoherence[meta_write_index][b] = hQMetaData->surcoh_band_data[band].surround_coherence[block] / 255.0f; + } + else + { + hDirAC->surroundingCoherence[meta_write_index][b] = 0.0f; + } + } + } + } +#else + band_mapping = hMasa->data.band_mapping; for ( band = 0; band < hMasa->config.numCodingBands; ++band ) { for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) @@ -1545,10 +1594,37 @@ void ivas_qmetadata_to_dirac( } } } +#endif if ( hQMetaData->no_directions == 2 ) { q_direction = &( hQMetaData->q_direction[1] ); +#ifdef FIX_350_MASA_DELAY_COMP + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) + { + meta_write_index = ( hDirAC->dirac_bs_md_write_idx + block ) % hDirAC->dirac_md_buffer_length; + + for ( band = 0; band < hMasa->config.numCodingBands; ++band ) + { + for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) + { + hDirAC->azimuth2[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block]; + hDirAC->elevation2[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block]; + hDirAC->energy_ratio2[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block]; + hDirAC->diffuseness_vector[meta_write_index][b] -= q_direction->band_data[band].energy_ratio[block]; + + if ( q_direction->coherence_band_data != NULL ) + { + hDirAC->spreadCoherence2[meta_write_index][b] = q_direction->coherence_band_data[band].spread_coherence[block] / 255.0f; + } + else + { + hDirAC->spreadCoherence2[meta_write_index][b] = 0.0f; + } + } + } + } +#else for ( band = 0; band < hMasa->config.numCodingBands; ++band ) { for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) @@ -1571,7 +1647,22 @@ void ivas_qmetadata_to_dirac( } } } +#endif + } +#ifdef FIX_350_MASA_DELAY_COMP + else if ( hDirAC->azimuth2 != NULL && hDirAC->elevation2 != NULL && hDirAC->energy_ratio2 != NULL && hDirAC->spreadCoherence2 != NULL ) + { + /* zero out old dir2 data */ + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) + { + meta_write_index = ( hDirAC->dirac_bs_md_write_idx + block ) % hDirAC->dirac_md_buffer_length; + set_s( hDirAC->azimuth2[meta_write_index], 0, hDirAC->num_freq_bands ); + set_s( hDirAC->elevation2[meta_write_index], 0, hDirAC->num_freq_bands ); + set_zero( hDirAC->energy_ratio2[meta_write_index], hDirAC->num_freq_bands ); + set_zero( hDirAC->spreadCoherence2[meta_write_index], hDirAC->num_freq_bands ); + } } +#endif } else /* SBA mode/SID/Zero frame*/ { diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 18d42cb910..5803a2467e 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -48,6 +48,9 @@ * Local constants *-----------------------------------------------------------------------*/ #define SPAR_META_DELAY_SUBFRAMES 2 /* Number of subframes to delay the SPAR metadata */ +#ifdef FIX_350_MASA_DELAY_COMP +#define SPH_IDX_FRONT ( MASA_NO_POINTS_EQUATOR / 2 ) /* Spherical index corresponding to front direction for setting as default value */ +#endif /*-----------------------------------------------------------------------* * Local function prototypes @@ -57,6 +60,9 @@ static int16_t quantize_theta( float x, int16_t no_cb, float *xhat ); static uint16_t index_theta_phi_16( float theta, float phi, SPHERICAL_GRID_DATA *Sph_Grid16 ); static int16_t quantize_phi_masa( float phi, int16_t flag_delta, float *phi_hat, const int16_t n ); static void index_16bits( IVAS_QMETADATA_HANDLE hQMetaData, SPHERICAL_GRID_DATA *Sph_Grid16 ); +#ifdef FIX_350_MASA_DELAY_COMP +static void create_masa_ext_out_meta( MASA_DECODER *hMasa, IVAS_QMETADATA_HANDLE hQMetaData, const int16_t nchan_transport ); +#endif static void replicate_subframes( IVAS_QMETADATA_HANDLE hQMetaData ); @@ -306,6 +312,12 @@ ivas_error ivas_masa_decode( } } +#ifdef FIX_350_MASA_DELAY_COMP + if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) + { + create_masa_ext_out_meta( hMasa, hQMetaData, st_ivas->nchan_transport ); + } +#endif return error /* *nb_bits_read*/; } @@ -339,10 +351,16 @@ ivas_error ivas_masa_dec_open( { hMasa->data.sph_grid16 = (SPHERICAL_GRID_DATA *) malloc( sizeof( SPHERICAL_GRID_DATA ) ); generate_gridEq( hMasa->data.sph_grid16 ); +#ifdef FIX_350_MASA_DELAY_COMP + hMasa->data.extOutMeta = (MASA_DECODER_EXT_OUT_META *) malloc( sizeof( MASA_DECODER_EXT_OUT_META ) ); +#endif } else { hMasa->data.sph_grid16 = NULL; +#ifdef FIX_350_MASA_DELAY_COMP + hMasa->data.extOutMeta = NULL; +#endif } if ( st_ivas->mc_mode == MC_MODE_MCMASA ) @@ -377,6 +395,13 @@ void ivas_masa_dec_close( hMasa->data.sph_grid16 = NULL; } +#ifdef FIX_350_MASA_DELAY_COMP + if ( hMasa->data.extOutMeta != NULL ) + { + free( hMasa->data.extOutMeta ); + hMasa->data.extOutMeta = NULL; + } +#endif if ( hMasa->hMasaLfeSynth != NULL ) { if ( hMasa->hMasaLfeSynth->lfeSynthRingBuffer != NULL ) @@ -1357,3 +1382,134 @@ static void compute_foa_cov_matrix( return; } + +#ifdef FIX_350_MASA_DELAY_COMP +static void create_masa_ext_out_meta( MASA_DECODER *hMasa, IVAS_QMETADATA_HANDLE hQMetaData, const int16_t nchan_transport ) +{ + const uint8_t ivasmasaFormatDescriptor[8] = { 0x49, 0x56, 0x41, 0x53, 0x4D, 0x41, 0x53, 0x41 }; /* "IVASMASA" */ + int16_t i, sf, b_old, b_new, dir; + MASA_DECRIPTIVE_META *descMeta; + int16_t *bandMap; + uint8_t numCodingBands; + uint8_t numDirections; + MASA_DECODER_EXT_OUT_META *extOutMeta; + + numDirections = hMasa->config.numberOfDirections; + numCodingBands = hMasa->config.numCodingBands; + bandMap = hMasa->data.band_mapping; + extOutMeta = hMasa->data.extOutMeta; + descMeta = &hMasa->data.extOutMeta->descriptiveMeta; + + /* Construct descriptive meta */ + for ( i = 0; i < 8; i++ ) + { + descMeta->formatDescriptor[i] = ivasmasaFormatDescriptor[i]; + } + descMeta->numberOfDirections = numDirections - 1; + descMeta->numberOfChannels = (uint8_t) ( nchan_transport - 1 ); + /* Following correspond to "unknown" values until transmission is implemented */ + descMeta->sourceFormat = 0x0u; + descMeta->transportDefinition = 0x0u; + descMeta->channelAngle = 0x0u; + descMeta->channelDistance = 0x0u; + descMeta->channelLayout = 0x0u; + + /* Construct spatial metadata from qmetadata */ + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + for ( dir = 0; dir < numDirections; dir++ ) + { + /* Spherical index */ + for ( b_old = 0; b_old < numCodingBands; b_old++ ) + { + for ( b_new = bandMap[b_old]; b_new < bandMap[b_old + 1]; b_new++ ) + { + extOutMeta->directionIndex[dir][sf][b_new] = hQMetaData->q_direction[dir].band_data[b_old].spherical_index[sf]; + } + } + + /* Direct-to-total ratio */ + for ( b_old = 0; b_old < numCodingBands; b_old++ ) + { + for ( b_new = bandMap[b_old]; b_new < bandMap[b_old + 1]; b_new++ ) + { + extOutMeta->directToTotalRatio[dir][sf][b_new] = (uint8_t) floorf( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio[sf] * UINT8_MAX ); + } + } + + /* Spread coherence */ + if ( hQMetaData->q_direction[dir].coherence_band_data != NULL ) + { + for ( b_old = 0; b_old < numCodingBands; b_old++ ) + { + for ( b_new = bandMap[b_old]; b_new < bandMap[b_old + 1]; b_new++ ) + { + extOutMeta->spreadCoherence[dir][sf][b_new] = hQMetaData->q_direction[dir].coherence_band_data[b_old].spread_coherence[sf]; + } + } + } + else + { + for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + extOutMeta->spreadCoherence[dir][sf][i] = 0; + } + } + } + + /* Fill second direction with zero energy data for EXT output */ + if ( numDirections == 1 ) + { + for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + extOutMeta->directionIndex[1][sf][i] = SPH_IDX_FRONT; + } + + for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + extOutMeta->directToTotalRatio[1][sf][i] = 0; + } + + for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + extOutMeta->spreadCoherence[1][sf][i] = 0; + } + } + + /* Common spatial meta */ + /* Diffuse-to-total ratio = 1 - sum(direct-to-total ratios) */ + for ( b_old = 0; b_old < numCodingBands; b_old++ ) + { + for ( b_new = bandMap[b_old]; b_new < bandMap[b_old + 1]; b_new++ ) + { + extOutMeta->diffuseToTotalRatio[sf][b_new] = UINT8_MAX; + for ( dir = 0; dir < numDirections; dir++ ) + { + extOutMeta->diffuseToTotalRatio[sf][b_new] -= (uint8_t) floorf( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio[sf] * UINT8_MAX ); + } + } + } + + /* Surround coherence */ + if ( hQMetaData->surcoh_band_data != NULL ) + { + for ( b_old = 0; b_old < numCodingBands; b_old++ ) + { + for ( b_new = bandMap[b_old]; b_new < bandMap[b_old + 1]; b_new++ ) + { + extOutMeta->surroundCoherence[sf][b_new] = hQMetaData->surcoh_band_data[b_old].surround_coherence[sf]; + } + } + } + else + { + for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + extOutMeta->surroundCoherence[sf][i] = 0; + } + } + } + + return; +} +#endif diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 1ceba1e3fd..1d5200e666 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1098,11 +1098,29 @@ typedef struct ivas_mcmasa_lfe_synth_struct } MCMASA_LFE_SYNTH_DATA, *MCMASA_LFE_SYNTH_DATA_HANDLE; +#ifdef FIX_350_MASA_DELAY_COMP +typedef struct ivas_masa_decoder_ext_out_meta_struct +{ + MASA_DECRIPTIVE_META descriptiveMeta; + + uint16_t directionIndex[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + uint8_t directToTotalRatio[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + uint8_t spreadCoherence[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + + uint8_t surroundCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + uint8_t diffuseToTotalRatio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + +} MASA_DECODER_EXT_OUT_META; +#endif + typedef struct ivas_masa_decoder_data_struct { int16_t band_mapping[MASA_FREQUENCY_BANDS + 1]; SPHERICAL_GRID_DATA *sph_grid16; +#ifdef FIX_350_MASA_DELAY_COMP + MASA_DECODER_EXT_OUT_META *extOutMeta; +#endif float dir_decode_quality; } MASA_DECODER_DATA; diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index a1fee7f0fd..2ccda3457c 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -857,8 +857,12 @@ ivas_error IVAS_DEC_GetObjectMetadata( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetMasaMetadata( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ +#ifdef FIX_350_MASA_DELAY_COMP + MASA_DECODER_EXT_OUT_META_HANDLE *hMasaExtOutMeta /* o : pointer to handle, which will be set to point to metadata from the most recently decoded frame */ +#else IVAS_MASA_QMETADATA_HANDLE *hMasaMetadata /* o : pointer to handle, which will be set to point to metadata from the most recently decoded frame */ +#endif ) { if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) @@ -871,7 +875,11 @@ ivas_error IVAS_DEC_GetMasaMetadata( return IVAS_ERR_WRONG_MODE; } +#ifdef FIX_350_MASA_DELAY_COMP + *hMasaExtOutMeta = hIvasDec->st_ivas->hMasa->data.extOutMeta; +#else *hMasaMetadata = hIvasDec->st_ivas->hQMetaData; +#endif return IVAS_ERR_OK; } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index d3035af0b5..3917286c49 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -170,8 +170,12 @@ ivas_error IVAS_DEC_GetObjectMetadata( /*! r: error code */ ivas_error IVAS_DEC_GetMasaMetadata( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - IVAS_MASA_QMETADATA_HANDLE *hMasaMetadata /* o : pointer to handle, which will be set to point to metadata from the most recently decoded frame */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ +#ifdef FIX_350_MASA_DELAY_COMP + MASA_DECODER_EXT_OUT_META_HANDLE *hMasaExtOutMeta /* o : pointer to handle, which will be set to point to metadata from the most recently decoded frame */ +#else + IVAS_MASA_QMETADATA_HANDLE *hMasaMetadata /* o : pointer to handle, which will be set to point to metadata from the most recently decoded frame */ +#endif ); /*! r: error code */ diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index f358a8ba2e..006b6f4273 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -119,6 +119,7 @@ ivas_error ivas_masa_enc_open( mvs2s( DirAC_block_grouping, hMasa->config.block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); mvs2s( MASA_band_grouping_24, hMasa->config.band_grouping, MASA_FREQUENCY_BANDS + 1 ); +#ifndef FIX_350_MASA_DELAY_COMP if ( hEncoderConfig->ivas_format == MASA_FORMAT ) { for ( i = 0; i < st_ivas->nchan_transport; i++ ) @@ -127,6 +128,7 @@ ivas_error ivas_masa_enc_open( set_f( hMasa->data.delay_buffer[i], 0.0f, MASA_ENC_DELAY_SLOTS * CLDFB_NO_CHANNELS_MAX ); } } +#endif hMasa->data.onset_detector_1 = 0.0f; hMasa->data.onset_detector_2 = 0.0f; @@ -159,6 +161,7 @@ void ivas_masa_enc_close( deleteCldfb( &( hMasa->data.cldfbAnaEnc[i] ) ); } +#ifndef FIX_350_MASA_DELAY_COMP if ( ivas_format == MASA_FORMAT ) { for ( i = 0; i < nchan_transport; i++ ) @@ -167,6 +170,7 @@ void ivas_masa_enc_close( hMasa->data.delay_buffer[i] = NULL; } } +#endif free( hMasa ); @@ -397,6 +401,12 @@ void ivas_masa_estimate_energy( for ( ts = mrange[0]; ts < mrange[1]; ts++ ) { +#ifdef FIX_350_MASA_DELAY_COMP + for ( i = 0; i < nchan_transport; i++ ) + { + cldfbAnalysis_ts( &( data_f[i][l_ts * ts] ), Input_RealBuffer[i], Input_ImagBuffer[i], l_ts, hMasa->data.cldfbAnaEnc[i] ); + } +#else if ( ts < MASA_ENC_DELAY_SLOTS ) { for ( i = 0; i < nchan_transport; i++ ) @@ -411,6 +421,7 @@ void ivas_masa_estimate_energy( cldfbAnalysis_ts( &( data_f[i][l_ts * ( ts - MASA_ENC_DELAY_SLOTS )] ), Input_RealBuffer[i], Input_ImagBuffer[i], l_ts, hMasa->data.cldfbAnaEnc[i] ); } } +#endif for ( band_m_idx = 0; band_m_idx < MASA_FREQUENCY_BANDS; band_m_idx++ ) { @@ -438,10 +449,12 @@ void ivas_masa_estimate_energy( } } +#ifndef FIX_350_MASA_DELAY_COMP for ( i = 0; i < nchan_transport; i++ ) { mvr2r( &data_f[i][input_frame - MASA_ENC_DELAY_SLOTS * maxBin], &( hMasa->data.delay_buffer[i][0] ), MASA_ENC_DELAY_SLOTS * maxBin ); } +#endif return; } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 8a96430129..295141281f 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -743,7 +743,9 @@ typedef struct ivas_masa_encoder_data_struct float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; int16_t num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_ENC_CLDFB_INSTANCES]; +#ifndef FIX_350_MASA_DELAY_COMP float *delay_buffer[MASA_MAX_TRANSPORT_CHANNELS]; +#endif int16_t band_mapping[MASA_FREQUENCY_BANDS + 1]; uint8_t twoDirBands[MASA_FREQUENCY_BANDS]; float importanceWeight[MASA_FREQUENCY_BANDS]; diff --git a/lib_util/masa_file_writer.c b/lib_util/masa_file_writer.c index 3b4df4f1c9..079ef9238e 100644 --- a/lib_util/masa_file_writer.c +++ b/lib_util/masa_file_writer.c @@ -32,25 +32,44 @@ #include "masa_file_writer.h" #include "ivas_stat_com.h" +#ifdef FIX_350_MASA_DELAY_COMP +#include "ivas_stat_dec.h" +#endif #include "ivas_cnst.h" #include #include #include #include +#ifdef FIX_350_MASA_DELAY_COMP +typedef struct masaMetaDelayStorage +{ + MASA_DECRIPTIVE_META descriptiveMeta; + uint16_t directionIndex[MASA_MAXIMUM_DIRECTIONS][DELAY_MASA_PARAM_DEC_SFR][MASA_FREQUENCY_BANDS]; + uint8_t directToTotalRatio[MASA_MAXIMUM_DIRECTIONS][DELAY_MASA_PARAM_DEC_SFR][MASA_FREQUENCY_BANDS]; + uint8_t spreadCoherence[MASA_MAXIMUM_DIRECTIONS][DELAY_MASA_PARAM_DEC_SFR][MASA_FREQUENCY_BANDS]; + uint8_t surroundCoherence[DELAY_MASA_PARAM_DEC_SFR][MASA_FREQUENCY_BANDS]; + uint8_t diffuseToTotalRatio[DELAY_MASA_PARAM_DEC_SFR][MASA_FREQUENCY_BANDS]; + +} MASA_META_DELAY_STORAGE; +#endif struct MasaFileWriter { FILE *file; char *file_path; +#ifdef FIX_350_MASA_DELAY_COMP + MASA_META_DELAY_STORAGE *delayStorage; +#endif }; /*-----------------------------------------------------------------------* * Local constants *-----------------------------------------------------------------------*/ +#ifndef FIX_350_MASA_DELAY_COMP #define SPH_IDX_FRONT ( MASA_NO_POINTS_EQUATOR / 2 ) /* Spherical index corresponding to front direction for setting as default value */ - +#endif /*-----------------------------------------------------------------------* * Local functions @@ -75,16 +94,76 @@ static void getExtMasaMetadataFileName( return; } +#ifdef FIX_350_MASA_DELAY_COMP +static void delayMasaMetadata( + MASA_DECODER_EXT_OUT_META_HANDLE extOutMeta, /* i/o : New input metadata which is inplace replaced with delayed metadata frame */ + MASA_META_DELAY_STORAGE *delayStorage /* i/o : Storage for 10 ms of metadata and related descriptive metadata */ +) +{ + int16_t dir, sf, band; + uint16_t temp; + uint8_t currentNumberOfDirections; + + /* Move meta to delay and output. Always use two directions as the metadata is prepared to contain zero energy second direction + * if there is 1dir meta. */ + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES - DELAY_MASA_PARAM_DEC_SFR; sf++ ) + { + for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + { + for ( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ ) + { + temp = delayStorage->directionIndex[dir][sf][band]; + delayStorage->directionIndex[dir][sf][band] = extOutMeta->directionIndex[dir][sf + DELAY_MASA_PARAM_DEC_SFR][band]; + extOutMeta->directionIndex[dir][sf + DELAY_MASA_PARAM_DEC_SFR][band] = extOutMeta->directionIndex[dir][sf][band]; + extOutMeta->directionIndex[dir][sf][band] = temp; + + temp = delayStorage->directToTotalRatio[dir][sf][band]; + delayStorage->directToTotalRatio[dir][sf][band] = extOutMeta->directToTotalRatio[dir][sf + DELAY_MASA_PARAM_DEC_SFR][band]; + extOutMeta->directToTotalRatio[dir][sf + DELAY_MASA_PARAM_DEC_SFR][band] = extOutMeta->directToTotalRatio[dir][sf][band]; + extOutMeta->directToTotalRatio[dir][sf][band] = temp; + + temp = delayStorage->spreadCoherence[dir][sf][band]; + delayStorage->spreadCoherence[dir][sf][band] = extOutMeta->spreadCoherence[dir][sf + DELAY_MASA_PARAM_DEC_SFR][band]; + extOutMeta->spreadCoherence[dir][sf + DELAY_MASA_PARAM_DEC_SFR][band] = extOutMeta->spreadCoherence[dir][sf][band]; + extOutMeta->spreadCoherence[dir][sf][band] = temp; + } + + temp = delayStorage->surroundCoherence[sf][band]; + delayStorage->surroundCoherence[sf][band] = extOutMeta->surroundCoherence[sf + DELAY_MASA_PARAM_DEC_SFR][band]; + extOutMeta->surroundCoherence[sf + DELAY_MASA_PARAM_DEC_SFR][band] = extOutMeta->surroundCoherence[sf][band]; + extOutMeta->surroundCoherence[sf][band] = temp; + + temp = delayStorage->diffuseToTotalRatio[sf][band]; + delayStorage->diffuseToTotalRatio[sf][band] = extOutMeta->diffuseToTotalRatio[sf + DELAY_MASA_PARAM_DEC_SFR][band]; + extOutMeta->diffuseToTotalRatio[sf + DELAY_MASA_PARAM_DEC_SFR][band] = extOutMeta->diffuseToTotalRatio[sf][band]; + extOutMeta->diffuseToTotalRatio[sf][band] = temp; + } + } + + /* Finalize descriptive meta by using new frame except for number of directions which is the larger of the two */ + currentNumberOfDirections = extOutMeta->descriptiveMeta.numberOfDirections; + if ( delayStorage->descriptiveMeta.numberOfDirections > extOutMeta->descriptiveMeta.numberOfDirections ) + { + extOutMeta->descriptiveMeta.numberOfDirections = delayStorage->descriptiveMeta.numberOfDirections; + } + delayStorage->descriptiveMeta.numberOfDirections = currentNumberOfDirections; + + return; +} +#endif /*---------------------------------------------------------------------* - * MasaFileWriter_writeFrame() + * MasaFileWriter_open() * * *---------------------------------------------------------------------*/ ivas_error MasaFileWriter_open( - const char *outputWavFilename, /* i : name of the output audio file */ - MasaFileWriter **masaWriter /* o : MasaFileWriter handle */ + const char *outputWavFilename, /* i : name of the output audio file */ +#ifdef FIX_350_MASA_DELAY_COMP + const bool delayCompensationEnabled, /* i : is delay compensation enabled */ +#endif + MasaFileWriter **masaWriter /* o : MasaFileWriter handle */ ) { MasaFileWriter *self; @@ -110,6 +189,13 @@ ivas_error MasaFileWriter_open( self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); strcpy( self->file_path, filePath ); +#ifdef FIX_350_MASA_DELAY_COMP + if ( !delayCompensationEnabled ) + { + self->delayStorage = calloc( sizeof(MASA_META_DELAY_STORAGE), 1 ); + } +#endif + *masaWriter = self; return IVAS_ERR_OK; @@ -123,8 +209,12 @@ ivas_error MasaFileWriter_open( *---------------------------------------------------------------------*/ ivas_error MasaFileWriter_writeFrame( - MasaFileWriter *self, /* i/o: MasaFileWriter handle */ - IVAS_MASA_QMETADATA_HANDLE hMasaQMetadata /* i/o: MASA qMetadata handle to be written */ + MasaFileWriter *self, /* i/o: MasaFileWriter handle */ +#ifdef FIX_350_MASA_DELAY_COMP + MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta /* i/o: MASA ext out meta handle to be written */ +#else + IVAS_MASA_QMETADATA_HANDLE hMasaQMetadata /* i/o: MASA qMetadata handle to be written */ +#endif ) { if ( self == NULL ) @@ -132,6 +222,11 @@ ivas_error MasaFileWriter_writeFrame( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef FIX_350_MASA_DELAY_COMP + uint16_t descMetaTemp = 0; + int16_t i, sf, dir, numDirections; + uint8_t writeTempOther[MASA_FREQUENCY_BANDS]; +#else const uint8_t ivasmasaFormatDescriptor[8] = { 0x49, 0x56, 0x41, 0x53, 0x4D, 0x41, 0x53, 0x41 }; /* "IVASMASA" */ uint16_t descMetaTemp = 0; int16_t i, sf, b_old, b_new, dir; @@ -147,7 +242,45 @@ ivas_error MasaFileWriter_writeFrame( numCodingBands = hMasaQMetadata->numCodingBands; bandMap = hMasaQMetadata->bandMap; nchan_transport = hMasaQMetadata->nchan_transport; +#endif + +#ifdef FIX_350_MASA_DELAY_COMP + /* If delay storage has been reserved, then we are in the normal mode for the decoder + * (i.e., no delay compensation for PCM) which means that metadata should be delayed + * by two subframes (10 ms). Descriptive metadata is a combined result. */ + if ( self->delayStorage ) + { + delayMasaMetadata( hMasaExtOutMeta, self->delayStorage ); + } + numDirections = hMasaExtOutMeta->descriptiveMeta.numberOfDirections + 1; + + if ( fwrite( &( hMasaExtOutMeta->descriptiveMeta.formatDescriptor ), sizeof( uint8_t ), 8, self->file ) != 8 ) + { + return IVAS_ERR_FAILED_FILE_WRITE; + } + + descMetaTemp += hMasaExtOutMeta->descriptiveMeta.numberOfDirections << 15u; + descMetaTemp += hMasaExtOutMeta->descriptiveMeta.numberOfChannels << 14u; + descMetaTemp += hMasaExtOutMeta->descriptiveMeta.sourceFormat << 12u; + if ( hMasaExtOutMeta->descriptiveMeta.sourceFormat == 0x0 || hMasaExtOutMeta->descriptiveMeta.sourceFormat == 0x1 ) + { + descMetaTemp += hMasaExtOutMeta->descriptiveMeta.transportDefinition << 9u; + descMetaTemp += hMasaExtOutMeta->descriptiveMeta.channelAngle << 6u; + descMetaTemp += hMasaExtOutMeta->descriptiveMeta.channelDistance; + } + else if ( hMasaExtOutMeta->descriptiveMeta.sourceFormat == 0x2 ) + { + descMetaTemp += hMasaExtOutMeta->descriptiveMeta.channelLayout << 9u; + /* 9 LSB remain at zero */ + } + else if ( hMasaExtOutMeta->descriptiveMeta.sourceFormat == 0x3 ) + { + descMetaTemp += hMasaExtOutMeta->descriptiveMeta.transportDefinition << 9u; + descMetaTemp += hMasaExtOutMeta->descriptiveMeta.channelAngle << 6u; + /* 6 LSB remain at zero */ + } +#else /* Construct descriptive meta */ for ( i = 0; i < 8; i++ ) { @@ -187,6 +320,7 @@ ivas_error MasaFileWriter_writeFrame( descMetaTemp += descMeta.channelAngle << 6u; /* 6 LSB remain at zero */ } +#endif if ( fwrite( &( descMetaTemp ), sizeof( uint16_t ), 1, self->file ) != 1 ) { @@ -198,6 +332,9 @@ ivas_error MasaFileWriter_writeFrame( for ( dir = 0; dir < numDirections; dir++ ) { /* Spherical index */ +#ifdef FIX_350_MASA_DELAY_COMP + if ( fwrite( hMasaExtOutMeta->directionIndex[dir][sf], sizeof( uint16_t ), MASA_FREQUENCY_BANDS, self->file ) != MASA_FREQUENCY_BANDS ) +#else for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) { writeTempIndex[i] = SPH_IDX_FRONT; @@ -212,11 +349,15 @@ ivas_error MasaFileWriter_writeFrame( } if ( fwrite( writeTempIndex, sizeof( uint16_t ), MASA_FREQUENCY_BANDS, self->file ) != MASA_FREQUENCY_BANDS ) +#endif { return IVAS_ERR_FAILED_FILE_WRITE; } /* Direct-to-total ratio */ +#ifdef FIX_350_MASA_DELAY_COMP + if ( fwrite( hMasaExtOutMeta->directToTotalRatio[dir][sf], sizeof( uint8_t ), MASA_FREQUENCY_BANDS, self->file ) != MASA_FREQUENCY_BANDS ) +#else for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) { writeTempOther[i] = 0; @@ -231,11 +372,15 @@ ivas_error MasaFileWriter_writeFrame( } if ( fwrite( writeTempOther, sizeof( uint8_t ), MASA_FREQUENCY_BANDS, self->file ) != MASA_FREQUENCY_BANDS ) +#endif { return IVAS_ERR_FAILED_FILE_WRITE; } /* Spread coherence */ +#ifdef FIX_350_MASA_DELAY_COMP + if ( fwrite( hMasaExtOutMeta->spreadCoherence[dir][sf], sizeof( uint8_t ), MASA_FREQUENCY_BANDS, self->file ) != MASA_FREQUENCY_BANDS ) +#else for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) { writeTempOther[i] = 0; @@ -253,6 +398,7 @@ ivas_error MasaFileWriter_writeFrame( } if ( fwrite( writeTempOther, sizeof( uint8_t ), MASA_FREQUENCY_BANDS, self->file ) != MASA_FREQUENCY_BANDS ) +#endif { return IVAS_ERR_FAILED_FILE_WRITE; } @@ -260,6 +406,9 @@ ivas_error MasaFileWriter_writeFrame( /* Common spatial meta */ /* Diffuse-to-total ratio = 1 - sum(direct-to-total ratios) */ +#ifdef FIX_350_MASA_DELAY_COMP + if ( fwrite( hMasaExtOutMeta->diffuseToTotalRatio[sf], sizeof( uint8_t ), MASA_FREQUENCY_BANDS, self->file ) != MASA_FREQUENCY_BANDS ) +#else for ( b_new = 0; b_new < MASA_FREQUENCY_BANDS; b_new++ ) { writeTempOther[b_new] = UINT8_MAX; @@ -278,11 +427,16 @@ ivas_error MasaFileWriter_writeFrame( } if ( fwrite( writeTempOther, sizeof( uint8_t ), MASA_FREQUENCY_BANDS, self->file ) != MASA_FREQUENCY_BANDS ) +#endif { return IVAS_ERR_FAILED_FILE_WRITE; } /* Surround coherence */ +#ifdef FIX_350_MASA_DELAY_COMP + if ( fwrite( hMasaExtOutMeta->surroundCoherence[sf], sizeof( uint8_t ), MASA_FREQUENCY_BANDS, self->file ) != MASA_FREQUENCY_BANDS ) +#else + /* Surround coherence */ for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) { writeTempOther[i] = 0; @@ -300,16 +454,24 @@ ivas_error MasaFileWriter_writeFrame( } if ( fwrite( writeTempOther, sizeof( uint8_t ), MASA_FREQUENCY_BANDS, self->file ) != MASA_FREQUENCY_BANDS ) +#endif { return IVAS_ERR_FAILED_FILE_WRITE; } /* Remainder-to-total ratio */ /* This is zero after codec */ +#ifdef FIX_350_MASA_DELAY_COMP + for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + writeTempOther[i] = 0u; + } +#else for ( b_new = 0; b_new < MASA_FREQUENCY_BANDS; b_new++ ) { writeTempOther[b_new] = 0u; } +#endif if ( fwrite( writeTempOther, sizeof( uint8_t ), MASA_FREQUENCY_BANDS, self->file ) != MASA_FREQUENCY_BANDS ) { @@ -338,6 +500,9 @@ void MasaFileWriter_close( fclose( ( *selfPtr )->file ); free( ( *selfPtr )->file_path ); +#ifdef FIX_350_MASA_DELAY_COMP + free( ( *selfPtr )->delayStorage ); +#endif free( *selfPtr ); *selfPtr = NULL; diff --git a/lib_util/masa_file_writer.h b/lib_util/masa_file_writer.h index 29b4dd1b3f..b440bb5e2e 100644 --- a/lib_util/masa_file_writer.h +++ b/lib_util/masa_file_writer.h @@ -34,6 +34,10 @@ #define IVAS_MASA_FILE_WRITER_H #include +#include "options.h" +#ifdef FIX_350_MASA_DELAY_COMP +#include +#endif #include "common_api_types.h" #include "ivas_error.h" @@ -43,12 +47,19 @@ typedef struct MasaFileWriter MasaFileWriter; ivas_error MasaFileWriter_open( const char *outputWavFilename, /* i : name of the output audio file */ - MasaFileWriter **masaWriter /* o : MasaFileWriter handle */ +#ifdef FIX_350_MASA_DELAY_COMP + const bool delayCompensationEnabled, /* i : is delay compensation enabled */ +#endif + MasaFileWriter **masaWriter /* o : MasaFileWriter handle */ ); ivas_error MasaFileWriter_writeFrame( - MasaFileWriter *self, /* i/o: MasaFileWriter handle */ + MasaFileWriter *self, /* i/o: MasaFileWriter handle */ +#ifdef FIX_350_MASA_DELAY_COMP + MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta /* i/o: MASA ext out meta handle to be written */ +#else IVAS_MASA_QMETADATA_HANDLE hMasaQMetadata /* i/o: MASA qMetadata handle to be written */ +#endif ); void MasaFileWriter_close( -- GitLab From 59ea3dba8bd581f3804f08a1e1bab4bdbebf6282 Mon Sep 17 00:00:00 2001 From: Lauros Pajunen Date: Wed, 22 Feb 2023 17:09:29 +0200 Subject: [PATCH 2/3] Run clang format --- lib_util/masa_file_writer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_util/masa_file_writer.c b/lib_util/masa_file_writer.c index 079ef9238e..5e1068b199 100644 --- a/lib_util/masa_file_writer.c +++ b/lib_util/masa_file_writer.c @@ -159,11 +159,11 @@ static void delayMasaMetadata( *---------------------------------------------------------------------*/ ivas_error MasaFileWriter_open( - const char *outputWavFilename, /* i : name of the output audio file */ + const char *outputWavFilename, /* i : name of the output audio file */ #ifdef FIX_350_MASA_DELAY_COMP const bool delayCompensationEnabled, /* i : is delay compensation enabled */ #endif - MasaFileWriter **masaWriter /* o : MasaFileWriter handle */ + MasaFileWriter **masaWriter /* o : MasaFileWriter handle */ ) { MasaFileWriter *self; @@ -192,7 +192,7 @@ ivas_error MasaFileWriter_open( #ifdef FIX_350_MASA_DELAY_COMP if ( !delayCompensationEnabled ) { - self->delayStorage = calloc( sizeof(MASA_META_DELAY_STORAGE), 1 ); + self->delayStorage = calloc( sizeof( MASA_META_DELAY_STORAGE ), 1 ); } #endif @@ -209,7 +209,7 @@ ivas_error MasaFileWriter_open( *---------------------------------------------------------------------*/ ivas_error MasaFileWriter_writeFrame( - MasaFileWriter *self, /* i/o: MasaFileWriter handle */ + MasaFileWriter *self, /* i/o: MasaFileWriter handle */ #ifdef FIX_350_MASA_DELAY_COMP MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta /* i/o: MASA ext out meta handle to be written */ #else -- GitLab From 604544d39530a20c9607816429806710d62b19e9 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Wed, 22 Feb 2023 16:37:18 +0100 Subject: [PATCH 3/3] fix the build-time warnings of unused parameters when the flag FIX_350_MASA_DELAY_COMP is active --- lib_com/ivas_prot.h | 5 ++++- lib_enc/ivas_init_enc.c | 4 ++++ lib_enc/ivas_masa_enc.c | 5 ++++- lib_enc/ivas_mcmasa_enc.c | 4 ++++ lib_enc/ivas_mct_enc.c | 8 ++++++++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 9a69f81882..972f5ecaa4 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4462,9 +4462,12 @@ ivas_error ivas_masa_enc_open( ); void ivas_masa_enc_close( - MASA_ENCODER_HANDLE hMasa, /* i/o: MASA metadata structure */ + MASA_ENCODER_HANDLE hMasa /* i/o: MASA metadata structure */ + #ifndef FIX_350_MASA_DELAY_COMP + , const int16_t nchan_transport, /* i : Number of transport channels */ const IVAS_FORMAT ivas_format /* i : IVAS format */ + #endif ); void ivas_masa_enc_reconfigure( diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 8995ebe92a..6a753847cf 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -974,7 +974,11 @@ void ivas_destroy_enc( /* MASA handle */ if ( st_ivas->hMasa != NULL ) { +#ifdef FIX_350_MASA_DELAY_COMP + ivas_masa_enc_close( st_ivas->hMasa ); +#else ivas_masa_enc_close( st_ivas->hMasa, st_ivas->nchan_transport, ivas_format ); +#endif st_ivas->hMasa = NULL; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 006b6f4273..0836afa3d1 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -149,9 +149,12 @@ ivas_error ivas_masa_enc_open( *-----------------------------------------------------------------------*/ void ivas_masa_enc_close( - MASA_ENCODER_HANDLE hMasa, /* i/o: MASA metadata structure */ + MASA_ENCODER_HANDLE hMasa /* i/o: MASA metadata structure */ +#ifndef FIX_350_MASA_DELAY_COMP + , const int16_t nchan_transport, /* i : Number of transport channels */ const IVAS_FORMAT ivas_format /* i : IVAS format */ +#endif ) { int16_t i; diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index e456cb3b70..a4affbe598 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -418,7 +418,11 @@ ivas_error ivas_mcmasa_enc_reconfig( /* bitrate changed, may need to do something */ /* brute-force solution: close McMASA and re-instantiate with new settings */ +#ifdef FIX_350_MASA_DELAY_COMP + ivas_masa_enc_close( st_ivas->hMasa ); +#else ivas_masa_enc_close( st_ivas->hMasa, st_ivas->nchan_transport, st_ivas->hEncoderConfig->ivas_format ); +#endif ivas_mcmasa_enc_close( st_ivas->hMcMasa, st_ivas->hEncoderConfig->input_Fs ); /* Determine if to separate some channels from the analysis */ diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 5da41e279e..fd8d1939b7 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -621,7 +621,11 @@ static ivas_error ivas_mc_enc_reconfig( if ( st_ivas->hMasa != NULL ) { +#ifdef FIX_350_MASA_DELAY_COMP + ivas_masa_enc_close( st_ivas->hMasa ); +#else ivas_masa_enc_close( st_ivas->hMasa, nchan_transport_old, MC_FORMAT ); +#endif st_ivas->hMasa = NULL; } @@ -654,7 +658,11 @@ static ivas_error ivas_mc_enc_reconfig( } if ( st_ivas->hMasa != NULL ) { +#ifdef FIX_350_MASA_DELAY_COMP + ivas_masa_enc_close( st_ivas->hMasa ); +#else ivas_masa_enc_close( st_ivas->hMasa, nchan_transport_old, MC_FORMAT ); +#endif st_ivas->hMasa = NULL; } -- GitLab