Commit 9653165e authored by Jan Brouwer's avatar Jan Brouwer
Browse files

update text_to_binary_payload.py to make input format more compatible with...

update text_to_binary_payload.py to make input format more compatible with render configuration files
parent 5f50e331
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
[roomAcoustics]
frequencyGridCount = 1;
acousticEnvironmentCount = 1;

[frequencyGrid:0]
method = individualFrequencies
method = individualFrequencies;
frequencies = [
        20.0, 25.0, 31.5, 40.0, 
        50.0, 63.0, 80.0, 100.0, 
@@ -8,21 +12,21 @@ frequencies = [
        800.0, 1000.0, 1250.0, 1600.0, 
        2000.0, 2500.0, 3150.0, 4000.0, 
        5000.0, 6300.0, 8000.0, 10000.0, 
        12500.0, 16000.0, 20000.0]
        12500.0, 16000.0, 20000.0];

[acousticEnvironment:0]
id = 0
frequencyGridIndex = 0
predelay = 0.08163
id = 0;
frequencyGridIndex = 0;
predelay = 0.08163;
rt60 = [
        0.81275, 0.61888, 0.45111, 0.34672, 0.46683, 0.53987, 0.61874, 0.70291, 0.66657, 0.73037,
        0.75090, 0.72470, 0.75486, 0.75857, 0.76844, 0.74999, 0.77622, 0.78227, 0.77441, 0.74688, 
        0.73521, 0.73782, 0.71928, 0.71708, 0.71465, 0.60592, 0.52031, 0.51768, 0.52102, 0.37956,
        0.30786]
        0.30786];

dsr = [
        0.00019952621, 0.00019952621, 7.9432844e-05, 5.0118702e-05, 7.943284e-06, 6.3095763e-06, 6.3095763e-06, 7.943284e-06, 1e-05, 1e-05,
        7.943284e-06, 1e-05, 1e-05, 1e-05, 7.943284e-06, 1e-05, 1e-05, 7.943284e-06, 7.943284e-06, 6.3095763e-06,
        6.3095763e-06, 6.3095763e-06, 6.3095763e-06, 6.3095763e-06, 6.3095763e-06, 3.1622776e-06, 3.1622776e-06, 3.1622776e-06, 6.3095763e-07, 3.1622776e-07,
        3.1622776e-07]
        3.1622776e-07];
+11 −10
Original line number Diff line number Diff line
[roomAcoustics]
frequencyGridCount = 1
acousticEnvironmentCount = 1
frequencyGridCount = 1;
acousticEnvironmentCount = 1;

[frequencyGrid:0]
nBands = 31
method = individualFrequencies
nBands = 31;
method = individualFrequencies;
frequencies = [
    20.0, 25.0, 31.5, 40.0, 
    50.0, 63.0, 80.0, 100.0, 
@@ -12,20 +13,20 @@ frequencies = [
    800.0, 1000.0, 1250.0, 1600.0, 
    2000.0, 2500.0, 3150.0, 4000.0, 
    5000.0, 6300.0, 8000.0, 10000.0, 
    12500.0, 16000.0, 20000.0]
    12500.0, 16000.0, 20000.0];

[acousticEnvironment:0]
id = 0
frequencyGridIndex = 0
predelay = 0.43031
id = 0;
frequencyGridIndex = 0;
predelay = 0.43031;
rt60 = [
        4.51916, 4.89553, 4.83276, 5.00198, 5.34468, 5.76026, 6.36818, 6.95503, 7.27557, 7.62559,
        8.08892, 8.16002, 8.13900, 8.17919, 8.16280, 8.46226, 9.61806, 9.93048, 9.81353, 8.59340, 
        8.38885, 8.36823, 6.51845, 3.76089, 3.75374, 3.57451, 1.28724, 1.22174, 1.22448, 1.71631,
        2.14343]
        2.14343];

dsr = [
        1e-06, 7.943284e-07, 1e-06, 1e-06, 1.5848925e-06, 1.9952631e-06, 3.1622776e-06, 3.9810707e-06, 6.3095763e-06, 7.943284e-06,
        1e-05, 7.943284e-06, 7.943284e-06, 7.943284e-06, 7.943284e-06, 7.943284e-06, 5.01187e-06, 5.01187e-06, 3.9810707e-06, 3.1622776e-06,
        3.1622776e-06, 2.511887e-06, 7.943284e-07, 6.3095763e-07, 6.3095763e-07, 5.01187e-08, 1.2589251e-08, 1.2589251e-08, 1.2589265e-09, 1.2589266e-11,
        3.981075e-12]
        3.981075e-12];
+11 −7
Original line number Diff line number Diff line
[roomAcoustics]
frequencyGridCount = 1;
acousticEnvironmentCount = 1;

