2
$\begingroup$

1) Problem description

I am trying to implement a 3D audio simulator in Python. I am using the HUTUBS dataset as HRIR database (more informations here: https://depositonce.tu-berlin.de/handle/11303/9429), in particular I am using the simulated one, which has a higher resolution than the measured dataset.

Since I need continous movement of sound sources, I am interpolating the available HRIR using the VBAP technique proposed by Pulkki (http://lib.tkk.fi/Diss/2001/isbn9512255324/article1.pdf), in particular I am referring to this paper solution: https://www.ime.usp.br/~mqz/TwoApproachesForHRTFInterpolation.pdf , where the authors suggest to interpolate the available HRIR exploiting the VBAP technique.

So far I have implemented all the code and it works fine to a certain extent, but I am not able to achieve constant gain amplitude using the proposed interpolation technique. When I use the interpolation technique, I get like "jumps" of volume (I will show an audio example later)

2) My implementation

Using the previous HRIR database, I am going to compute the 3 closest HRIR to the requested position using the following function:

 def compute_three_closest_positions(self, azimuth_angle, elevation):
        requested_position = np.array([azimuth_angle, elevation, 0])

        # computing the absolute difference between the requested angles and the available one in the dataset
        result = abs(self.sourcePositions - requested_position)
        result = np.delete(result, 2, 1)
        result = result.sum(axis=1)

        # returning index of the requested IR
        indexes = result.argsort()[:3]

        interpolated_positions = self.sourcePositions[indexes]
        print(interpolated_positions)
        self.real_azimuth_angles = interpolated_positions[:,0]
        self.real_elevations = interpolated_positions[:,1]
        print('printing azimuth angles: ',self.real_azimuth_angles)
        print('printing elevation angles: ',self.real_elevations)
        return indexes, interpolated_positions, requested_position

This function returns the index in the database which contains the 3 closest HRIR to the desider point (along with the positions of those points and the requested position). self.sourcePosition is computed by means of self.sourcePositions = self.HRIR_SOFA_file.getVariableValue('SourcePosition') which leverages on the pysofaconventions library to read SOFA datasets.

Once I get the desired HRIRs, I compute the VBAP gains using its formula:

def compute_gains(self, indexes, interpolated_positions, requested_position):
   
    interpolated_positions_cartesian = self.polar2cart(1.47, interpolated_positions[:,0], interpolated_positions[:,1])
    requested_position_cartesian = self.polar2cart(1.47, requested_position[0], requested_position[1], array = False)

    inverse_interpolated_positions_cartesian = np.linalg.inv(interpolated_positions_cartesian)
    g = np.matmul(requested_position_cartesian,inverse_interpolated_positions_cartesian)
    g_normalized = (np.sqrt(1.47)*g)/np.sqrt(g[0][0]**2 + g[0][1]**2 + g[0][2]**2)

    return g_normalized

Where self.polar2cart is a simple support function that converts the input data from spherical to cartesian coordinates and the constant value 1.47 has been used because the dataset has HRIRs measured at a distance of 1.47 meters.

The above two functions have been used inside a function which returns the final interpolated HRIR:

 def get_interpolated_IR(self,azimuth_angle, elevation, distance):
        indexes, interpolated_positions, requested_position = self.compute_three_closest_positions(azimuth_angle, elevation)
        gains = self.compute_gains(indexes, interpolated_positions, requested_position)
        aux_IR = np.array((self.IR_dictionary[indexes, 0, :],
                           self.IR_dictionary[indexes, 1, :]))
        aux_IR = np.moveaxis(aux_IR, 1,0)
        gains = np.squeeze(gains,axis=0)
        weighted_IR = 0
        for i in range(0,3):
            weighted_IR =+ gains[i] * aux_IR[i,:,:]

        return weighted_IR

Where self.IR_dictionary has been computed by means of self.IR_dictionary = self.HRIR_SOFA_file.getDataIR()

Finally, I use my weighted_IR to filter some audio data. The code about the audio processing, reproduction ecc... is omitted since it works fine.

3) Problems and examples

If I use the standard HRIR dataset (so no interpolations via VBAP) using the single closest HRIR to the desired position, this is what I get (use headphones): https://drive.google.com/file/d/1ywMwmHMKlmnG0MnjEnrmztxmuiZDxDjO/view?usp=sharing As you might hear, the 3D audio simulation works quite decently, even though you can hear a kind of "step" behaviour between each spatial position.

On the other hand, if I use the above mentioned interpolation method, this is the result I get (the audio movement is slower, to make more evident the volume jumps): https://drive.google.com/file/d/1F_9IdfiWgeHQNYSYrdqMYC1SQ9q_U7QE/view?usp=sharing

4) Known possible bugs

I noticed that in my approach, computing the 3 closest points to the desired source position, sometimes leads to a triangle that doesn't contain the source position, thus obtaining negative gain factors. An example is the following:

Requested point: azimut, elevation, distance
[200   0   1.47]

