Commit cfa49b74 authored by vaclav's avatar vaclav
Browse files

framework: introduce JBM reader. get rid of printf() in init_enc(); when RF is...

framework: introduce JBM reader. get rid of printf() in init_enc(); when RF is specified at the encoder command-line and other than 13.2 kbps 32/48kHz is selected, the encoder does not stop but just prints-out a message about "switching to normal mode" to replicate the EVS behavior
parent 267b2d69
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -148,6 +148,7 @@
    <ClCompile Include="..\lib_util\hrtf_file_reader.c" />
    <ClCompile Include="..\lib_util\ism_file_reader.c" />
    <ClCompile Include="..\lib_util\ism_file_writer.c" />
    <ClCompile Include="..\lib_util\jbm_file_reader.c" />
    <ClCompile Include="..\lib_util\jbm_file_writer.c" />
    <ClCompile Include="..\lib_util\ls_custom_file_reader.c" />
    <ClCompile Include="..\lib_util\masa_file_reader.c" />
@@ -168,6 +169,7 @@
    <ClInclude Include="..\lib_util\hrtf_file_reader.h" />
    <ClInclude Include="..\lib_util\ism_file_reader.h" />
    <ClInclude Include="..\lib_util\ism_file_writer.h" />
    <ClInclude Include="..\lib_util\jbm_file_reader.h" />
    <ClInclude Include="..\lib_util\jbm_file_writer.h" />
    <ClInclude Include="..\lib_util\ls_custom_file_reader.h" />
    <ClInclude Include="..\lib_util\mime_io.h" />
+19 −82
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include "cmdl_tools.h"
#include "audio_file_reader.h"
#include "bitstream_writer.h"
#include "jbm_file_reader.h"
#include "masa_file_reader.h"
#include "ism_file_reader.h"
#include <stdio.h>
@@ -142,7 +143,6 @@ typedef struct
static void initArgStruct( EncArguments *arg );
static bool parseCmdlIVAS_enc( int16_t argc, char *argv[], EncArguments *arg );
static void usage_enc( void );
static ivas_error readChannelAwareConfig( FILE *file, IVAS_ENC_CHANNEL_AWARE_CONFIG *caConfig );
static bool readBandwidth( FILE *file, IVAS_ENC_BANDWIDTH *bandwidth, int32_t *bandwidthFrameCounter );
static bool readBitrate( FILE *file, int32_t *bitrate );
#ifdef DEBUGGING
@@ -206,7 +206,7 @@ int main(
    AudioFileReader *audioReader = NULL;
    FILE *f_bitrateProfile = NULL;
    FILE *f_bwProfile = NULL;
    FILE *f_caProfile = NULL;
    JbmFileReader *jbmReader = NULL;
    MasaFileReader *masaReader = NULL;
    IsmFileReader *ismReaders[IVAS_MAX_NUM_OBJECTS];
    for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i )
