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?