Commit 5be3060d authored by emerit's avatar emerit
Browse files

remove use of python

parent 89eaa34f
Loading
Loading
Loading
Loading
+2 −12
Original line number Diff line number Diff line
@@ -33,11 +33,7 @@
## Requirements
- MATLAB >= R2020b
- Signal Processing Toolbox
- Python 3.9.* with pip
- [`../../scripts/pyaudio3dtools`](../../scripts/pyaudio3dtools) packages
- NumPy (`pip install numpy`)
- H5py (`pip install h5py`)
- SciPy (`pip install scipy`) for [`../../scripts/pyaudio3dtools`](../../scripts/pyaudio3dtools) packages
- C/C++ compiler 
   - Linux (Ubuntu) :
     ```shell
@@ -62,13 +58,7 @@
     cd ..
     ```
   - `generate_crend_ivas_tables` executable shall be in folder [`../../scripts/binauralRenderer_interface`](../../scripts/binauralRenderer_interface)  
   - `SofaReader.py` file must be in the same folder as the executable `generate_crend_ivas_tables`
   - Run
     ```shell 
     python3 run.py
     ``` 
     → No error message shall appear
      - Using `pip` and `PYTHONPATH`. Add `pip` packages folder (e.g., [`C:\Users\username\AppData\Local\Programs\Python\Python311\Lib\site-packages`](C:\Users\username\AppData\Local\Programs\Python\Python311\Lib\site-packages)) to environment variable `PYTHONPATH`. It can be necessary also to add folder [`../../scripts/pyaudio3dtools`](../../scripts/pyaudio3dtools) to `PYTHONPATH`.  
   - On windows this executable requires dll from matlab, you need to add to your path "*/matlab/version/bin/win64"
   - For more details on `generate_crend_ivas_tables` see [`mixer_conv_sofa_to_rom_table_converter_readme.txt`](mixer_conv_sofa_to_rom_table_converter_readme.txt).

### Build `tables_format_converter` in `Release` or `RelWithDebugInfo` configuration. `Debug` configuration does not work calling NumPy
+0 −190
Original line number Diff line number Diff line
"""
   (C) 2022-2023 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.
"""

import numpy as np
import pyaudio3dtools
import h5py
from typing import Tuple


def load(
    filename,
) -> Tuple[
    str,
    str,
    int,
    np.ndarray,
    np.ndarray,
    np.ndarray,
    np.ndarray,
    np.ndarray,
    np.ndarray,
    np.ndarray,
]:
    hrtf = h5py.File(filename, "r")
    Database_Name = str(hrtf.attrs["DatabaseName"])
    Listener_Short_Name = str(hrtf.attrs["ListenerShortName"])
    latencys = 0
    if "latencys" in hrtf.keys():
        latencys = np.array(hrtf["latencys"])
    Sampling_Rate = np.array(hrtf["Data.SamplingRate"])
    if Sampling_Rate.size > 1:
        return (
            "",
            "",
            0,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
        )
    Sampling_Rate = int(Sampling_Rate[0])
    ind_dir = 0
    Source_Position_hd5 = hrtf["SourcePosition"]
    Source_Position = np.array(Source_Position_hd5)
    unitToRad = [1.0, 1.0]
    Units = str(Source_Position_hd5.attrs["Units"])
    if "degree" in Units:
        unitToRad[0] = np.pi / 180
        Units = Units.replace("degree,", "", 1)
        if "degree" in Units:
            unitToRad[1] = np.pi / 180
            Units = Units.replace("degree,", "", 1)
    Source_Position_Cartesian = np.copy(Source_Position)
    for ind_dir_ptr in Source_Position:
        Source_Position_Cartesian[ind_dir][0] = (
            ind_dir_ptr[2]
            * np.cos(ind_dir_ptr[0] * unitToRad[0])
            * np.cos(ind_dir_ptr[1] * unitToRad[1])
        )
        Source_Position_Cartesian[ind_dir][1] = (
            ind_dir_ptr[2]
            * np.sin(ind_dir_ptr[0] * unitToRad[0])
            * np.cos(ind_dir_ptr[1] * unitToRad[1])
        )
        Source_Position_Cartesian[ind_dir][2] = ind_dir_ptr[2] * np.sin(
            ind_dir_ptr[1] * unitToRad[1]
        )
        ind_dir = ind_dir + 1
    Data_Delay = np.array(hrtf["Data.Delay"])
    Data_IR = np.array(hrtf["Data.IR"])
    Data_IR_48khz = np.zeros(
        (
            Data_IR.shape[0],
            Data_IR.shape[1],
            int(np.ceil(Data_IR.shape[2] * 48000 / Sampling_Rate)),
        )
    )
    Data_IR_32khz = np.zeros(
        (
            Data_IR.shape[0],
            Data_IR.shape[1],
            int(np.ceil(Data_IR.shape[2] * 32000 / Sampling_Rate)),
        )
    )
    Data_IR_16khz = np.zeros(
        (
            Data_IR.shape[0],
            Data_IR.shape[1],
            int(np.ceil(Data_IR.shape[2] * 16000 / Sampling_Rate)),
        )
    )
    ind_dir = 0
    for ind_dir_ptr in Data_IR:
        ind_ear = 0
        for ind_ear_ptr in ind_dir_ptr:
            tmp = np.copy(ind_ear_ptr)
            Data_IR_48khz[ind_dir][ind_ear][:] = pyaudio3dtools.audioarray.resample(
                tmp, Sampling_Rate, 48000
            )
            tmp = np.copy(ind_ear_ptr)
            Data_IR_32khz[ind_dir][ind_ear][:] = pyaudio3dtools.audioarray.resample(
                tmp, Sampling_Rate, 32000
            )
            tmp = np.copy(ind_ear_ptr)
            Data_IR_16khz[ind_dir][ind_ear][:] = pyaudio3dtools.audioarray.resample(
                tmp, Sampling_Rate, 16000
            )
            ind_ear = ind_ear + 1
        ind_dir = ind_dir + 1
    return (
        Database_Name,
        Listener_Short_Name,
        Sampling_Rate,
        latencys,
        Data_Delay,
        Data_IR_48khz,
        Data_IR_32khz,
        Data_IR_16khz,
        Source_Position,
        Source_Position_Cartesian,
    )


