Commit a6fbbe88 authored by emerit's avatar emerit
Browse files

improve code

parent 1bed0f4c
Loading
Loading
Loading
Loading
+27 −27
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ hrtfPath = f'{ivasPath}scripts/binauralRenderer_interface/binaural_renderers_hrt
# brirFile = f'{hrtfPath}{hrtfName}+{brirName}.bin'
# brirFile = f'{hrtfPath}fastconv_{hrtfName}_{brirKern}.bin'
# brirFile = f'{hrtfPath}ivas_binaural_custom_48kHz.bin'
brirFiles = [f'ivas_binaural_custom_{fs}kHz', f'ivas_binaural_custom_no_optim_{fs}kHz', f'ivas_binaural_custom_fabian_hrir_{fs}kHz']
brirFiles = ['',f'ivas_binaural_{fs}kHz',f'ivas_binaural_custom_{fs}kHz', f'ivas_binaural_custom_no_optim_{fs}kHz', f'ivas_binaural_custom_fabian_hrir_{fs}kHz']
brirPaths = [f'{hrtfPath}{brirFiles[0]}.bin', f'{hrtfPath}{brirFiles[1]}.bin']
bitrates = [32, 80, 256]
# inFormats = ['mc 5_1', 'mc 7_1_4', 'sba 1', 'sba 2', 'sba 3']
@@ -52,38 +52,38 @@ if encode:
            subprocess.run(cmd,shell=True)

#Decode & Render
for b in bitrates:
    for f in inFormats:
        for brir in brirFiles:
            ivasFile = f'{bitPath}{files[f]}-{b}kbps.ivas'
            outFileBase = f'{outPath}{files[f]}-{b}kbps'
            # Decode and render binaural
            cmd = f'{ivasPath}{ivasDec} -hrtf {hrtfPath}{brir}.bin BINAURAL {fs} {ivasFile} {outFileBase}-dec-bin-{brir}.wav'
            subprocess.run(cmd,shell=True)

            # Decode and render binaural IR
            cmd = f'{ivasPath}{ivasDec} -hrtf {hrtfPath}{brir}.bin BINAURAL_ROOM_IR {fs} {ivasFile} {outFileBase}-dec-brir-{brir}.wav'
            subprocess.run(cmd,shell=True)

            # Decode and render binaural reverb
            cmd = f'{ivasPath}{ivasDec} -hrtf {hrtfPath}{brir}.bin BINAURAL_ROOM_REVERB {fs} {ivasFile} {outFileBase}-dec-rev-{brir}.wav'
            subprocess.run(cmd,shell=True)

            # Decode pass-through
            cmd = f'{ivasPath}{ivasDec} {outFormats[f]} {fs} {ivasFile} {outFileBase}-dec-ext.wav'
            subprocess.run(cmd,shell=True)

            # Render binaural
            cmd = f'{ivasPath}{ivasRend} -i {outFileBase}-dec-ext.wav -if {outFormats[f]} -o {outFileBase}-ext-bin-{brir}.wav -of BINAURAL -fs {fs} -hrtf {hrtfPath}{brir}.bin'
            subprocess.run(cmd,shell=True)

            # Render binaural IR
            cmd = f'{ivasPath}{ivasRend} -i {outFileBase}-dec-ext.wav -if {outFormats[f]} -o {outFileBase}-ext-brir-{brir}.wav -of BINAURAL_ROOM_IR -fs {fs} -hrtf {hrtfPath}{brir}.bin'
            subprocess.run(cmd,shell=True)

            # Render binaural reverb
            cmd = f'{ivasPath}{ivasRend} -i {outFileBase}-dec-ext.wav -if {outFormats[f]} -o {outFileBase}-ext-rev-{brir}.wav -of BINAURAL_ROOM_REVERB -fs {fs}'
            subprocess.run(cmd,shell=True)
# for b in bitrates:
#     for f in inFormats:
#         for brir in brirFiles:
#             ivasFile = f'{bitPath}{files[f]}-{b}kbps.ivas'
#             outFileBase = f'{outPath}{files[f]}-{b}kbps'
#             # Decode and render binaural
#             cmd = f'{ivasPath}{ivasDec} -hrtf {hrtfPath}{brir}.bin BINAURAL {fs} {ivasFile} {outFileBase}-dec-bin-{brir}.wav'
#             subprocess.run(cmd,shell=True)