[frequencyGrid:0]
method = individualFrequencies
method = individualFrequencies;
frequencies = [
        20.0, 25.0, 31.5, 40.0,
        50.0, 63.0, 80.0, 100.0,
@@ -8,12 +12,12 @@ frequencies = [
        800.0, 1000.0, 1250.0, 1600.0,
        2000.0, 2500.0, 3150.0, 4000.0,
        5000.0, 6300.0, 8000.0, 10000.0,
        12500.0, 16000.0, 20000.0]
        12500.0, 16000.0, 20000.0];

[acousticEnvironment:0]
id = 0
frequencyGridIndex = 0
predelay = 0.1
id = 0;
frequencyGridIndex = 0;
predelay = 0.1;
rt60 = [
        1.3622, 1.4486, 1.3168, 1.5787,
        1.4766, 1.3954, 1.2889, 1.3462,
@@ -22,12 +26,12 @@ rt60 = [
        1.1028, 1.1714, 1.1027, 1.0666,
        1.0550, 1.0553, 1.0521, 1.0569,
        1.0421, 0.97822, 0.80487, 0.75944,
        0.71945, 0.61682, 0.60031]
        0.71945, 0.61682, 0.60031];

dsr = [
        1.9952632e-08, 1.9952632e-08, 1.2589251e-08, 1.5848926e-08, 1.2589251e-08, 1.9952632e-08, 2.511887e-08, 3.9810708e-08, 1e-07, 1.9952633e-07,
        3.981071e-07, 6.3095763e-07, 7.943284e-07, 6.3095763e-07, 5.01187e-07, 5.01187e-07, 6.3095763e-07, 6.3095763e-07, 7.943284e-07, 6.3095763e-07,
        5.01187e-07, 6.3095763e-07, 6.3095763e-07, 6.3095763e-07, 5.01187e-07, 2.511887e-07, 1.2589251e-07, 1e-07, 6.309576e-08, 3.1622776e-08,
        2.511887e-08]
        2.511887e-08];

+13 −9
Original line number Diff line number Diff line
[roomAcoustics]
frequencyGridCount = 1;
acousticEnvironmentCount = 1;

[frequencyGrid:0]
method = individualFrequencies
method = individualFrequencies;
frequencies = [
        20.0, 25.0, 31.5, 40.0,
        50.0, 63.0, 80.0, 100.0,
@@ -8,12 +12,12 @@ frequencies = [
        800.0, 1000.0, 1250.0, 1600.0,
        2000.0, 2500.0, 3150.0, 4000.0,
        5000.0, 6300.0, 8000.0, 10000.0,
        12500.0, 16000.0, 20000.0]
        12500.0, 16000.0, 20000.0];

[acousticEnvironment:0]
id = 0
frequencyGridIndex = 0
predelay = 0.1
id = 0;
frequencyGridIndex = 0;
predelay = 0.1;
rt60 = [
        1.3622, 1.4486, 1.3168, 1.5787,
        1.4766, 1.3954, 1.2889, 1.3462,
@@ -22,13 +26,13 @@ rt60 = [
        1.1028, 1.1714, 1.1027, 1.0666,
        1.0550, 1.0553, 1.0521, 1.0569,
        1.0421, 0.97822, 0.80487, 0.75944,
        0.71945, 0.61682, 0.60031]
        0.71945, 0.61682, 0.60031];

dsr = [
        1.9952632e-08, 1.9952632e-08, 1.2589251e-08, 1.5848926e-08, 1.2589251e-08, 1.9952632e-08, 2.511887e-08, 3.9810708e-08, 1e-07, 1.9952633e-07,
        3.981071e-07, 6.3095763e-07, 7.943284e-07, 6.3095763e-07, 5.01187e-07, 5.01187e-07, 6.3095763e-07, 6.3095763e-07, 7.943284e-07, 6.3095763e-07,
        5.01187e-07, 6.3095763e-07, 6.3095763e-07, 6.3095763e-07, 5.01187e-07, 2.511887e-07, 1.2589251e-07, 1e-07, 6.309576e-08, 3.1622776e-08,
        2.511887e-08]
        2.511887e-08];

[directivity:0]
directivity = [0.0, 360.0, 0.2512]
[directivity]
directivity = [0.0, 360.0, 0.2512];
+30 −21
Original line number Diff line number Diff line
@@ -40,9 +40,9 @@
#   <option>=<value>
#   # a comment
#
#   <section> is one of the supported section names (frequencyGrid, acousticEnvironment).
#   <section> is one of the supported section names, e.g. frequencyGrid.
#   <index> is an integer used as acoustic environment ID (revAcEnvID), and to refer to (revFreqGridIdx).
#   There is no leading white space for sections and options, and no trailing ';'.
#   There is no leading white space for sections and options.
#


@@ -54,6 +54,7 @@ from generate_acoustic_environments_metadata import *

