You can always use cheap approximations. I suppose you need to compute
tangents, in which case polynomial and rational approximations are easy
to derive and implement with likely satisfactory results, especially if
you know the range of interest in advance.
I don't know how well JavaScript engines actually manage to run
(real-time?) DSP code these days, but in case you go to the WebAssembly
route beware that emscripten might implement calls to standard/math
library functions by "context switching" between WebAssembly and
JavaScript, which would give you huge performance penalties.
The approach we've taken with my company to run custom DSP code in the
browser relies on both using our own implementations/approximations
(https://github.com/sdangelo/brickworks/blob/main/include/bw_math.h) and
building WebAssembly modules using Clang directly (see
https://github.com/sdangelo/brickworks/blob/main/examples/common/web/web.mk).
It's been working wonders for us.
Best,
Stefano D'Angelo
Il 02/05/23 04:48, Yisheng Jiang ha scritto:
I'm not sure. I just always had fear of doing trigonometry, asking
some (script) to do it potentially 48000/second * several voices per
channel * 16 channels seems demanding it alot.
but i took your email as a challenge and just plugged them in the
loop, and so far it hasn't melted down my computer.
it fact it sounds much better than before, I can see the fft graph of
the piano move to the right and hear it.
---------- Forwarded message ---------
From: *Stefano D'Angelo* <[email protected]>
Date: Mon, May 1, 2023 at 12:53 AM
Subject: Re: Rendering note with dynamic low-pass filter by cross fading
To: <[email protected]>
Il 26/04/23 05:39, Yisheng Jiang ha scritto:
> To make concrete of what I’m trying to do, here’s a (wip) code example
>
https://github.com/yishengjiang99/sf2rend/blob/bacca1bf2092dbd78b1affacac11155b70f1bc55/spin/mk_lpf_fade.js#L29
>
> Sent from my iPhone
>
>> On Apr 25, 2023, at 8:37 PM, Yisheng Jiang <[email protected]>
>> wrote:
>>
>> I’m trying to render a note that feed into a IIR filter (2-3 poles)
>> whose cutoff frequency following an envelope generator, and it’s not
>> possible for me to compute the z-transform parameters every rendering
>> block..
>>
>> Is it approximately the same to generate two pcm streams with the
>> starting and ending cutoff frequencies, then cross fade them to make
>> the resultant sound?
>>
>>
May I ask why you can't compute coefficients continuously (each block/N
samples)? What sort of platform are you targeting? The repo hints at a
web page/app...
Best,
Stefano D'Angelo