Three closest points: azimut, elevation, distance
[[199.69547046   0.           1.47      ]
 [199.40203659   5.61508214   1.47      ]
 [199.40203659  -5.61508214   1.47      ]]

gain matrix:  [[ 2.03778511 -0.52140831 -0.52140831]]

g_normalized:  [[1.1400898290447332 -0.29171491366465313 -0.2917149136646515]]

NB: I get "jumping" volumes also for valid gains (all positives) like in the following example:

Requested position:
[190   0   0]
Three closest points:
[[191.83033621   0.           1.47      ]
 [188.02560265   2.34839855   1.47      ]
 [188.02560265  -2.34839855   1.47      ]]
gain matrix:  [[0.51921064 0.24087231 0.24087231]]
g_normalized:  [[1.013732209139594 0.47029087177669177 0.47029087177668905]]

5) question

Which could be the cause of jumping gains and non constant volume? (beside the above already mentioned bug) I get that behaviour also for "valid" triplets of positions.

NB: My data has the following shape (i added a visualization to simplify the understanding of my problem)

Sphere

And here is an example of the data matrix with the available positions in the dataset (i can't provide the full matrix due to characters limitations in the question):

Source Positions
[[  0.          90.           1.47      ]
 [  0.          85.2073787    1.47      ]
 [  0.          78.16966379   1.47      ]
 [  0.          70.30452954   1.47      ]
 [  0.          62.0367492    1.47      ]
 [  0.          53.56289304   1.47      ]
 [  0.          45.           1.47      ]
 [  0.          36.43710696   1.47      ]
 [  0.          27.9632508    1.47      ]
 [  0.          19.69547046   1.47      ]
 [  0.          11.83033621   1.47      ]
 [  0.           4.7926213    1.47      ]
 [  0.           0.           1.47      ]
 [  0.          -4.7926213    1.47      ]
 [  0.         -11.83033621   1.47      ]
 [  0.         -19.69547046   1.47      ]
 [  0.         -27.9632508    1.47      ]
 [  0.         -36.43710696   1.47      ]
 [  0.         -45.           1.47      ]
 [  0.         -53.56289304   1.47      ]
 [  0.         -62.0367492    1.47      ]
 [  0.         -70.30452954   1.47      ]
 [  0.         -78.16966379   1.47      ]
 [  0.         -85.2073787    1.47      ]
 [  0.         -90.           1.47      ]
 [  1.64008341  -1.6394119    1.47      ]
 [  1.64008341   1.6394119    1.47      ]
 [  2.37160039   8.01881788   1.47      ]
 [  2.37160039  -8.01881788   1.47      ]
 [  2.80356493 -15.58649429   1.47      ]
 [  2.80356493  15.58649429   1.47      ]
 [  3.16999007  23.70233802   1.47      ]
 [  3.16999007 -23.70233802   1.47      ]
 [  3.56208248 -32.09871039   1.47      ]
 [  3.56208248  32.09871039   1.47      ]
 [  4.04606896  40.63141594   1.47      ]
 [  4.04606896 -40.63141594   1.47      ]
 [  4.1063771   -4.09587122   1.47      ]
 [  4.1063771    4.09587122   1.47      ]
 [  4.70089981  49.2024397    1.47      ]
 [  4.70089981 -49.2024397    1.47      ]
 [  4.7926213    0.           1.47      ]
 [  5.18003348  11.34988901   1.47      ]
 [  5.18003348 -11.34988901   1.47      ]
 [  5.65662228 -57.72525378   1.47      ]
 [  5.65662228  57.72525378   1.47      ]
 [  5.950799    19.30523849   1.47      ]
 [  5.950799   -19.30523849   1.47      ]
 [  6.69117127 -27.61716167   1.47      ]
 [  6.69117127  27.61716167   1.47      ]
 [  6.99679324   6.9451987    1.47      ]
 [  6.99679324  -6.9451987    1.47      ]
 [  7.17914676 -66.09875172   1.47      ]
 [  7.17914676  66.09875172   1.47      ]
 [  7.54685777  36.10960472   1.47      ]
 [  7.54685777 -36.10960472   1.47      ]
 [  8.02560265  -2.34839855   1.47      ]
 [  8.02560265   2.34839855   1.47      ]
 [  8.31015293  14.75097316   1.47      ]
 [  8.31015293 -14.75097316   1.47      ]
 [  8.65428668 -44.67195851   1.47      ]
 [  8.65428668  44.67195851   1.47      ]
 [  9.4113917   22.9850347    1.47      ]
 [  9.4113917  -22.9850347    1.47      ]
 [  9.94527716 -74.16952628   1.47      ]
 [  9.94527716  74.16952628   1.47      ]
 [ 10.16924521  10.01274933   1.47      ]
 [ 10.16924521 -10.01274933   1.47      ]
 [ 10.20644567 -53.21545998   1.47      ]
 [ 10.20644567  53.21545998   1.47      ]
 [ 10.57849119  31.43870375   1.47      ]
 [ 10.57849119 -31.43870375   1.47      ]
 [ 11.39521763  -5.07846224   1.47      ]
 [ 11.39521763   5.07846224   1.47      ]
 [ 11.71781242  18.18752703   1.47      ]
 [ 11.71781242 -18.18752703   1.47      ]
 [ 11.83033621   0.           1.47      ]
 [ 12.00910817  39.98781129   1.47      ]
 [ 12.00910817 -39.98781129   1.47      ]
 [ 12.55572647 -61.64591517   1.47      ]
 [ 12.55572647  61.64591517   1.47      ]
 [ 13.18808541  26.61516878   1.47      ]
 [ 13.18808541 -26.61516878   1.47      ]
 [ 13.57223424 -13.20668987   1.47      ]
 [ 13.57223424  13.20668987   1.47      ]
 [ 13.93222636  48.53955038   1.47      ]
 [ 13.93222636 -48.53955038   1.47      ]
 [ 14.86973294 -35.15709506   1.47      ]
 [ 14.86973294  35.15709506   1.47      ]
 [ 14.9005703    8.03442269   1.47      ]
 [ 14.9005703   -8.03442269   1.47      ]
 [ 15.39564168 -21.62918492   1.47      ]
 [ 15.39564168  21.62918492   1.47      ]
 [ 15.6042627    2.70038857   1.47      ]
 [ 15.6042627   -2.70038857   1.47      ]
 [ 16.36946156 -81.6400267    1.47      ]
 [ 16.36946156  81.6400267    1.47      ]
 [ 16.48669352  69.83188274   1.47      ]
 [ 16.48669352 -69.83188274   1.47      ]
 [ 16.7150029  -57.00288364   1.47      ]
 [ 16.7150029   57.00288364   1.47      ]
 [ 17.02691737  43.71636296   1.47      ]
 [ 17.02691737 -43.71636296   1.47      ]
 [ 17.19395061 -16.46805812   1.47      ]
 [ 17.19395061  16.46805812   1.47      ]
 [ 17.30592586  30.17930126   1.47      ]
 [ 17.30592586 -30.17930126   1.47      ]
 [ 18.5483898  -11.124716     1.47      ]
 [ 18.5483898   11.124716     1.47      ]
 [ 19.35894951  25.04791476   1.47      ]
 [ 19.35894951 -25.04791476   1.47      ]
 [ 19.40203659  -5.61508214   1.47      ]
 [ 19.40203659   5.61508214   1.47      ]
 [ 19.62236001  38.75484136   1.47      ]
 [ 19.62236001 -38.75484136   1.47      ]
 [ 19.69547046   0.           1.47      ]
 [ 20.01992939  52.2039386    1.47      ]
 [ 20.01992939 -52.2039386    1.47      ]
 [ 21.04482476 -19.7531228    1.47      ]
 [ 21.04482476  19.7531228    1.47      ]
 [ 21.08234374  65.25985975   1.47      ]
 [ 21.08234374 -65.25985975   1.47      ]
 [ 21.80747487 -33.65623199   1.47      ]
 [ 21.80747487  33.65623199   1.47      ]
 [ 22.35617628  14.28763204   1.47      ]
 [ 22.35617628 -14.28763204   1.47      ]
 [ 22.7019775  -47.26870019   1.47      ]
 [ 22.7019775   47.26870019   1.47      ]
 [ 23.26547643   8.65819735   1.47      ]
 [ 23.26547643  -8.65819735   1.47      ]
 [ 23.63943111 -28.41582338   1.47      ]
 [ 23.63943111  28.41582338   1.47      ]
 [ 23.7346488    2.9023498    1.47      ]
 [ 23.7346488   -2.9023498    1.47      ]
 [ 24.21803858 -77.53803241   1.47      ]
 [ 24.21803858  77.53803241   1.47      ]
 [ 24.47980904  60.51175385   1.47      ]
 [ 24.47980904 -60.51175385   1.47      ]
 [ 24.91227418 -42.20657626   1.47      ]
 [ 24.91227418  42.20657626   1.47      ]
 [ 25.15024972  23.02517483   1.47      ]
 [ 25.15024972 -23.02517483   1.47      ]
 [ 26.35068855 -17.47624816   1.47      ]
 [ 26.35068855  17.47624816   1.47      ]
 [ 26.75062552  37.01937754   1.47      ]
 [ 26.75062552 -37.01937754   1.47      ]
 [ 27.0913713  -55.62120718   1.47      ]
 [ 27.0913713   55.62120718   1.47      ]
 [ 27.23340936  11.76937527   1.47      ]
 [ 27.23340936 -11.76937527   1.47      ]
 [ 27.77832208  -5.92590316   1.47      ]
 [ 27.77832208   5.92590316   1.47      ]
 [ 27.9632508    0.           1.47      ]
 [ 28.28221843 -31.70311174   1.47      ]
 [ 28.28221843  31.70311174   1.47      ]
 [ 28.76376549  73.11464641   1.47      ]
 [ 28.76376549 -73.11464641   1.47      ]
 [ 29.1592042  -50.60695206   1.47      ]
 [ 29.1592042   50.60695206   1.47      ]
 [ 29.54728944  26.24983039   1.47      ]
 [ 29.54728944 -26.24983039   1.47      ]
 [ 30.56674657 -20.65061551   1.47      ]
 [ 30.56674657  20.65061551   1.47      ]
 [ 30.83270788  45.47781292   1.47      ]
 [ 30.83270788 -45.47781292   1.47      ]
 [ 31.34578223 -14.9011977    1.47      ]
 [ 31.34578223  14.9011977    1.47      ]
 [ 31.72271753  68.47240153   1.47      ]
 [ 31.72271753 -68.47240153   1.47      ]
 [ 31.87747186  -9.01147133   1.47      ]
 [ 31.87747186   9.01147133   1.47      ]
 [ 32.14860743   3.0170113    1.47      ]
 [ 32.14860743  -3.0170113    1.47      ]
 [ 32.20717627 -40.23544245   1.47      ]
 [ 32.20717627  40.23544245   1.47      ]
 [ 33.34422421  34.87601987   1.47      ]
 [ 33.34422421 -34.87601987   1.47      ]
 [ 33.80374677 -63.6670032    1.47      ]
 [ 33.80374677  63.6670032    1.47      ]
 [ 34.28301486  29.39174041   1.47      ]
 [ 34.28301486 -29.39174041   1.47      ]
 [ 35.04658869 -23.77296238   1.47      ]
 [ 35.04658869  23.77296238   1.47      ]
 [ 35.34895957  58.73011406   1.47      ]
 [ 35.34895957 -58.73011406   1.47      ]
 [ 35.64559338 -18.01217841   1.47      ]
 [ 35.64559338  18.01217841   1.47      ]
 [ 36.08099358  12.11111736   1.47      ]
 [ 36.08099358 -12.11111736   1.47      ]
 [ 36.3472473   -6.09089013   1.47      ]
 [ 36.3472473    6.09089013   1.47      ]
 [ 36.43710696   0.           1.47      ]
 [ 36.54240134 -53.67929106   1.47      ]
 [ 36.54240134  53.67929106   1.47      ]
 [ 37.49104029  48.52285063   1.47      ]
 [ 37.49104029 -48.52285063   1.47      ]
 [ 38.26049473 -43.26244646   1.47      ]
 [ 38.26049473  43.26244646   1.47      ]
 [ 38.89235441  37.89458326   1.47      ]
 [ 38.89235441 -37.89458326   1.47      ]
 [ 39.41317128 -32.41179615   1.47      ]
 [ 39.41317128  32.41179615   1.47      ]
 [ 39.83934649  26.80417916   1.47      ]
 [ 39.83934649 -26.80417916   1.47      ]
 [ 40.17988842 -21.06217068   1.47      ]
 [ 40.17988842  21.06217068   1.47      ]
 [ 40.4381312   15.18178714   1.47      ]
 [ 40.4381312  -15.18178714   1.47      ]
 [ 40.61322257  -9.17306752   1.47      ]
 [ 40.61322257   9.17306752   1.47      ]
 [ 40.70208965   3.06953652   1.47      ]
 [ 40.70208965  -3.06953652   1.47      ]
 [ 45.         -87.68120488   1.47      ]
 [ 45.         -84.20260831   1.47      ]
 [ 45.         -80.15364767   1.47      ]
 [ 45.         -75.76582943   1.47      ]
 [ 45.         -71.14963815   1.47      ]
 [ 45.         -66.36539941   1.47      ]
 [ 45.         -61.44781755   1.47      ]
 [ 45.         -56.41666981   1.47      ]
 [ 45.         -51.28206575   1.47      ]
 [ 45.         -46.04723346   1.47      ]
 [ 45.         -40.71010299   1.47      ]
 [ 45.         -35.26438968   1.47      ]
 [ 45.         -29.70075831   1.47      ]
 [ 45.         -24.00879372   1.47      ]
 [ 45.         -18.18080994   1.47      ]
 [ 45.         -12.21860297   1.47      ]
 [ 45.          -6.14282693   1.47      ]
 [ 45.           0.           1.47      ]
 [ 45.           6.14282693   1.47      ]
 [ 45.          12.21860297   1.47      ]
 [ 45.          18.18080994   1.47      ]
 [ 45.          24.00879372   1.47      ]
 [ 45.          29.70075831   1.47      ]
 [ 45.          35.26438968   1.47      ]
 [ 45.          40.71010299   1.47      ]
 [ 45.          46.04723346   1.47      ]
 [ 45.          51.28206575   1.47      ]
 [ 45.          56.41666981   1.47      ]
 [ 45.          61.44781755   1.47      ]
 [ 45.          66.36539941   1.47      ]
 [ 45.          71.14963815   1.47      ]
 [ 45.          75.76582943   1.47      ]
 [ 45.          80.15364767   1.47      ]
 [ 45.          84.20260831   1.47      ]
 [ 45.          87.68120488   1.47      ]
 [ 49.29791035   3.06953652   1.47      ]
 [ 49.29791035  -3.06953652   1.47      ]
 [ 49.38677743  -9.17306752   1.47      ]
 [ 49.38677743   9.17306752   1.47      ]
 [ 49.5618688   15.18178714   1.47      ]
 [ 49.5618688  -15.18178714   1.47      ]
 [ 49.82011158 -21.06217068   1.47      ]
 [ 49.82011158  21.06217068   1.47      ]
 [ 50.16065351  26.80417916   1.47      ]
 [ 50.16065351 -26.80417916   1.47      ]
 [ 50.58682872 -32.41179615   1.47      ]
 [ 50.58682872  32.41179615   1.47      ]
 [ 51.10764559  37.89458326   1.47      ]
 [ 51.10764559 -37.89458326   1.47      ]
 [ 51.73950527 -43.26244646   1.47      ]
 [ 51.73950527  43.26244646   1.47      ]
 [ 52.50895971  48.52285063   1.47      ]
 [ 52.50895971 -48.52285063   1.47      ]
 [ 53.45759866 -53.67929106   1.47      ]
 [ 53.45759866  53.67929106   1.47      ]
 [ 53.56289304   0.           1.47      ]
 [ 53.6527527   -6.09089013   1.47      ]
 [ 53.6527527    6.09089013   1.47      ]
 [ 53.91900642  12.11111736   1.47      ]
 [ 53.91900642 -12.11111736   1.47      ]
 [ 54.35440662 -18.01217841   1.47      ]
 [ 54.35440662  18.01217841   1.47      ]
 [ 54.65104043  58.73011406   1.47      ]
 [ 54.65104043 -58.73011406   1.47      ]
 [ 54.95341131 -23.77296238   1.47      ]
 [ 54.95341131  23.77296238   1.47      ]
 [ 55.71698514  29.39174041   1.47      ]
 [ 55.71698514 -29.39174041   1.47      ]
 [ 56.19625323 -63.6670032    1.47      ]
 [ 56.19625323  63.6670032    1.47      ]
 [ 56.65577579  34.87601987   1.47      ]
 [ 56.65577579 -34.87601987   1.47      ]
 [ 57.79282373 -40.23544245   1.47      ]
 [ 57.79282373  40.23544245   1.47      ]
 [ 57.85139257   3.0170113    1.47      ]
 [ 57.85139257  -3.0170113    1.47      ]
 [ 58.12252814  -9.01147133   1.47      ]
 [ 58.12252814   9.01147133   1.47      ]
 [ 58.27728247  68.47240153   1.47      ]
 [ 58.27728247 -68.47240153   1.47      ]
 [ 58.65421777 -14.9011977    1.47      ]
 [ 58.65421777  14.9011977    1.47      ]
 [ 59.16729212  45.47781292   1.47      ]
 [ 59.16729212 -45.47781292   1.47      ]
 [ 59.43325343 -20.65061551   1.47      ]
 [ 59.43325343  20.65061551   1.47      ]
 [ 60.45271056  26.24983039   1.47      ]
 [ 60.45271056 -26.24983039   1.47      ]
 [ 60.8407958  -50.60695206   1.47      ]
 [ 60.8407958   50.60695206   1.47      ]
 [ 61.23623451  73.11464641   1.47      ]
 [ 61.23623451 -73.11464641   1.47      ]
 [ 61.71778157 -31.70311174   1.47      ]
 [ 61.71778157  31.70311174   1.47      ]
 [ 62.0367492    0.           1.47      ]
 [ 62.22167792  -5.92590316   1.47      ]
 [ 62.22167792   5.92590316   1.47      ]
 [ 62.76659064  11.76937527   1.47      ]
 [ 62.76659064 -11.76937527   1.47      ]
 [ 62.9086287  -55.62120718   1.47      ]
 [ 62.9086287   55.62120718   1.47      ]
 [ 63.24937448  37.01937754   1.47      ]
 [ 63.24937448 -37.01937754   1.47      ]
 [ 63.64931145 -17.47624816   1.47      ]
 [ 63.64931145  17.47624816   1.47      ]
 [ 64.84975028  23.02517483   1.47      ]
 [ 64.84975028 -23.02517483   1.47      ]
 [ 65.08772582 -42.20657626   1.47      ]
 [ 65.08772582  42.20657626   1.47      ]
 [ 65.52019096  60.51175385   1.47      ]
 [ 65.52019096 -60.51175385   1.47      ]
 [ 65.78196142 -77.53803241   1.47      ]
 [ 65.78196142  77.53803241   1.47      ]
 [ 66.2653512    2.9023498    1.47      ]
 [ 66.2653512   -2.9023498    1.47      ]
 [ 66.36056889 -28.41582338   1.47      ]
 [ 66.36056889  28.41582338   1.47      ]
 [ 66.73452357   8.65819735   1.47      ]
 [ 66.73452357  -8.65819735   1.47      ]
 [ 67.2980225  -47.26870019   1.47      ]
 [ 67.2980225   47.26870019   1.47      ]
 [ 67.64382372  14.28763204   1.47      ]
 [ 67.64382372 -14.28763204   1.47      ]
 [ 68.19252513 -33.65623199   1.47      ]
 [ 68.19252513  33.65623199   1.47      ]
 [ 68.91765626  65.25985975   1.47      ]
 [ 68.91765626 -65.25985975   1.47      ]
 [ 68.95517524 -19.7531228    1.47      ]
 [ 68.95517524  19.7531228    1.47      ]
 [ 69.98007061  52.2039386    1.47      ]
 [ 69.98007061 -52.2039386    1.47      ]
 [ 70.30452954   0.           1.47      ]
 [ 70.37763999  38.75484136   1.47      ]
 [ 70.37763999 -38.75484136   1.47      ]
 [ 70.59796341  -5.61508214   1.47      ]
 [ 70.59796341   5.61508214   1.47      ]
 [ 70.64105049  25.04791476   1.47      ]
 [ 70.64105049 -25.04791476   1.47      ]
 [ 71.4516102  -11.124716     1.47      ]
 [ 71.4516102   11.124716     1.47      ]
 [ 72.69407414  30.17930126   1.47      ]
 [ 72.69407414 -30.17930126   1.47      ]
 [ 72.80604939 -16.46805812   1.47      ]
 [ 72.80604939  16.46805812   1.47      ]
 [ 72.97308263  43.71636296   1.47      ]
 [ 72.97308263 -43.71636296   1.47      ]
 [ 73.2849971  -57.00288364   1.47      ]
 [ 73.2849971   57.00288364   1.47      ]
 [ 73.51330648  69.83188274   1.47      ]
 [ 73.51330648 -69.83188274   1.47      ]
 [ 73.63053844 -81.6400267    1.47      ]
 [ 73.63053844  81.6400267    1.47      ]
 [ 74.3957373    2.70038857   1.47      ]
 [ 74.3957373   -2.70038857   1.47      ]
 [ 74.60435832 -21.62918492   1.47      ]
 [ 74.60435832  21.62918492   1.47      ]
 [ 75.0994297    8.03442269   1.47      ]
 [ 75.0994297   -8.03442269   1.47      ]
 [ 75.13026706 -35.15709506   1.47      ]
 [ 75.13026706  35.15709506   1.47      ]
 [ 76.06777364  48.53955038   1.47      ]
 [ 76.06777364 -48.53955038   1.47      ]
 [ 76.42776576 -13.20668987   1.47      ]
 [ 76.42776576  13.20668987   1.47      ]
 [ 76.81191459  26.61516878   1.47      ]
 [ 76.81191459 -26.61516878   1.47      ]
 [ 77.44427353 -61.64591517   1.47      ]
 [ 77.44427353  61.64591517   1.47      ]
 [ 77.99089183  39.98781129   1.47      ]
 [ 77.99089183 -39.98781129   1.47      ]
 [ 78.16966379   0.           1.47      ]
 [ 78.28218758  18.18752703   1.47      ]
 [ 78.28218758 -18.18752703   1.47      ]
 [ 78.60478237  -5.07846224   1.47      ]
 [ 78.60478237   5.07846224   1.47      ]
 [ 79.42150881  31.43870375   1.47      ]
 [ 79.42150881 -31.43870375   1.47      ]
 [ 79.79355433 -53.21545998   1.47      ]
 [ 79.79355433  53.21545998   1.47      ]
 [ 79.83075479  10.01274933   1.47      ]
 [ 79.83075479 -10.01274933   1.47      ]
 [ 80.05472284 -74.16952628   1.47      ]
 [ 80.05472284  74.16952628   1.47      ]
 [ 80.5886083   22.9850347    1.47      ]
 [ 80.5886083  -22.9850347    1.47      ]
 [ 81.34571332 -44.67195851   1.47      ]
 [ 81.34571332  44.67195851   1.47      ]
 [ 81.68984707  14.75097316   1.47      ]
 [ 81.68984707 -14.75097316   1.47      ]
 [ 81.97439735  -2.34839855   1.47      ]
 [ 81.97439735   2.34839855   1.47      ]
 [ 82.45314223  36.10960472   1.47      ]
 [ 82.45314223 -36.10960472   1.47      ]
 [ 82.82085324 -66.09875172   1.47      ]
 [ 82.82085324  66.09875172   1.47      ]
 [ 83.00320676   6.9451987    1.47      ]
 [ 83.00320676  -6.9451987    1.47      ]
 [ 83.30882873 -27.61716167   1.47      ]
 [ 83.30882873  27.61716167   1.47      ]
 [ 84.049201    19.30523849   1.47      ]
 [ 84.049201   -19.30523849   1.47      ]
 [ 84.34337772 -57.72525378   1.47      ]
 [ 84.34337772  57.72525378   1.47      ]
 [ 84.81996652  11.34988901   1.47      ]
 [ 84.81996652 -11.34988901   1.47      ]
 [ 85.2073787    0.           1.47      ]
 [ 85.29910019  49.2024397    1.47      ]
 [ 85.29910019 -49.2024397    1.47      ]
 [ 85.8936229   -4.09587122   1.47      ]
 [ 85.8936229    4.09587122   1.47      ]
 [ 85.95393104  40.63141594   1.47      ]
 [ 85.95393104 -40.63141594   1.47      ]
 [ 86.43791752 -32.09871039   1.47      ]
 [ 86.43791752  32.09871039   1.47      ]
 [ 86.83000993  23.70233802   1.47      ]
 [ 86.83000993 -23.70233802   1.47      ]
 [ 87.19643507 -15.58649429   1.47      ]
 [ 87.19643507  15.58649429   1.47      ]
 [ 87.62839961   8.01881788   1.47      ]
 [ 87.62839961  -8.01881788   1.47      ]
 [ 88.35991659  -1.6394119    1.47      ]
 [ 88.35991659   1.6394119    1.47      ]
 [ 90.          85.2073787    1.47      ]
 [ 90.          78.16966379   1.47      ]
 [ 90.          70.30452954   1.47      ]
 [ 90.          62.0367492    1.47      ]
 [ 90.          53.56289304   1.47      ]
 [ 90.          45.           1.47      ]
 [ 90.          36.43710696   1.47      ]
 [ 90.          27.9632508    1.47      ]
 [ 90.          19.69547046   1.47      ]
 [ 90.          11.83033621   1.47      ]
 [ 90.           4.7926213    1.47      ]
 [ 90.           0.           1.47      ]
 [ 90.          -4.7926213    1.47      ]
 [ 90.         -11.83033621   1.47      ]
 [ 90.         -19.69547046   1.47      ]
 [ 90.         -27.9632508    1.47      ]
 [ 90.         -36.43710696   1.47      ]
 [ 90.         -45.           1.47      ]
 [ 90.         -53.56289304   1.47      ]
 [ 90.         -62.0367492    1.47      ]
 [ 90.         -70.30452954   1.47      ]
 [ 90.         -78.16966379   1.47      ]
 [ 90.         -85.2073787    1.47      ]
 [ 91.64008341  -1.6394119    1.47      ]
 [ 91.64008341   1.6394119    1.47      ]
 [ 92.37160039   8.01881788   1.47      ]
 [ 92.37160039  -8.01881788   1.47      ]
 [ 92.80356493 -15.58649429   1.47      ]
 [ 92.80356493  15.58649429   1.47      ]
 [ 93.16999007  23.70233802   1.47      ]
 [ 93.16999007 -23.70233802   1.47      ]
 [ 93.56208248 -32.09871039   1.47      ]
 [ 93.56208248  32.09871039   1.47      ]
 [ 94.04606896  40.63141594   1.47      ]
 [ 94.04606896 -40.63141594   1.47      ]
 [ 94.1063771   -4.09587122   1.47      ]
 [ 94.1063771    4.09587122   1.47      ]
 [ 94.70089981  49.2024397    1.47      ]
 [ 94.70089981 -49.2024397    1.47      ]
 [ 94.7926213    0.           1.47      ]
 [ 95.18003348  11.34988901   1.47      ]
 [ 95.18003348 -11.34988901   1.47      ]
 [ 95.65662228 -57.72525378   1.47      ]
 [ 95.65662228  57.72525378   1.47      ]
 [ 95.950799    19.30523849   1.47      ]
 [ 95.950799   -19.30523849   1.47      ]
 [ 96.69117127 -27.61716167   1.47      ]
 [ 96.69117127  27.61716167   1.47      ]
 [ 96.99679324   6.9451987    1.47      ]
 [ 96.99679324  -6.9451987    1.47      ]
 [ 97.17914676 -66.09875172   1.47      ]
 [ 97.17914676  66.09875172   1.47      ]
 [ 97.54685777  36.10960472   1.47      ]
  ecc...
$\endgroup$

2 Answers 2

1
$\begingroup$

For your known bug:

Since your azimuth-elevation grid is uniformly distributed, finding the closest triangle containing the target direction is not difficult.

Say the target direction is $(\varphi, \vartheta)$. Let $\varphi = [\varphi_1, \varphi_2, ..., \varphi_M]$ and $\vartheta=[\vartheta_1, \vartheta_2, ..., \vartheta_N]$ be ascending sorted arrays of azimuths and elevations, respectively. You can use binary search to find the closest azimuth-elevation pair $(\varphi_m, \vartheta_n)$ satisfying $\varphi_m\leq\varphi$ and $\vartheta_n\leq\vartheta$, and the other two points should be $(\varphi_{m+1}, \vartheta_n)$ and $(\varphi_m, \vartheta_{n+1})$. Note the azimuth wraping at 360$^\circ$.

Other things to note:

As you are interpolating HRIR, you should calculate the weighted average of the minimum-phase parts of HRIRs. The detailed steps are: remove the delays of HRIRs, interpolate, add new delays calculated by specific interpolation method.

Why should you perform interpolation on the minimum-phase part, think of two HRIRs which are ideal delta functions.

$h_1(t) = A_1\delta(t_1)$ and $h_2(t) = A_2\delta(t_2)$, where $A_1$ and $A_2$ are respectively amplitude of HRIRs and $t_1$ is generally not equal to $t_2$. You will get two pulses if you just sum $h_1(t)$ and $h_2(t)$ up with different weights, which is obviously not the result we want.

$\endgroup$
12
  • $\begingroup$ Are you assuming to order the azimuths and elevations indipendently? Because (maybe i'm wrong) if i do this way, i could end up with a couple of (azimuth,elevation) which doesnt exist in my dataset. I edited my question with an example of the available positions data. I am sorry but I didn't understand the second point, what do you mean by 'also found in the first case'? $\endgroup$ Jan 14, 2021 at 9:50
  • $\begingroup$ @MattiaSurricchio Yes my approach to find triangles only works for mesh grid of azimuth-elevation pairs, so it doesn't work for your database. Maybe you can search for a mature VBAP code, or choose another database. I think most databases have uniformly distributed source positions, because it is easy to do the measurement. And the second point is saying that as seen from the waveform of your first audio example without interpolation, the jumping gains are also observed. $\endgroup$
    – ZR Han
    Jan 14, 2021 at 12:25
  • $\begingroup$ Did you plot the waveform of the audio file? I actually didn't, but from the only listening perspective, it seemed that the volume of my audio file in the different spatial positions is more or less constant, there are no huge jumps in the perceived audio volume. Do you have any other database you could suggest me? The ones that i know (KEMAR, CIPIC ecc...) they still have the same problem i mentioned, you have fixed couples of (azimuth,elevation). Maybe i'm doing something wrong, but ordering azimuth and elevations indipendetly, could lead to the same problem i've already mentioned $\endgroup$ Jan 14, 2021 at 12:48
  • $\begingroup$ If you are referring to those spikes, as you might notice they're almost periodical, they are probably the consequence of my real time processing. I'm basically taking n samples from real time audio and then i convolve them with the selected HRIR. $\endgroup$ Jan 14, 2021 at 13:11
  • 1
    $\begingroup$ @MattiaSurricchio A decently working HRTF processing will not produce these peaks, unless your input signals contain these peaks periodically. Otherwise, there is something wrong with your framing operation. BTW, the database I use is Priceton's 3D3A database, which has 72 azimuths: [0°, 5°, 10°, …, 355°] and 9 elevations: [–57°, –30°, –15°, 0°, 15°, 30°, 45°, 60°, 75°] (72 × 9 = 648 positions in total). $\endgroup$
    – ZR Han
    Jan 14, 2021 at 13:23
1
$\begingroup$

This is a long post with a lot of info, I just and give some high level feedback

  1. Loose the 1.47 scale factor and just do everything on the unit sphere. If absolute distance/gain matters, just scale your whole HRIR set by 1.47/1.
  2. If you do a three point interpolation, the three points should form a triangle which encloses the point that you want. These are NOT necessarily the three closest point (depending on how your grid looks like) and your result seem to indicate cases where this is not the enclosing triangle.
  3. Gain normalization is tricky: at low frequencies HRIR add in amplitude and not in energy, i.e. they are highly correlated.

Here is what I would do

  1. Normalize HRIR data base to the unit sphere.
  2. Find the enclosing triangle.
  3. If the target point is "very close" to one side of the triangle, I would just do a two point interpolation
  4. Calculate the gains as the inverse of the distance of each vertex (triangle or line) to the target point
  5. Normalize the gains so that the sum of the gains (NOT the square of the gains) is unity. You have a fairly dense grid of HRIRs so you will see way more correlated summing than uncorrelated summing.

An alternative approach would be a 4 point interpolation. Do two 2-point azimuth interpolations at the two nearest elevations and then another 2-point elevation between the results of azimuth interpolations. That has the advantage that you can line up the interaural delays for different azimuth angles before interpolating. So you interpolate the interaural delays and the spectral features separately.

A completely different approach for this type of thing as spherical harmonics. You can represent the entire data set through a series of spherical harmonics and just do a weighted sum of the harmonics at the target location.

$\endgroup$
3
  • $\begingroup$ So I removed the 1.47 constant (thus working on the unit circle) and used the suggested gain normalization, but the problem still holds. Your 4th point suggest to compute the gains in that way, is it wrong to use the VBAP formula? Furthermore, I updated the question with a visualization of the data. I expected to get triangle meshes by computing the 3 nearest points, but sometimes it seems that it doesn't work. Do you have an idea about why? Given the data "structure" it seemed reasonable to compute the three nearest point and expect a triangle as result $\endgroup$ Jan 13, 2021 at 19:49
  • $\begingroup$ I'm not familiar with VBAP so I can't help. However, it looks like some of the gains are negative, which makes no sense, so something must be wrong there, $\endgroup$
    – Hilmar
    Jan 13, 2021 at 21:24
  • $\begingroup$ Yes, they are negative for some triplets because the desired point is not contained inside the triangle created by the 3 closest point, i mentioned that in the "known bugs" part $\endgroup$ Jan 14, 2021 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.