diff --git a/lib_util/ivas_rtp_pi_data.c b/lib_util/ivas_rtp_pi_data.c index 710121db6822e0042df38728e01d878d62601fbd..b9b7bcc7e44fbd19ca75570c793acd9e697bc588 100644 --- a/lib_util/ivas_rtp_pi_data.c +++ b/lib_util/ivas_rtp_pi_data.c @@ -1037,13 +1037,13 @@ static ivas_error packISMGain( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffe for ( n = 0; n < ism_gain->numObjects; n++ ) { gain = (int16_t) ism_gain->dB[n]; - idx = min( -gain, 97 ); + idx = min( -gain, 25 ); if ( gain > 0 ) { - idx += 97; + idx += 25; } - buffer[nBytes++] = ( idx & MASK_7BIT ) << 1; + buffer[nBytes++] = ( idx & MASK_6BIT ) << 2; } *nBytesWritten = nBytes; return IVAS_ERR_OK; @@ -1067,21 +1067,21 @@ static ivas_error unpackISMGain( const uint8_t *buffer, uint32_t numDataBytes, I /* Unpack ID for each object (1 byte each) */ for ( n = 0; n < ism_gain->numObjects; n++ ) { - idx = ( buffer[n] ) >> 1; + idx = ( buffer[n] ) >> 2; /* negative gains*/ - if ( idx < 97 ) + if ( idx < 25 ) { ism_gain->dB[n] = -(int8_t) ( idx ); } /* Set to min for muting, to be interpreted as -Inf */ - else if ( idx == 97 ) + else if ( idx == 25 ) { ism_gain->dB[n] = -128; } /* postive gains */ - else if ( idx < 101 ) + else if ( idx < 38 ) { - ism_gain->dB[n] = (int8_t) idx - 97; + ism_gain->dB[n] = (int8_t) idx - 25; } else { @@ -1249,7 +1249,7 @@ static ivas_error unpackISMDirectivity( const uint8_t *buffer, uint32_t numDataB if ( idx == 0 ) { - ism_directivity->directivity[n].outerAttenuationdB = -32768.0f; /* corresponds to muting */ + ism_directivity->directivity[n].outerAttenuationdB = -128.0f; /* corresponds to muting */ } else { @@ -1339,13 +1339,13 @@ static ivas_error packReverseISMGain( const IVAS_PIDATA_GENERIC *piData, uint8_t buffer[nBytes++] = ( r_ism_gain->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ gain = (int16_t) r_ism_gain->dB; - idx = min( -gain, 97 ); + idx = min( -gain, 25 ); if ( gain > 0 ) { - idx += 97; + idx += 25; } - buffer[nBytes++] = ( idx & MASK_7BIT ) << 1; + buffer[nBytes++] = ( idx & MASK_6BIT ) << 2; *nBytesWritten = nBytes; return IVAS_ERR_OK; } @@ -1365,21 +1365,21 @@ static ivas_error unpackReverseISMGain( const uint8_t *buffer, uint32_t numDataB r_ism_gain->piDataType = IVAS_PI_R_ISM_GAIN; /* Unpack gain */ - idx = ( *buffer ) >> 1; + idx = ( *buffer ) >> 2; /* negative gains*/ - if ( idx < 97 ) + if ( idx < 25 ) { r_ism_gain->dB = -(int8_t) ( idx ); } /* Set to min for muting, to be interpreted as -Inf */ - else if ( idx == 97 ) + else if ( idx == 25 ) { r_ism_gain->dB = -128; } /* postive gains */ - else if ( idx < 101 ) + else if ( idx < 38 ) { - r_ism_gain->dB = (int8_t) idx - 97; + r_ism_gain->dB = (int8_t) idx - 25; } else { diff --git a/tests/rtp/ivasrtp.py b/tests/rtp/ivasrtp.py index 224df7472e22197c14ec8366b63c1079d679311a..5b1bb2be7948643fbe9b8c01768e4b3193a64564 100644 --- a/tests/rtp/ivasrtp.py +++ b/tests/rtp/ivasrtp.py @@ -639,12 +639,12 @@ roomDimensionValue = [ 90.51, ] absorptionCoeffValues = [0.0800, 0.1656, 0.3430, 0.7101] -ismGains = list(range(0, -97, -1)) + [-float("inf")] + list(range(1, 4)) +ismGains = list(range(0, -25, -1)) + [-128] + list(range(1, 13)) # -128 corresponds to -Inf refDistances = [round(x * 0.1, 1) for x in range(1, 65)] maxDistances = list(range(1,65)) rolloffFactors = [round(x * 0.1, 1) for x in range(0, 41)] innerOuterAngles = list(range(0,361,15)) -outerAttenuations = [-float("inf")] + list(range(-90,1,3)) +outerAttenuations = [-128] + list(range(-90,1,3)) # -128 corresponds to -Inf codedFormats = list(FORMATS) codedSubFormats = list(SUBFORMATS) PiTypeNames = list(PIDATAS) @@ -1052,7 +1052,7 @@ def unpackISMGain(bitstrm: ConstBitStream, piSize: int) -> ISM_GAIN: assert piSize == 1 or piSize == 2 or piSize == 3 or piSize == 4, "Incorrect PI Data Size for ISM_GAIN" IsmGain = list() for _ in range(piSize): - IsmGain.append(bitstrm.read(7).uint) + IsmGain.append(bitstrm.read(6).uint) bitstrm.bytealign() return ISM_GAIN(gains=IsmGain) @@ -1062,8 +1062,8 @@ def packISMGain(bitstrm: BitStream, data: any): assert len(ism_gain.gains) <= 4, "Maximum 4 objects" for gain in ism_gain.gains: gain_idx = getListIndex(ismGains, gain) - bitstrm.append(f'uint:7={gain_idx}') - bitstrm.append(f'uint:1=0') + bitstrm.append(f'uint:6={gain_idx}') + bitstrm.append(f'uint:2=0') def unpackISMDistanceAttenuation(bitstrm: ConstBitStream, piSize: int) -> ISM_DISTANCE_ATTENUATION: ref_dist = None @@ -1131,15 +1131,15 @@ def packReverseISMID(bitstrm: BitStream, data: any): def unpackReverseISMGain(bitstrm: ConstBitStream, piSize: int) -> R_ISM_GAIN: assert piSize == 1, "Incorrect PI Data Size for R_ISM_GAIN" - gain = bitstrm.read(7).uint + gain = bitstrm.read(6).uint return R_ISM_GAIN(gain=gain) def packReverseISMGain(bitstrm: BitStream, data: any): assert type(data) == R_ISM_GAIN, "Data of type R_ISM_GAIN is expected" r_ism_gain = cast(R_ISM_GAIN, data) gain_idx = getListIndex(ismGains, r_ism_gain.gain) - bitstrm.append(f'uint:7={gain_idx}') - bitstrm.append(f'uint:1=0') + bitstrm.append(f'uint:6={gain_idx}') + bitstrm.append(f'uint:2=0') def unpackReverseISMDirection(bitstrm: ConstBitStream, piSize: int) -> R_ISM_DIRECTION: assert piSize == 2, "Incorrect PI Data Size for R_ISM_DIRECTION" diff --git a/tests/rtp/test_rtp.py b/tests/rtp/test_rtp.py index b8a542a4ed07d8ee271cb4f1643d4c8d30200f8a..53cb6488c5768ab3266bcaf3fe3a763592e126db 100644 --- a/tests/rtp/test_rtp.py +++ b/tests/rtp/test_rtp.py @@ -272,14 +272,14 @@ def generatePiData(startTs: int, endTs: int) -> dict: someNumISM = lambda : ISM_NUM(num=random.randint(1, 4)) someISMIds = lambda num_ism : ISM_ID(ids=[int(random.getrandbits(8)) for _ in range(num_ism)]) - someISMGains = lambda num_ism : ISM_GAIN(gains=[int(random.randint(-96,3)) for _ in range(num_ism)]) + someISMGains = lambda num_ism : ISM_GAIN(gains=[random.choice([int(random.randint(-24,12)), -128]) for _ in range(num_ism)]) # -128 corresponds to -Inf someISMOrientations = lambda num_ism : [ORIENTATION(w=2*random.random()-1.0, x=2*random.random()-1.0, y=2*random.random()-1.0, z=2*random.random()-1.0) for _ in range(num_ism)] someISMPositions = lambda num_ism : [POSITION( x=random.randint(-32788, 32767)/100.0, y=random.randint(-32788, 32767)/100.0, z=random.randint(-32788, 32767)/100.0) for _ in range(num_ism)] someISMDistanceAttenuations = lambda num_ism : [DISTANCE_ATTENUATION(ref_dist=random.randint(1,64)/10.0, max_dist=random.randint(1,64), roll_off=random.randint(0,40)/10.0) for _ in range(num_ism)] - someISMDirectivities = lambda num_ism : [DIRECTIVITY(inner_ang=random.randint(0,24)*15, outer_ang=random.randint(0,24)*15, outer_att=random.randint(-30,0)*3) for _ in range(num_ism)] + someISMDirectivities = lambda num_ism : [DIRECTIVITY(inner_ang=random.randint(0,24)*15, outer_ang=random.randint(0,24)*15, outer_att=random.choice([random.randint(-30,0)*3, -128])) for _ in range(num_ism)] # -128 corresponds to -Inf someReverseISMId = lambda : R_ISM_ID(id=(random.getrandbits(8))) - someReverseISMGain = lambda : R_ISM_GAIN(gain=int(random.randint(-96,3))) + someReverseISMGain = lambda : R_ISM_GAIN(gain=random.choice([int(random.randint(-24,12)), -128])) someReverseISMDirection = lambda : R_ISM_DIRECTION( azi=random.randint(1,512) * azimuthStepSize - 180.0, elev=random.randint(0,127) * elevationStepSize - 90.0 ) for ts in range(startTs, endTs, 320):