# convert text containing an option value to a Python value, if possible
def eval_option(text):
    text = text.replace(';', '')
    try:
        value = ast.literal_eval(text)
    except ValueError:
@@ -77,14 +78,19 @@ def parse_reverb_text_configuration_and_generate_binary_payload(file):
    sections = { key : {} for key in ['roomAcoustics', 'frequencyGrid', 'acousticEnvironment', 'directivity' ] }
    for section_name in config.sections():
        if ':' in section_name:
            assert section in ['frequencyGrid', 'acousticEnvironment']
            section, index = section_name.split(':')
            assert section in ['frequencyGrid', 'acousticEnvironment'], 'unknown section name'
            sections[section][index] = config[section_name]
        else:
            assert section in ['roomAcoustics', 'directivity']
            sections[section] = config[section_name]
        assert section in sections, 'unknown section name'
            assert section_name in ['roomAcoustics', 'directivity'], 'unknown section name'
            sections[section_name] = config[section_name]

    # parse room acoustics
    if 'roomAcoustics' in sections:
        frequencyGridCount = eval_option(sections['roomAcoustics']['frequencyGridCount'])
        acousticEnvironmentCount = eval_option(sections['roomAcoustics']['acousticEnvironmentCount'])
        assert frequencyGridCount == len(sections['frequencyGrid'])
        assert acousticEnvironmentCount == len(sections['acousticEnvironment'])

    # parse frequency grids
    nr_bands = []
@@ -93,20 +99,21 @@ def parse_reverb_text_configuration_and_generate_binary_payload(file):
        + get_count_or_index_code(len(sections['frequencyGrid'])),                  # fgdNrGrids
        endian='big')
    for _, fg in sections['frequencyGrid'].items():
        if fg['method'] == 'individualFrequencies':
        method = eval_option(fg['method'])
        if method == 'individualFrequencies':
            nr_bands.append(len(eval_option(fg['frequencies'])))
            data += bitarray(
                  fgdMethod.Individual_Frequencies.value                            # fgdMethod
                + get_count_or_index_code(len(eval_option(fg['frequencies'])))      # fgdNrBands
                + concatenate(get_frequency_code, eval_option(fg['frequencies'])))  # fgdCenterFreq
        elif fg['method'] == 'startHopAmount':
        elif method == 'startHopAmount':
            nr_bands.append(eval_option(fg['nrBands']))
            data += bitarray(
                  fgdMethod.Start_Hop_Amount.value                                  # fgdMethod
                + get_count_or_index_code(eval_option(fg['nrBands']))               # fgdNrBands
                + get_frequency_code(eval_option(fg['centerFrequency']))            # fgdCenterFreq
                + get_frequency_hop_code(eval_option(fg['hop'])))                   # frequencyHop
        elif fg['method'] == 'defaultBanding':
        elif method == 'defaultBanding':
            nr_bands.append(get_default_grid_nr_bands(eval_option(fg['defaultGrid'])))
            data += bitarray(
                  fgdMethod.Default_Banding.value                                   # fgdMethod
@@ -150,8 +157,7 @@ def parse_reverb_text_configuration_and_generate_binary_payload(file):
    hasDirectivity = len(sections['directivity']) > 0
    data += get_bool_code(hasDirectivity)                                                                      # hasDirectivity
    if hasDirectivity:
        for _, dir in sections['directivity'].items():
            dir_values = eval_option(dir['directivity'])
        dir_values = eval_option(sections['directivity']['directivity'])
        data += bitarray(get_angle_code(dir_values[0])                                                         # Directivity inner angle
            + get_angle_code(dir_values[1])                                                                    # Directivity outer angle
            + get_outer_attenuation_code(dir_values[2]))                                                       # Directivity outer attenuation
@@ -168,9 +174,12 @@ if __name__ == "__main__":
    parse_reverb_text_configuration_and_generate_binary_payload(args.configuration_file)

    print("\nNote: the conversion algorithm uses quantization, which may lead to quantization errors.")
    print('Maximum relative quantization errors:')
    print('    duration  : {:.1e}'.format(max_quantization_error['duration']))
    print('    frequency : {:.1e}'.format(max_quantization_error['frequency']))
    print('    DSR       : {:.1e}'.format(max_quantization_error['dsr']))
    print('    distance  : {:.1e}'.format(max_quantization_error['distance']))
    print('    absorption: {:.1e}'.format(max_quantization_error['absorption']))

    # print maximum quantization errors exceeding float32 resolution
    epsilon = 2e-7  # slighly larger than float32 epsilon
    text = ''
    for name in max_quantization_error.keys():
        if max_quantization_error[name] > epsilon:
           text += '\n    {:10s}: {:.1e}'.format(name, max_quantization_error[name])
    if len(text) > 0:
        print('Maximum relative quantization errors > {}:'.format(epsilon) + text)
 No newline at end of file