omnitone icon indicating copy to clipboard operation
omnitone copied to clipboard

Better support for Three.js integration

Open hoch opened this issue 6 years ago • 7 comments

@drewbitllama

What can be done to support the Three.js integration better? We can consider adding new APIs for this purpose.

FYI: This topic stemmed from this PR.

hoch avatar Mar 13 '18 21:03 hoch

Can you make it a smoother transition whenever a Listener/Source Position/Rotation is set? When I use a slider in Threejs to change the params, I always hear the clipping sounds, which is not so tolerable.

/**
 * Updates the rotation matrix with 4x4 matrix.
 * @param {Number[]} rotationMatrix4 - A 4x4 rotation matrix. (column-major)
 */
FOARotator.prototype.setRotationMatrix4 = function(rotationMatrix4) {
  this._m0.gain.value = rotationMatrix4[0];
  this._m1.gain.value = rotationMatrix4[1];
  this._m2.gain.value = rotationMatrix4[2];
  this._m3.gain.value = rotationMatrix4[4];
  this._m4.gain.value = rotationMatrix4[5];
  this._m5.gain.value = rotationMatrix4[6];
  this._m6.gain.value = rotationMatrix4[8];
  this._m7.gain.value = rotationMatrix4[9];
  this._m8.gain.value = rotationMatrix4[10];
};

Maybe can change it like

FOARotator.prototype.setRotationMatrix4 = function(rotationMatrix4, endTime=this.context.currentTime+0.01) {
  this._m0.gain.linearRampToValue(rotationMatrix4[0], endTime);
  ......
}

iooops avatar Mar 15 '19 07:03 iooops

Thanks for suggestion! There are two things to consider.

  1. We don't want to break things that are already using this function.
  2. Also there's performance implication of using AudioParam automation.
  3. Does linear interpolation of each value in the matrix make sense here?

1 or 2 is not a big deal, but I want to make sure about 3. These values are not directly related to the position or angle. The linear interpolation on each value might not make sense (mathematically) in this context. @drewbitllama might have some ideas on this.

Also if I have to add this feature, it'll be a new method tied to FOA/HOA rotator.

hoch avatar Mar 15 '19 16:03 hoch

I tried linear interpolation using JavaScript. It did improve the performance a lot. But still I can hear the clipping sound when I’m sliding very fast. It would be great if I can use the built-in omnitone/resonance audio function to do more precise smooth transition.

On Mar 15, 2019, at 09:10, Hongchan Choi [email protected] wrote:

Thanks for suggestion! There are two things to consider.

We don't want to break things that are already using this function. Also there's performance implication of using AudioParam automation. Does linear interpolation of each value in the matrix make sense here? 1 or 2 is not a big deal, but I want to make sure about 3. These values are not directly related to the position or angle. The linear interpolation on each value might not make sense (mathematically) in this context. @drewbitllama might have some ideas on this.

Also if I have to add this feature, it'll be a new method tied to FOA/HOA rotator.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

iooops avatar Mar 15 '19 19:03 iooops

Can you elaborate on "improve the performance a lot"? Does it use less CPU? Or you meant better audio quality (like less glitching)?

hoch avatar Mar 15 '19 19:03 hoch

Just less glitching compared to using it without interpolation. But still it has glitching.

On Mar 15, 2019, at 12:32, Hongchan Choi [email protected] wrote:

Can you elaborate on "improve the performance a lot"? Does it use less CPU? Or you meant better audio quality (like less glitching)?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

iooops avatar Mar 15 '19 20:03 iooops

Thanks. AudioParam.value = v is identical to AudioParam.setValueAtTime(v, t). So it is an instantaneous jump. No matter how you do it, it won't be sample-accurate interpolation.

On the other hand, setValueAtTime is much lighter than linearRampToValueAtTime function, but in this case I don't think it really matters in terms of the performance because it only has 9 AudioParams to deal with.

But the question still remains: is this mathematically correct? I have to rely on @drewbitllama's opinion on this. If the answer is yes, I can fix this right away.

hoch avatar Mar 15 '19 20:03 hoch

Hi there, I am currently working on a project that uses Omnitone and Three.js and wondering if there's any update on the issues raised in this thread. I am also encountering some glitching - even when moving quite slowly around the scene. Thanks!

ttoommmmiiee avatar Aug 15 '20 13:08 ttoommmmiiee