#             # Decode and render binaural IR
#             cmd = f'{ivasPath}{ivasDec} -hrtf {hrtfPath}{brir}.bin BINAURAL_ROOM_IR {fs} {ivasFile} {outFileBase}-dec-brir-{brir}.wav'
#             subprocess.run(cmd,shell=True)

#             # Decode and render binaural reverb
#             cmd = f'{ivasPath}{ivasDec} -hrtf {hrtfPath}{brir}.bin BINAURAL_ROOM_REVERB {fs} {ivasFile} {outFileBase}-dec-rev-{brir}.wav'
#             subprocess.run(cmd,shell=True)

#             # Decode pass-through
#             cmd = f'{ivasPath}{ivasDec} {outFormats[f]} {fs} {ivasFile} {outFileBase}-dec-ext.wav'
#             subprocess.run(cmd,shell=True)

#             # Render binaural
#             cmd = f'{ivasPath}{ivasRend} -i {outFileBase}-dec-ext.wav -if {outFormats[f]} -o {outFileBase}-ext-bin-{brir}.wav -of BINAURAL -fs {fs} -hrtf {hrtfPath}{brir}.bin'
#             subprocess.run(cmd,shell=True)

#             # Render binaural IR
#             cmd = f'{ivasPath}{ivasRend} -i {outFileBase}-dec-ext.wav -if {outFormats[f]} -o {outFileBase}-ext-brir-{brir}.wav -of BINAURAL_ROOM_IR -fs {fs} -hrtf {hrtfPath}{brir}.bin'
#             subprocess.run(cmd,shell=True)

#             # Render binaural reverb
#             cmd = f'{ivasPath}{ivasRend} -i {outFileBase}-dec-ext.wav -if {outFormats[f]} -o {outFileBase}-ext-rev-{brir}.wav -of BINAURAL_ROOM_REVERB -fs {fs}'
#             subprocess.run(cmd,shell=True)
            
for f in inFormats:
    outFileBase = f'{outPath}{files[f]}'
+145 −42

File changed.

Preview size limit exceeded, changes collapsed.

