Commit 936f0bf5 authored by Marek Szczerba's avatar Marek Szczerba
Browse files

Merge branch...

Merge branch 'philips/contribution-38-control-metadata-reverb-acoustic-environment-payload' of https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec into philips/contribution-38-control-metadata-reverb-acoustic-environment-payload
parents f5940be2 4d2731c6
Loading
Loading
Loading
Loading
+50 −41
Original line number Diff line number Diff line
@@ -117,9 +117,9 @@ def get_duration_code(duration):
        '110100000',  '111010', '110100001', '111011', '110100110',  '111000', '110100111',  '111001', '110100100',  '111110',
        '110100101',  '111111', '110111010', '111100', '110111011',  '111101', '110111000',  '11000',  '110111001' ]

    duration_dus = int(round(np.float32(duration) * np.float32(100000)))   # [deca us]
    duration_dus = round(np.float32(duration) * np.float32(100000))   # [deca us]
    if print_cfg:
        print('duration: ', duration_dus)
        print('duration: ', duration_dus, 'dus')

    dus = duration_dus          # [deca us]
    s = dus // 100000           # 0, 1, ... 30  [s]
@@ -168,7 +168,7 @@ def get_frequency_code(f):
    assert 16 <= f <= 40000
    if f in frequencyCode.keys():
        if print_cfg:
            print('frequency:', f)
            print('frequency:', f, 'Hz')
        return frequencyCode[f] + '0'
    else:
        # exact frequency not found, use frequency refinement to aproximate
@@ -185,25 +185,24 @@ def get_frequency_code(f):
        if refinement >= 16:
            # choose next higer frequency
            if print_cfg:
                print('frequency:', list(frequencyCode)[f_high])
                print('frequency:', list(frequencyCode)[f_high], 'Hz')
            return frequencyCode[f_high] + '0'
        else:
            if print_cfg:
                print('frequency:', list(frequencyCode)[f_low], ', refined: ', f_low * 2 ** ((refinement + 1) / 51))
                print('frequency:', list(frequencyCode)[f_low], ', Hz, refined: ', f_low * 2 ** ((refinement + 1) / 51), 'Hz')
            return frequencyCode[f_low] + '1' + format(refinement, '04b')


def get_frequency_hop_code(index):
    assert 0 <= index < 9
    assert 0 <= index < 7
    return [
        '0010',       # 2^(1/12)
        '0011',       # 2^(1/6)
        '0000',       # 2^(1/4)
        '01',         # 2^(1/3)
        '0001',       # 2^(1/2)
        '10',          # 2^1
        '111'][index]  # 2^2
        
        '11',         # 2^1
        '10'][index]  # 2^2


def get_dsr_code(dsr):
@@ -239,7 +238,7 @@ class fgdMethod(Enum):
    Default_Banding        = '10'


def get_distance_code(dist, isSmallScene = True):
def get_distance_code(distance, isSmallScene = True):
    # 0, 1, ... 99
    metersCode = [
          '111101',   '110010',   '110011',   '110000',   '110001',   '110110',   '110111',   '110100',   '110101',   '001010',
@@ -274,37 +273,36 @@ def get_distance_code(dist, isSmallScene = True):
        '100010',   '100011',   '100000',   '100001',   '100110',   '100111',   '100100',   '100101',  '1111010',  '1111011',
       '1111000',  '1111001',  '1111110',  '1111111',  '1111100',  '1111101',   '111010',   '111011',   '111000',   '111001' ]

    distance_mm = int(round(np.float32(distance) * np.float32(1000)))      # distance in mm
    distance_cm = round(np.float32(distance) * np.float32(100))      # distance in cm
    if print_cfg:
        print('distance: ', distance_mm)
        print('distance: ', distance_cm, 'cm')

    mm = distance_mm            # [mm]
    cm = mm // 10               # [cm]
    cm = distance_cm            # [cm]
    m = cm // 100               # [m]
    hm = m // 100               # [hm]
    km = hm // 10               # [km]

    mm = (mm % 10)              # 0, 1, ... 9  [mm]
    cm = (cm % 100)             # 0, 1, ... 99 [cm]
    m = (m % 100)               # 0, 1, ... 99 [m]
    hm = (hm % 9)               # 0, 1, ... 9  [hm]
    hm = (hm % 10)              # 0, 1, ... 9  [hm]

    assert 0 <= mm <= 9
    assert 0 <= cm <= 99
    assert 0 <= m <= 99
    assert 0 <= hm <= 9
    assert distance_mm == km * 1000000 + hm * 100000 + m * 1000 + cm * 10 + mm
    assert distance_cm == km * 100000 + hm * 10000 + m * 100 + cm

    code = metersCode[m]
    
    if not isSmallScene:
    if isSmallScene:
        assert(m == hm == km == 0)
    else:
        # large scenes
        if hm > 0 or km > 0:
            # hectometers
            code += '1' + hectometersCode[hm]
            while km > 0:
                # kilometers
                code += '1' + kilometersCode[min(km, 10)]
                code += '1' + kilometersCode[min(km, 10) - 1]
                km = km - 10
            code += '0'
        else:
@@ -326,6 +324,7 @@ def get_absorption_code(absorption):

    return ['110', '100', '101', '0110', '0111', '111', '0100', '0101', '0010', '0011', '000' ][index]


# apply function to elements of list and concatenate the resulting strings
def concatenate(function, data):
    return ''.join([function(d) for d in data])
@@ -333,16 +332,15 @@ def concatenate(function, data):