@@ -396,20 +396,18 @@ int main(

    if ( arg.ca_config_file )
    {
        if ( ( f_caProfile = fopen( arg.ca_config_file, "rb" ) ) == NULL )
        if ( ( jbmReader = JbmFileReader_open( arg.ca_config_file ) ) == NULL )
        {
            fprintf( stderr, "\nError: Channel aware configuration file could not be opened: %s\n\n", arg.ca_config_file );
            usage_enc();
            goto cleanup;
        }
        else
        {
            fprintf( stdout, "\nChannel-aware mode:     ON, Channel-aware config file name:  %s  \n\n", arg.ca_config_file );
        }

        fprintf( stdout, "Channel-aware mode:     ON, config file:  %s  \n", arg.ca_config_file );
    }
    else if ( arg.caConfig.channelAwareModeEnabled )
    else if ( caConfig.channelAwareModeEnabled )
    {
        fprintf( stdout, "\nChannel-aware mode:     ON, FEC indicator : %s  FEC offset: %d \n\n", ( caConfig.fec_indicator == IVAS_ENC_FEC_LO ) ? "LO" : "HI", caConfig.fec_offset );
        fprintf( stdout, "Channel-aware mode:     ON, FEC indicator : %s  FEC offset: %d \n\n", ( caConfig.fec_indicator == IVAS_ENC_FEC_LO ) ? "LO" : "HI", caConfig.fec_offset );
    }

    /*------------------------------------------------------------------------------------------*
@@ -470,7 +468,7 @@ int main(
            goto cleanup;
    }

    IVAS_ENC_PrintConfig( hIvasEnc );
    IVAS_ENC_PrintConfig( hIvasEnc, caConfig.channelAwareModeEnabled );

    /*------------------------------------------------------------------------------------------*
     * Open input metadata files
@@ -637,17 +635,17 @@ int main(
            }
        }

        if ( f_caProfile )
        if ( jbmReader )
        {
            if ( ( error = readChannelAwareConfig( f_caProfile, &caConfig ) ) != IVAS_ERR_OK )
            if ( ( error = JbmFileReader_readCAconfig( jbmReader, &caConfig ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "readChannelAwareConfig failed: %s\n", IVAS_ENC_GetErrorMessage( error ) );
                fprintf( stderr, "JbmFileReader_readCAconfig() failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) );
                goto cleanup;
            }

            if ( ( error = IVAS_ENC_SetChannelAwareConfig( hIvasEnc, caConfig ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "IVAS_ENC_SetChannelAwareConfig failed: %s\n", IVAS_ENC_GetErrorMessage( error ) );
                fprintf( stderr, "IVAS_ENC_SetChannelAwareConfig failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) );
                goto cleanup;
            }
        }
@@ -768,6 +766,11 @@ cleanup:

    AudioFileReader_close( &audioReader );

    if ( jbmReader )
    {
        JbmFileReader_close( &jbmReader );
    }

    for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i )
    {
        if ( ismReaders[i] != NULL )
@@ -791,11 +794,6 @@ cleanup:
        fclose( f_bitrateProfile );
    }

    if ( f_caProfile )
    {
        fclose( f_caProfile );
    }

#ifdef DEBUGGING
    if ( f_forcedModeProfile )
    {
@@ -1049,7 +1047,7 @@ static bool parseCmdlIVAS_enc(

        else if ( strcmp( argv_to_upper, "-RF" ) == 0 )
        {
            arg->caConfig.channelAwareModeEnabled = true;
            arg->caConfig.channelAwareModeEnabled = 1;
            i++;

            if ( i < argc - 4 )
@@ -1069,12 +1067,11 @@ static bool parseCmdlIVAS_enc(
                }
                i++;


                if ( ( sscanf( argv[i], "%d", &tmp ) == 1 ) && ( i < argc - 4 ) )
                {
                    if ( tmp == 0 )
                    {
                        arg->caConfig.channelAwareModeEnabled = false;
                        arg->caConfig.channelAwareModeEnabled = 0;
                        arg->caConfig.fec_offset = 0;
                        i++;
                    }
@@ -1646,66 +1643,6 @@ static void usage_enc( void )
}


/*---------------------------------------------------------------------*
 * readChannelAwareConfig()
 *
 *
 *---------------------------------------------------------------------*/

static ivas_error readChannelAwareConfig(
    FILE *file,
    IVAS_ENC_CHANNEL_AWARE_CONFIG *caConfig )
{
    char rline[10], str[4];
    int16_t tmp;

    /* Initialize */
    caConfig->fec_offset = 0;
    caConfig->fec_indicator = IVAS_ENC_FEC_HI;

    while ( fgets( rline, 10, file ) == NULL && feof( file ) )
    {
        rewind( file );
    }

    if ( sscanf( rline, "%s %hd", str, &tmp ) != 2 )
    {
        fprintf( stderr, "Error in the RF configuration file. There is no proper configuration line.\n" );
        return IVAS_ERR_INVALID_FEC_CONFIG;
    }

    /* Read RF FEC indicator */
    to_upper( str );

    if ( strcmp( str, "HI" ) == 0 )
    {
        caConfig->fec_indicator = IVAS_ENC_FEC_HI;
    }
    else if ( strcmp( str, "LO" ) == 0 )
    {
        caConfig->fec_indicator = IVAS_ENC_FEC_LO;
    }
    else
    {
        fprintf( stderr, "Error: Incorrect FEC indicator string. Exiting the encoder.\n" );
        return IVAS_ERR_INVALID_FEC_CONFIG;
    }

    /* Read RF FEC offset */
    if ( tmp == 0 || tmp == 2 || tmp == 3 || tmp == 5 || tmp == 7 )
    {
        caConfig->fec_offset = tmp;
    }
    else
    {
        fprintf( stderr, "Error: incorrect FEC offset specified in the RF configuration file; RF offset can be 2, 3, 5, or 7. \n" );
        return IVAS_ERR_INVALID_FEC_CONFIG;
    }

    return IVAS_ERR_OK;
}


/*---------------------------------------------------------------------*
 * readBandwidth()
 *
+16 −0
Original line number Diff line number Diff line
@@ -47,10 +47,26 @@
#define IVAS_MAX_NUM_OBJECTS       4
#define IVAS_MAX_OUTPUT_CHANNELS   16
#define IVAS_CLDFB_NO_CHANNELS_MAX ( 60 )

/*----------------------------------------------------------------------------------*
 * Common API structures
 *----------------------------------------------------------------------------------*/

typedef enum _IVAS_ENC_FEC_INDICATOR
{
    IVAS_ENC_FEC_LO,
    IVAS_ENC_FEC_HI,
    IVAS_ENC_FEC_UNDEFINED = 0xffff
} IVAS_ENC_FEC_INDICATOR;

typedef struct _IVAS_ENC_CHANNEL_AWARE_CONFIG
{
    int16_t channelAwareModeEnabled;
    IVAS_ENC_FEC_INDICATOR fec_indicator;
    int16_t fec_offset;
} IVAS_ENC_CHANNEL_AWARE_CONFIG;


typedef struct _IVAS_ISM_METADATA
{
    float azimuth;
+1 −0
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@
#define SIMPLIFY_SBA_RENDERING_LOGIC
#define SBA_CLEANING


/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */
#endif
+0 −7
Original line number Diff line number Diff line
@@ -646,13 +646,6 @@ ivas_error init_encoder(

    if ( !st->Opt_RF_ON || ( st->bwidth != WB && st->bwidth != SWB ) || st->total_brate != ACELP_13k20 )
    {
        if ( st->Opt_RF_ON )
        { // VE: this should be printed outside of library
            printf( "\nWarning: Channel-aware mode only available for 13.2 kbps WB/SWB\n" );
            printf( "         Switched to normal mode!\n" );
            st->Opt_RF_ON = 0;
            st->rf_fec_offset = 0;
        }
        st->rf_mode = 0;
    }
    else
Loading