+50 −12
Original line number Diff line number Diff line
@@ -466,7 +466,11 @@ static ivas_error DefaultBSplineModel(

    /* float parameters */
#ifdef FIX_1123_TDREN_16BIT_ROM
    model->elevKSeq_dyn = (float *) malloc( ( model->elevDim3 - 2 ) * sizeof( float ) );
    if ( ( model->elevKSeq_dyn = (float *) malloc( ( model->elevDim3 - 2 ) * sizeof( float ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
    }

    q_scale = powf( 2.f, -1.f * (float) defaultHRIR_rom_elevKSeq_Q );
    for ( j = 0; j < model->elevDim3 - 2; j++ )
    {
@@ -475,7 +479,11 @@ static ivas_error DefaultBSplineModel(
    model->elevKSeq = (const float *) model->elevKSeq_dyn;

    size_rom_table = sizeof( defaultHRIR_rom_elevBsShape ) / sizeof( int16_t );
    model->elevBsShape_dyn = (float *) malloc( size_rom_table * sizeof( float ) );
    if ( ( model->elevBsShape_dyn = (float *) malloc( size_rom_table * sizeof( float ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
    }

    q_scale = powf( 2.f, -1.f * (float) defaultHRIR_rom_elevBsShape_Q );
    for ( j = 0; j < size_rom_table; j++ )
    {
@@ -497,7 +505,10 @@ static ivas_error DefaultBSplineModel(
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
    }
    size_rom_table = sizeof( defaultHRIR_rom_azimBsShape ) / sizeof( int16_t );
    model->azimBsShape_dyn[0] = (float *) malloc( size_rom_table * sizeof( float ) );
    if ( ( model->azimBsShape_dyn[0] = (float *) malloc( size_rom_table * sizeof( float ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
    }
    q_scale = powf( 2.f, -1.f * (float) defaultHRIR_rom_azimBsShape_Q );
    for ( j = 0; j < size_rom_table; j++ )
    {
@@ -600,8 +611,14 @@ static ivas_error DefaultBSplineModel(
            break;
    }
#ifdef FIX_1123_TDREN_16BIT_ROM
    model->AlphaL_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) );
    model->AlphaR_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) );
    if ( ( model->AlphaL_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
    }
    if ( ( model->AlphaR_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
    }
    for ( j = 0; j < model->AlphaN * model->K; j++ )
    {
        model->AlphaL_dyn[j] = (float) alphaL_ptr[j] * q_scale_a;
@@ -615,8 +632,14 @@ static ivas_error DefaultBSplineModel(
#ifndef FIX_1123_TDREN_16BIT_ROM
    HRTF_energy_sections_precalc( model );
#endif
    model->EL_dyn = (float *) malloc( HRTF_MODEL_N_SECTIONS * model->AlphaN * sizeof( float ) );
    model->ER_dyn = (float *) malloc( HRTF_MODEL_N_SECTIONS * model->AlphaN * sizeof( float ) );
    if ( ( model->EL_dyn = (float *) malloc( HRTF_MODEL_N_SECTIONS * model->AlphaN * sizeof( float ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
    }
    if ( ( model->ER_dyn = (float *) malloc( HRTF_MODEL_N_SECTIONS * model->AlphaN * sizeof( float ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
    }
    for ( j = 0; j < HRTF_MODEL_N_SECTIONS * model->AlphaN; j++ )
    {
        model->EL_dyn[j] = (float) elL_ptr[j] * q_scale_e;
@@ -635,7 +658,10 @@ static ivas_error DefaultBSplineModel(
    modelITD->elevBsStart = defaultHRIR_rom_ITD_elevBsStart;

#ifdef FIX_1123_TDREN_16BIT_ROM
    modelITD->elevKSeq_dyn = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) );
    if ( ( modelITD->elevKSeq_dyn = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
    }
    q_scale = powf( 2.f, -1.f * (float) defaultHRIR_rom_ITD_elevKSeq_Q );
    for ( j = 0; j < modelITD->elevDim3 - 2; j++ )
    {
@@ -650,7 +676,10 @@ static ivas_error DefaultBSplineModel(
    modelITD->azimBsStart = defaultHRIR_rom_ITD_azimBsStart;

#ifdef FIX_1123_TDREN_16BIT_ROM
    modelITD->azimKSeq_dyn = (float *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( float ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */
    if ( ( modelITD->azimKSeq_dyn = (float *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( float ) ) ) == NULL ) /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
    }
    q_scale = powf( 2.f, -1.f * (float) defaultHRIR_rom_ITD_azimKSeq_Q );
    for ( j = 0; j < ( modelITD->azimDim3 + 1 ) / 2 - 2; j++ )
    {
@@ -662,7 +691,10 @@ static ivas_error DefaultBSplineModel(
#endif
#ifdef FIX_1123_TDREN_16BIT_ROM
    size_rom_table = sizeof( defaultHRIR_rom_ITD_W ) / sizeof( int16_t );
    modelITD->W_dyn = (float *) malloc( size_rom_table * sizeof( float ) );
    if ( ( modelITD->W_dyn = (float *) malloc( size_rom_table * sizeof( float ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
    }
    q_scale = powf( 2.f, -1.f * (float) defaultHRIR_rom_ITD_W_Q );
    for ( j = 0; j < size_rom_table; j++ )
    {
@@ -671,7 +703,10 @@ static ivas_error DefaultBSplineModel(
    modelITD->W = (const float *) modelITD->W_dyn;

    size_rom_table = sizeof( defaultHRIR_rom_ITD_azimBsShape ) / sizeof( int16_t );
    modelITD->azimBsShape_dyn = (float *) malloc( size_rom_table * sizeof( float ) );
    if ( ( modelITD->azimBsShape_dyn = (float *) malloc( size_rom_table * sizeof( float ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
    }
    q_scale = powf( 2.f, -1.f * (float) defaultHRIR_rom_ITD_azimBsShape_Q );
    for ( j = 0; j < size_rom_table; j++ )
    {
@@ -680,7 +715,10 @@ static ivas_error DefaultBSplineModel(
    modelITD->azimBsShape = (const float *) modelITD->azimBsShape_dyn;

    size_rom_table = sizeof( defaultHRIR_rom_ITD_elevBsShape ) / sizeof( int16_t );
    modelITD->elevBsShape_dyn = (float *) malloc( size_rom_table * sizeof( float ) );
    if ( ( modelITD->elevBsShape_dyn = (float *) malloc( size_rom_table * sizeof( float ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
    }
    q_scale = powf( 2.f, -1.f * (float) defaultHRIR_rom_ITD_elevBsShape_Q );
    for ( j = 0; j < size_rom_table; j++ )
    {