def test():
    # generate binary output which can be compared with the Matlab implementation output
    
    string = ''

    # count or index encoding
    string += concatenate(get_count_or_index_code, [n for n in range(0, 16 * 64)])
    string += concatenate(get_count_or_index_code, [n for n in range(16 * 64)])

    # duration encoding
    string += concatenate(get_duration_code, [d / 1000   for d in range(0, 30 * 1000)])
    string += concatenate(get_duration_code, [d / 10000  for d in range(0, 30 * 1000)])
    string += concatenate(get_duration_code, [d / 100000 for d in range(0, 30 * 1000)])
    string += concatenate(get_duration_code, [d / 1000   for d in range(30 * 1000)])
    string += concatenate(get_duration_code, [d / 10000  for d in range(30 * 1000)])
    string += concatenate(get_duration_code, [d / 100000 for d in range(30 * 1000)])

    # frequency encoding
    string += concatenate(get_frequency_code,
@@ -352,11 +350,20 @@ def test():
         16000, 20000, 25000, 31500, 40000])

    # frequency hop encoding
    string += concatenate(get_frequency_hop_code, [index for index in range(0, 9)])
    string += concatenate(get_frequency_hop_code, [index for index in range(7)])

    # DSR encoding
    string += concatenate(get_dsr_code, [math.pow(10, dsr / 10) for dsr in range(-150, -10 + 1)])

    # distance encoding
    string += concatenate(lambda d : get_distance_code(d, False), [d       for d in range(20 * 1000)])
    string += concatenate(lambda d : get_distance_code(d, False), [d / 10  for d in range(20 * 1000)])
    string += concatenate(lambda d : get_distance_code(d, False), [d / 100 for d in range(20 * 1000)])
    string += concatenate(lambda d : get_distance_code(d, True),  [d / 100 for d in range(      100)])

    # absorption encoding
    string += concatenate(get_absorption_code, [a / 100 for a in range(100 + 1)])

    data = bitarray(string, endian='big')

    file = open('test_python.dat', 'wb')
@@ -443,8 +450,8 @@ def generate_reverb_payload_equivalent_to_rend_config_renderer_cfg_plus_early_re
              2.6267e-08 ])

        + '1'                                     #   hasEarlyReflections
        + concatenate(get_distance_code,          #     room dimensions
            [ 3.0, 4.0, 2.5 ])
        + concatenate(lambda d : get_distance_code(d, False),
            [ 3.0, 4.0, 2.5 ])                    #     room dimensions
        
        + get_count_or_index_code(0)              #     FreqGridID
        + concatenate(get_absorption_code,        #     absorptionCode
@@ -500,8 +507,8 @@ def generate_reverb_payload_equivalent_to_rend_config_renderer_cfg_plus_early_re
              2.6267e-08 ])

        + '1'                                     #   hasEarlyReflections
        + concatenate(get_distance_code,          #     room dimensions
            [ 3.0, 4.0, 2.5 ])
        + concatenate(lambda code : get_distance_code(code, False),
            [ 3.0, 4.0, 2.5 ])                    #     room dimensions

        + get_count_or_index_code(0)              #     FreqGridID
        + concatenate(get_absorption_code,        #     absorptionCode
@@ -510,8 +517,8 @@ def generate_reverb_payload_equivalent_to_rend_config_renderer_cfg_plus_early_re
        + '1'                                     #     listener origin flag
        + '1'                                     #     positive x origin
        + '0'                                     #     negative y origin
        + concatenate(get_distance_code,          #     listener origin (x, y, z)
            [ 0.5, 0.5, 1.5 ])
        + concatenate(lambda d : get_distance_code(d, False),
            [ 0.5, 0.5, 1.5 ])                    #     listener origin (x, y, z)

        , endian='big')

@@ -520,12 +527,11 @@ def generate_reverb_payload_equivalent_to_rend_config_renderer_cfg_plus_early_re
    file.close()



def generate_reverb_payload_equivalent_to_rend_config_hospital_patientroom_cfg():
    # based on config_hospital_patientroom.cfg
    # note that because of encoding, resolution is lost and behaviour may not be bit-exact compared to .cfg file based values
    data = bitarray(
        1                                         # hasAcEnv
        '1'                                       # hasAcEnv
        + get_count_or_index_code(1)              # fgdNrGrids
        + fgdMethod.Individual_Frequencies.value  #   fgdMethod
        + get_count_or_index_code(31)             #     fgdNrBands
@@ -567,7 +573,7 @@ def generate_reverb_payload_equivalent_to_rend_config_recreation_cfg():
    # based on config_recreation.cfg
    # note that because of encoding, resolution is lost and behaviour may not be bit-exact compared to .cfg file based values
    data = bitarray(
        1                                         # hasAcEnv
        '1'                                       # hasAcEnv
        + get_count_or_index_code(1)              # fgdNrGrids
        + fgdMethod.Individual_Frequencies.value  #   fgdMethod
        + get_count_or_index_code(31)             #     fgdNrBands
@@ -609,3 +615,6 @@ def generate_reverb_payload_equivalent_to_rend_config_recreation_cfg():
generate_reverb_payload_equivalent_to_rend_config_renderer_cfg()
generate_reverb_payload_equivalent_to_rend_config_hospital_patientroom_cfg()
generate_reverb_payload_equivalent_to_rend_config_recreation_cfg()

#generate_reverb_payload_equivalent_to_rend_config_renderer_cfg_plus_early_reflections_no_listener_origin()
#generate_reverb_payload_equivalent_to_rend_config_renderer_cfg_plus_early_reflections_listener_origin()