def find_pos_cart(Source_Position_Cartesian, dir_cart):
    valmax = 0
    indmax = -1
    ind_dir = 0
    for ind_dir_ptr in Source_Position_Cartesian:
        tmp = np.dot(ind_dir_ptr, dir_cart)
        if tmp > valmax:
            valmax = tmp
            indmax = ind_dir
        ind_dir = ind_dir + 1
    return indmax


def find_pos_spheric(Source_Position_Cartesian, dir_spheric):
    valmax = 0
    indmax = -1
    ind_dir = 0
    dir_cart = np.copy(dir_spheric)
    dir_cart[0] = (
        dir_spheric[2]
        * np.cos(dir_spheric[0] * np.pi / 180)
        * np.cos(dir_spheric[1] * np.pi / 180)
    )
    dir_cart[1] = (
        dir_spheric[2]
        * np.sin(dir_spheric[0] * np.pi / 180)
        * np.cos(dir_spheric[1] * np.pi / 180)
    )
    dir_cart[2] = dir_spheric[2] * np.sin(dir_spheric[1] * np.pi / 180)

    for ind_dir_ptr in Source_Position_Cartesian:
        tmp = np.dot(ind_dir_ptr, dir_cart)
        if tmp > valmax:
            valmax = tmp
            indmax = ind_dir
        ind_dir = ind_dir + 1
    return indmax
+0 −64
Original line number Diff line number Diff line
"""
   (C) 2022-2023 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.
"""

import os
import sys

localPath = os.getcwd()
oseperator = os.sep
localPath = localPath.replace(os.sep + "binauralRenderer_interface", "")

sys.path.append(localPath)
import SofaReader as sr

filename = "./HRIRs_sofa/HRIR_128_Meth5_IRC_53_Q10_symL_Itrp1_48000.sofa"

[
    baseName,
    listName,
    sampleRate,
    latency,
    Data_Delay,
    Data_IR_48khz,
    Data_IR_32khz,
    Data_IR_16khz,
    srcPos,
    srcPosCart,
] = sr.load(filename)

ind = sr.find_pos_spheric(srcPosCart, [30.0, 0.0, 2.0])

print("base Name :" + baseName)
print("listener Name :" + listName)
print("sampleRate :" + str(sampleRate))
print("indice of direction [30.0, 0.0, 2.0] : " + str(ind))
print("No error in reading " + filename)

exit
+0 −30
Original line number Diff line number Diff line
Copyright (c) 2008 Andrew Collette and contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the
   distribution.

3. Neither the name of the copyright holder nor the names of its
   contributors may be used to endorse or promote products derived from
   this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+0 −145
Original line number Diff line number Diff line
Copyright Notice and License Terms for 
HDF5 (Hierarchical Data Format 5) Software Library and Utilities
-----------------------------------------------------------------------------

HDF5 (Hierarchical Data Format 5) Software Library and Utilities
Copyright 2006 by The HDF Group. 

NCSA HDF5 (Hierarchical Data Format 5) Software Library and Utilities
Copyright 1998-2006 by The Board of Trustees of the University of Illinois. 

All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted for any purpose (including commercial purposes) 
provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, 
   this list of conditions, and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, 
   this list of conditions, and the following disclaimer in the documentation 
   and/or materials provided with the distribution.

3. Neither the name of The HDF Group, the name of the University, nor the 
   name of any Contributor may be used to endorse or promote products derived 
   from this software without specific prior written permission from 
   The HDF Group, the University, or the Contributor, respectively.

