Esempio n. 1
0
def main():
    parser = argparse.ArgumentParser(
        description="This script shows information of *.sofa file.")

    parser.add_argument(
        'sofa_path',
        action='store',
        const=None,
        default=None,
        type=str,
        help='Directory path where the *.sofa file is located.',
        metavar=None)
    args = parser.parse_args()

    loadsofa = SOFAFile.load(args.sofa_path)

    # View the convention parameters
    loadsofa.view()

    # Copy impulse response data
    data = loadsofa.data_ir
    arr = np.array(data)
    print(arr.shape)

    print(loadsofa.SourcePosition)
    # for i in loadsofa.SourcePosition:
    #     print(i)
    print(loadsofa.getParam("ListenerPosition"))

    main_dic = {}
    params = loadsofa.flatten()
    for i in params:
        pi = params[i]
        value = pi.value.shape if \
            (pi.isType("double") or pi.isType("string")) else pi.value

        dic = {
            "shorthand": str(pi.getShorthandName()),
            "type": pi.type[0].upper(),
            "value": value,
            "ro": pi.isReadOnly(),
            "m": pi.isRequired(),
            "dims": pi.dimensions if pi.dimensions else None
        }

        main_dic[str(pi.getShorthandName())] = dic

    input_name_list = args.sofa_path.split("/")[-1].split(".")
    print(input_name_list)
    out_name = "".join(input_name_list[:-1]) + ".json"

    with open(f"/tmp/{out_name}", 'w') as f:
        # json.dump(main_dic, f, indent=4)
        json.dump(main_dic, f)
Esempio n. 2
0
#                           File: SimpleHeadphoneIR_1.0_0.2.py
#                           Project: SOFASonix
#                           Author: I.Laghidze
#                           License: BSD 3
#
# =============================================================================

from SOFASonix import SOFAFile
import numpy as np

"""
=============================== Initial Config ================================
"""

# Create SOFAFile object with the latest SimpleHeadphoneIR convention
sofa = SOFAFile("SimpleHeadphoneIR", sofaConventionsVersion=0.2, version=1.0)

# Set dimensions
sofa._M = 100
sofa._N = 1024

# View parameters of convention
sofa.view()


"""
=============================== Attributes ====================================
"""

# ----- Mandatory attributes -----
sofa.GLOBAL_AuthorContact = ""
#                           File: SingleRoomDRIR_1.0_0.3.py
#                           Project: SOFASonix
#                           Author: I.Laghidze
#                           License: BSD 3
#
# =============================================================================

from SOFASonix import SOFAFile
import numpy as np

"""
=============================== Initial Config ================================
"""

# Create SOFAFile object with the latest SingleRoomDRIR convention
sofa = SOFAFile("SingleRoomDRIR", sofaConventionsVersion=0.3, version=1.0)

# Set dimensions
sofa._M = 100
sofa._N = 1024
sofa._R = 2

# View parameters of convention
sofa.view()


"""
=============================== Attributes ====================================
"""

# ----- Mandatory attributes -----
#                           File: FreeFieldDirectivityTF_1.0_0.1.py
#                           Project: SOFASonix
#                           Author: I.Laghidze
#                           License: BSD 3
#
# =============================================================================

from SOFASonix import SOFAFile
import numpy as np
"""
=============================== Initial Config ================================
"""

# Create SOFAFile object with the latest FreeFieldDirectivityTF convention
sofa = SOFAFile("FreeFieldDirectivityTF",
                sofaConventionsVersion=0.1,
                version=1.0)

# Set dimensions
sofa._M = 100
sofa._N = 1024
sofa._R = 2
sofa._E = 4

# View parameters of convention
sofa.view()
"""
=============================== Attributes ====================================
"""

# ----- Mandatory attributes -----
Esempio n. 5
0
#                           File: GeneralFIRE_1.0_1.0.py
#                           Project: SOFASonix
#                           Author: I.Laghidze
#                           License: BSD 3
#
# =============================================================================

from SOFASonix import SOFAFile
import numpy as np

"""
=============================== Initial Config ================================
"""

# Create SOFAFile object with the latest GeneralFIRE convention
sofa = SOFAFile("GeneralFIRE", sofaConventionsVersion=1.0, version=1.0)

# Set dimensions
sofa._M = 100
sofa._N = 1024
sofa._R = 2
sofa._E = 4

# View parameters of convention
sofa.view()


"""
=============================== Attributes ====================================
"""
#                           File: SimpleFreeFieldTF_1.0_1.0.py
#                           Project: SOFASonix
#                           Author: I.Laghidze
#                           License: BSD 3
#
# =============================================================================

from SOFASonix import SOFAFile
import numpy as np

"""
=============================== Initial Config ================================
"""

# Create SOFAFile object with the latest SimpleFreeFieldTF convention
sofa = SOFAFile("SimpleFreeFieldTF", sofaConventionsVersion=1.0, version=1.0)

# Set dimensions
sofa._M = 100
sofa._N = 1024

# View parameters of convention
sofa.view()


"""
=============================== Attributes ====================================
"""

# ----- Mandatory attributes -----
sofa.GLOBAL_AuthorContact = ""
Esempio n. 7
0
# -*- coding: utf-8 -*-
"""
Loads a SOFA file and visualizes the HRTF amplitude and phase

Created on Mon Feb 24 23:08:19 2020
@author: Ivan
"""
#%% Load SOFA file

from SOFASonix import SOFAFile
import numpy as np
import matplotlib.pyplot as plt
import scipy.fft

filename = 'hrtf_M_hrtf B.sofa'
sofa = SOFAFile.load(filename)

#Get params/data
SR = sofa.Data_SamplingRate
delay = sofa.Data_Delay
pos = sofa.SourcePosition
IR = sofa.Data_IR
N = sofa._N

#%% FFT along equator
ind = pos[:, 1] == 0  #select where the elevation is zero
pos_pol = pos[ind, 0]  #only the polar plane (at constant radius and elevation)
IR_pl = IR[ind, :, :]  #Filter IR based on the above criteria
ind2 = np.argsort(pos_pol)  #sort values to prevent artifcats during plotting
pos_pol = pos_pol[ind2]
IR_pl = IR_pl[ind2, :, :]