1
$\begingroup$

I've already made 2 posts that I've deleted about this because I've found the solution. So I'm trying to implement Ville Pulkki's VBAP algorithm in typescript with math.js.

here is how my code looks like so far:

 calculateWeights = ( source:VirtualSource ) => { let results:number[][] = []; let p = math.matrix( [ source.object.position.x, source.object.position.y, source.object.position.z ] ); for ( let triplet of this.triplets ) { const l = math.matrix( [ [ triplet[ 0 ][ 0 ], triplet[ 0 ][ 1 ], triplet[ 0 ][ 2 ] ], [ triplet[ 1 ][ 0 ], triplet[ 1 ][ 1 ], triplet[ 1 ][ 2 ] ], [ triplet[ 2 ][ 0 ], triplet[ 2 ][ 1 ], triplet[ 2 ][ 2 ] ] ] ) if (math.det( l ) === 0 ) { console.log( 'determinant is 0' ); results.push( [ 0, 0, 0 ] ); continue; } const lInv = math.inv( l ); let g1 = math.dot( p, [ lInv.get( [ 0, 0 ] ), lInv.get( [ 0, 1 ] ), lInv.get( [ 0, 2 ] ) ] ); let g2 = math.dot( p, [ lInv.get( [ 1, 0 ] ), lInv.get( [ 1, 1 ] ), lInv.get( [ 1, 2 ] ) ] ); let g3 = math.dot( p, [ lInv.get( [ 2, 0 ] ), lInv.get( [ 2, 1 ] ), lInv.get( [ 2, 2 ] ) ] ); g1 = Math.max( 0, g1 ); g2 = Math.max( 0, g2 ); g3 = Math.max( 0, g3 ); const C = g1 * g1 + g2 * g2 + g3 * g3; const den = Math.sqrt( g1 * g1 + g2 * g2 + g3 * g3 ); const g1Scaled = Math.sqrt( C * g1 ) / den; const g2Scaled = Math.sqrt( C * g2 ) / den; const g3Scaled = Math.sqrt( C * g3 ) / den; results.push( [ g1Scaled, g2Scaled, g3Scaled ] ); } return ( results ); } 

triplets is a set of 3 speakers x, y, z positions.

I've tried understanding the paper and I can get some sort of different panning but my result are not as perceptible as I though it would be when changing the source position.

I was also forced to crop the values to 0 because negative values gave me NaN values when trying to square root.

Am I doing something wrong or does it look coherent?

$\endgroup$
8
  • 1
    $\begingroup$ The article mentions (pp. 458, second column right at the first paragraph) that the gain factors are non-negative scalars, and if I am not mistaken, in the formulation, they are supposed to be real, too. In this regard, it would be better to get the absolute values of the gains and use those. If you think about it, negative gains would just mean a phase inversion, which is not relevant to VBAP (as far as I am aware). $\endgroup$ Commented Jan 9 at 10:18
  • $\begingroup$ @ZaellixA Thank you for your answer.If I understand well you are telling me to take the absolute value when I get a negative value.Wouldn't this result in a loud gain (My gain can only go from 0 to anything ) in case of -2 for example. $\endgroup$ Commented Jan 9 at 10:25
  • $\begingroup$ Well, if I understand the article correctly, this shouldn’t be a problem. If you get a -2 gain, isn’t that supposed to be a gain of 2 with a negative phase? If not, could you please clarify why? $\endgroup$ Commented Jan 9 at 10:27
  • $\begingroup$ @ZaellixA Honestly I don't know this is why I've asked SE.Have you had a chance to look at the code does it look correct (btw I'll will try adding the absolute value). Thanks in advance $\endgroup$ Commented Jan 9 at 10:29
  • 1
    $\begingroup$ @ZaellixA ok sure will do $\endgroup$ Commented Jan 9 at 10:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.