Math help

For general discussion related FlowStone
adamszabo
Posts: 667
Joined: Sun Jul 11, 2010 7:21 am

Math help

Post by adamszabo »

Hey friends,

I have to revisit an old code with this nasty formula: 0.0001^( SampleRate / ( 10^(( x-1)*4.307) - 4.925e-005 )*600 ), and I have to rewrite this in stream form, which will use way too much CPU because there are too many powers and a division. Are there any math wizards that can help me rewrite this in a much simpler form? It doesnt matter if there are some errors, as long as its close to it. The only variable is the 'x' and a samplerate input.

Thank you!
Attachments
formula.fsm
(254.63 KiB) Downloaded 1043 times
User avatar
aronb
Posts: 154
Joined: Sun Apr 17, 2011 3:08 am
Location: Florida, USA
Contact:

Re: Math help

Post by aronb »

Hi,

I might be able to help... BUT I have a few questions:

1) What are you calculating? Might be a more efficient way...
2) Otherwise is it just that EXACT formula?
3) What tolerances do you need? How exact does what you are calculating have to be...

Thank you,

Aron
juha_tp
Posts: 60
Joined: Fri Nov 09, 2018 10:37 pm

Re: Math help

Post by juha_tp »

Try Simplify[0.0001^( f / ( 10^(( x-1)*4.307) - 4.925e-005 )*600 )] at https://www.wolframalpha.com/
MichaelBenjamin
Posts: 275
Joined: Tue Jul 13, 2010 1:32 pm

Re: Math help

Post by MichaelBenjamin »

.
Last edited by MichaelBenjamin on Mon Sep 21, 2020 11:02 am, edited 1 time in total.
juha_tp
Posts: 60
Joined: Fri Nov 09, 2018 10:37 pm

Re: Math help

Post by juha_tp »

What is the range for variable "x" ?
adamszabo
Posts: 667
Joined: Sun Jul 11, 2010 7:21 am

Re: Math help

Post by adamszabo »

Thanks guys. This is for a decay calculation on my envelope so it needs to be pretty accurate, but it depends on the formula on how much cpu I can save. The range for the x input is from 0-1 only.
User avatar
martinvicanek
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: Math help

Post by martinvicanek »

The formula that is implemented in the schematic should read

0.0001^{1/[600*SampleRate*(10^4.307*(x - 1) - 4.925e-5)]}

For x in the range between 0 and 1, a reasonable approximation for 44.1k is

1 - (0.9939 + 2914*x)/(1 + x*(3102 + x*4356980))

Relative error is less than 1%.
adamszabo
Posts: 667
Joined: Sun Jul 11, 2010 7:21 am

Re: Math help

Post by adamszabo »

Thanks Martin!

The sample rate variable must be dynamic however, as the synth will get the samerate from the DAW. I cannot set it as fixed. Any ideas what to do in that case?
deraudrl
Posts: 239
Joined: Thu Nov 28, 2019 9:12 pm
Location: SoCal

Re: Math help

Post by deraudrl »

adamszabo wrote:Thanks Martin!

The sample rate variable must be dynamic however, as the synth will get the samerate from the DAW. I cannot set it as fixed. Any ideas what to do in that case?
Derive the constants in Martin's equation once when the sample rate changes, then use the simplified equation thereafter?

Or maybe just look them up from a table: I suspect the number of different values for sample rate that you need to be able to deal with is rather small.
I keep a pair of oven mitts next to my computer so I don't get a concussion from slapping my forehead while I'm reading the responses to my questions.
User avatar
martinvicanek
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: Math help

Post by martinvicanek »

Forget my previous post. If the quantity of interest is the decay factor per sample, you need much more accuracy. I can offer the attached implementation using fast powers.
Attachments
stream_formula.fsm
(121.88 KiB) Downloaded 1052 times
Post Reply