Commit 318e42a4 authored by emerit's avatar emerit
Browse files

Merge branch '744-fix-sofa-to-rom-tables-and-binaural-binary-files' of...

Merge branch '744-fix-sofa-to-rom-tables-and-binaural-binary-files' of https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec into 744-fix-sofa-to-rom-tables-and-binaural-binary-files
parents 11319fab c5b53dbf
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ def load(
    hrtf = Dataset(filename, "r", format="NETCDF4")
    Database_Name = hrtf.DatabaseName
    Listener_Short_Name = hrtf.ListenerShortName
    latencys = None
    latencys = 0
    if "latencys" in hrtf.variables.keys():
        latencys = np.array(hrtf.variables["latencys"])
    Sampling_Rate = np.array(hrtf.variables["Data.SamplingRate"])
+6 −5
Original line number Diff line number Diff line
@@ -469,7 +469,7 @@ int main( int argc, char *argv[] )
    memcpy( file_header_wptr, &( nbHRTF ), sizeof( int16_t ) );
    file_header_wptr += sizeof( int16_t );

    //   hrtf_size_max -= 4 * sizeof( int32_t ); // ???? demander à Arnaud
    hrtf_size_max -= sizeof( ivas_hrtfs_header_t ); // Keep only the raw data size max (w/o the header of the hrtf)
    memcpy( file_header_wptr, &( hrtf_size_max ), sizeof( int32_t ) );
    file_header_wptr += sizeof( int32_t );

@@ -2679,13 +2679,14 @@ int32_t read_hrtf_size( char *hrtf )

    if ( hrtf != NULL )
    {
        // Get the raw data size
        hrtf_rptr += sizeof( int32_t ); // RENDERER_TYPE
        hrtf_rptr += sizeof( int32_t ); // BINAURAL_INPUT_AUDIO_CONFIG
        hrtf_rptr += sizeof( int32_t );

        hrtf_rptr += sizeof( int32_t ); // Sampling Frequency
        memcpy( &( hrtf_size ), hrtf_rptr, sizeof( uint32_t ) );
        //     hrtf_size += sizeof( int32_t ) + sizeof( int32_t ) + sizeof( int32_t ) + sizeof( int32_t ); // + hrtf header size
        // hrtf_rptr += sizeof(uint32_t);

        // Add the hrtf header's size
        hrtf_size += sizeof( ivas_hrtfs_header_t );
    }

    return hrtf_size;
+52 −9
Original line number Diff line number Diff line
@@ -34,8 +34,10 @@
#ifdef _WIN32
#include <direct.h>
#define getcwd _getcwd
#elif
#define MAX_PATH _MAX_PATH
#else
#include <unistd.h>
#define MAX_PATH PATH_MAX
#endif
#include <math.h>
#include "options.h"
@@ -759,15 +761,16 @@ int main( int argc, char *argv[] )

#ifdef FIX_REMOVE_MYSOFA

    char current_path[_MAX_PATH];
    char ivas_path[_MAX_PATH];
    char current_path[MAX_PATH];
    char ivas_path[MAX_PATH];

    getcwd( current_path, _MAX_PATH );
    getcwd( current_path, MAX_PATH );
    strcpy( ivas_path, current_path );
    strcpy( ivas_path, current_path );
    char *tmpstr = strstr( ivas_path, "\\binauralRenderer_interface" );
    char *tmpstr = strstr( ivas_path, "/binauralRenderer_interface" );
    tmpstr[0] = '\0';

#ifdef _WIN32
    wchar_t *pyPath = Py_GetPath();

    wprintf( L"pyPath = %ls\n", pyPath );
@@ -786,11 +789,24 @@ int main( int argc, char *argv[] )
    pyPath = Py_GetPath();

    wprintf( L"pyPath = %ls\n", pyPath );
#endif

    Py_Initialize();

#ifndef _WIN32
    PyObject* sysPath = PySys_GetObject((char*)"path");
    PyList_Append(sysPath, (PyUnicode_FromString(current_path)));
    PyList_Append(sysPath, (PyUnicode_FromString(ivas_path)));
#endif

    if ( numpy_import_array( -1 ) == -1 )
    {
#ifdef _WIN32
        free( myPyPath );
#else
        Py_DECREF( sysPath );
#endif

        Py_Finalize();
        fprintf( stderr, "Cannot load numpy!\n\n" );
        usage_gen_crend_tables();
@@ -802,6 +818,12 @@ int main( int argc, char *argv[] )

    if ( sofa_load_func == NULL )
    {
#ifdef _WIN32
        free( myPyPath );
#else
        Py_DECREF( sysPath );
#endif

        Py_Finalize();
        fprintf( stderr, "SofaReader.py!\n\n" );
        usage_gen_crend_tables();
@@ -813,6 +835,12 @@ int main( int argc, char *argv[] )
    if ( ret == 0 )
    {
        Py_DECREF( sofa_load_func );
#ifdef _WIN32
        free( myPyPath );
#else
        Py_DECREF( sysPath );
#endif

        Py_Finalize();
        fprintf( stderr, "error reading SofaReader.py!\n\n" );
        usage_gen_crend_tables();
@@ -824,6 +852,12 @@ int main( int argc, char *argv[] )
    if ( sofa_find_dir_func == NULL )
    {
        Py_DECREF( sofa_load_func );
#ifdef _WIN32
        free( myPyPath );
#else
        Py_DECREF( sysPath );
#endif

        Py_Finalize();
        fprintf( stderr, "error reading SofaReader.py!\n\n" );
        usage_gen_crend_tables();
@@ -836,6 +870,11 @@ int main( int argc, char *argv[] )
    {
        Py_DECREF( sofa_find_dir_func );
        Py_DECREF( sofa_load_func );
#ifdef _WIN32
        free( myPyPath );
#else
        Py_DECREF( sysPath );
#endif

        Py_Finalize();
        fprintf( stderr, "SofaReader.py!\n\n" );
@@ -955,7 +994,11 @@ int main( int argc, char *argv[] )
    Py_DECREF( sofa_find_dir_func );
    Py_DECREF( sofa_load_func );

#ifdef _WIN32
    free( myPyPath );
#else
    Py_DECREF( sysPath );
#endif

    Py_Finalize();
#endif
@@ -1025,17 +1068,17 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, bool no_optim )
        args = Py_BuildValue( "(s)", sofa_file_path );
        kwargs = NULL;
        py_results = PyObject_Call( sofa_load_func, args, kwargs );
        Py_DECREF( args );

        if ( py_results == NULL )
        {
            Py_DECREF( py_results );

            fprintf( stderr, "Wrong file with wrong sample rate %s!\n\n", sofa_file_path );
            usage_gen_crend_tables();
            free( sofa_file_path );

            return -1;
        }
        Py_DECREF( args );

        ret = PyTuple_Check( py_results );
        if ( ret )
        {
@@ -1332,7 +1375,7 @@ int generate_crend_ivas_tables_from_sofa( const char *file_path, bool no_optim )
            if ( a[0] < -180 )
                a[0] += 360;
            fprintf( stderr, "Nearest Position: %f, %f, %f\n", a[0], a[1], a[2] );
            fprintf( stderr, "Nearest position found at: %d\n", nearest );
            fprintf( stderr, "Nearest position found at: %ld\n", nearest );
            index_pos[i] = nearest;
        }
        else