DISCLAIMER: 
THIS SOFTWARE IS PROVIDED BY THE HDF GROUP AND THE CONTRIBUTORS 
"AS IS" WITH NO WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED. IN NO 
EVENT SHALL THE HDF GROUP OR THE CONTRIBUTORS BE LIABLE FOR ANY DAMAGES 
SUFFERED BY THE USERS ARISING OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
You are under no obligation whatsoever to provide any bug fixes, patches, or 
upgrades to the features, functionality or performance of the source code 
("Enhancements") to anyone; however, if you choose to make your Enhancements 
available either publicly, or directly to The HDF Group, without imposing a 
separate written license agreement for such Enhancements, then you hereby 
grant the following license: a non-exclusive, royalty-free perpetual license 
to install, use, modify, prepare derivative works, incorporate into other 
computer software, distribute, and sublicense such enhancements or derivative 
works thereof, in binary and source code form.

-----------------------------------------------------------------------------
-----------------------------------------------------------------------------

Limited portions of HDF5 were developed by Lawrence Berkeley National 
Laboratory (LBNL). LBNL's Copyright Notice and Licensing Terms can be
found here: COPYING_LBNL_HDF5 file in this directory or at 
http://support.hdfgroup.org/ftp/HDF5/releases/COPYING_LBNL_HDF5. 

-----------------------------------------------------------------------------
-----------------------------------------------------------------------------

Contributors:   National Center for Supercomputing Applications (NCSA) at 
the University of Illinois, Fortner Software, Unidata Program Center 
(netCDF), The Independent JPEG Group (JPEG), Jean-loup Gailly and Mark Adler 
(gzip), and Digital Equipment Corporation (DEC).

-----------------------------------------------------------------------------
 
Portions of HDF5 were developed with support from the Lawrence Berkeley 
National Laboratory (LBNL) and the United States Department of Energy 
under Prime Contract No. DE-AC02-05CH11231.

-----------------------------------------------------------------------------

Portions of HDF5 were developed with support from the University of 
California, Lawrence Livermore National Laboratory (UC LLNL).  
The following statement applies to those portions of the product and must 
be retained in any redistribution of source code, binaries, documentation, 
and/or accompanying materials:

   This work was partially produced at the University of California, 
   Lawrence Livermore National Laboratory (UC LLNL) under contract 
   no. W-7405-ENG-48 (Contract 48) between the U.S. Department of Energy 
   (DOE) and The Regents of the University of California (University) 
   for the operation of UC LLNL.

   DISCLAIMER: 
   THIS WORK WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF 
   THE UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES GOVERNMENT NOR 
   THE UNIVERSITY OF CALIFORNIA NOR ANY OF THEIR EMPLOYEES, MAKES ANY 
   WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY OR RESPONSIBILITY 
   FOR THE ACCURACY, COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, 
   APPARATUS, PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE 
   WOULD NOT INFRINGE PRIVATELY- OWNED RIGHTS. REFERENCE HEREIN TO ANY 
   SPECIFIC COMMERCIAL PRODUCTS, PROCESS, OR SERVICE BY TRADE NAME, 
   TRADEMARK, MANUFACTURER, OR OTHERWISE, DOES NOT NECESSARILY CONSTITUTE 
   OR IMPLY ITS ENDORSEMENT, RECOMMENDATION, OR FAVORING BY THE UNITED 
   STATES GOVERNMENT OR THE UNIVERSITY OF CALIFORNIA. THE VIEWS AND 
   OPINIONS OF AUTHORS EXPRESSED HEREIN DO NOT NECESSARILY STATE OR REFLECT 
   THOSE OF THE UNITED STATES GOVERNMENT OR THE UNIVERSITY OF CALIFORNIA, 
   AND SHALL NOT BE USED FOR ADVERTISING OR PRODUCT ENDORSEMENT PURPOSES.

-----------------------------------------------------------------------------

HDF5 (Hierarchical Data Format 5)
Copyright (c) 2016, The Regents of the University of California, through 
Lawrence Berkeley National Laboratory (subject to receipt of any required 
approvals from the U.S. Dept. of Energy).

All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, 
   this list of conditions, and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, 
   this list of conditions, and the following disclaimer in the documentation 
   and/or materials provided with the distribution.

3. Neither the name of the University of California, Lawrence Berkeley 
National Laboratory, U.S. Dept. of Energy nor the names of its contributors 
may be used to endorse or promote products derived from this software without 
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
THE POSSIBILITY OF SUCH DAMAGE.

You are under no obligation whatsoever to provide any bug fixes, patches, 
or upgrades to the features, functionality or performance of the source 
code ("Enhancements") to anyone; however, if you choose to make your 
Enhancements available either publicly, or directly to Lawrence Berkeley 
National Laboratory, without imposing a separate written license agreement 
for such Enhancements, then you hereby grant the following license: 
a non-exclusive, royalty-free perpetual license to install, use, modify, 
prepare derivative works, incorporate into other computer software, 
distribute, and sublicense such enhancements or derivative works thereof, 
in binary and source code form.

-----------------------------------------------------------------------------
Loading