Jump to content

Any math experts here?


Recommended Posts

I've been exploring the possibility of creating audio plugins. I met this developer who seems to be interested in that so the first tool I was thinking of creating is a free plugin, an audio calculator where we can calculate delays, LFO rates, etc.

I've found some math calculations for some of the operations, but not all.

Any math experts here who could give me a hand?

Right now I'm trying to find these:

BPM note shift: Insert original BPM, insert target/final BPM and it will show you how many semitones you need to go up or down

Tempo shift: almost the same as the above, but reversed. Insert original BPM, insert target/final number of semitones and it will show you how much you need to slow down or speed up your song's tempo (final value is in BPM)

Closest Musical Note: Insert frequency in Hz and it will show you the closest musical note (for example C3 is 130.81Hz so if you type in 128Hz it will show you C3 as the closest musical note)

 

Anyone can give me a hand? Thanks!

 

Here's the prototype so far:

2073831496_AudioCalculator-LogicGUI.thumb.jpg.bbcb04c98189ef0ab023b982b49d3f78.jpg

Link to comment
Share on other sites

I failed school at maths, but...notes in tempered tuning are spaced apart by the 12th root of 2, which is 1,059463094359295 (magic number, it pays to memorize it if you're into that stuff, works also for string lengths on guitars, air columns in pipes etc.)

 

So if you play a 120 bpm sample one half step higher, you get 120 bpm * 1,059463094359295 = 127,135571323115432 bpm. Then, *that* multiplied by 1,059463094359295 gives you 134,695445797124758 bpm which is the next half step, and so on until you hit 240.0000000000 bpm after the twelvth time.

Link to comment
Share on other sites

I failed school at maths, but...notes in tempered tuning are spaced apart by the 12th root of 2, which is 1,059463094359295 (magic number, it pays to memorize it if you're into that stuff, works also for string lengths on guitars, air columns in pipes etc.)

 

So if you play a 120 bpm sample one half step higher, you get 120 bpm * 1,059463094359295 = 127,135571323115432 bpm. Then, *that* multiplied by 1,059463094359295 gives you 134,695445797124758 bpm which is the next half step, and so on until you hit 240.0000000000 bpm after the twelvth time.

 

Thanks for the reply.

I actually found out the math formula for that right after I posted. So basically it's this:

OriginalBPM × 2^(NumberOfSemitones ÷ 12)

 

So now I need to reverse it. Maybe you can help me with that?

So I need to find how many semi tones I need to transpose my song up or down, if I already know the original BPM and the final BPM.

I need the actual math formula so I can then give it to the developer.

 

Thanks

Link to comment
Share on other sites

Have you studied the online calculators such as http://www.thewhippinpost.co.uk/tools/index.htm ?

 

The calculations are all stored in a single JS file which you may be able to use for educational purposes perhaps?

http://www.thewhippinpost.co.uk/js/sample-calculator.js

 

The first function "Calculate(t1,t2)" is what you're looking for.

 

Thanks for the reply!

That doesn't really help me, it got me even more confused hahaha

I'm not the developer, so all that code is not something I would understand.

I'm just looking for a math formula (for example, if I was working on a spreadsheet) that gives me the number of semi tones between 2 different tempos (BPM).

 

Once I have that, then I can send it to the developer and let him do his magic. Hopefully he will know how to deconstruct the math equation and convert it into plugin code.

Hope it makes sense :)

Link to comment
Share on other sites

Well, they're using the following:-

t1 = Original BPM

t2 = New BPM

 

val=Math.round((Math.log(t2/t1)/0.05776227)*100)/100;

In excel it would be:-

=ROUND((LN(B1/A1)/0.05776227)*100, 0)/100

Where cells A1 = Original BPM, and B1 = New BPM

 

Any coder would understand that easily as long as they have an equivalent natural logarithm function (ln).

Link to comment
Share on other sites

Well, they're using the following:-

t1 = Original BPM

t2 = New BPM

 

val=Math.round((Math.log(t2/t1)/0.05776227)*100)/100;

In excel it would be:-

=ROUND((LN(B1/A1)/0.05776227)*100, 0)/100

Where cells A1 = Original BPM, and B1 = New BPM

 

Any coder would understand that easily as long as they have an equivalent natural logarithm function (ln).

 

Can you clarify the Excel part?

Why 0.05776227? How can we achieve that same number mathematically?

And why the *100 and then /100?

 

I will pass this info and those links to the developer for sure, so thanks for that. I'm just also interested in understanding the math behind it, just for personal pleasure :)

Link to comment
Share on other sites

The excel part is if you wanted to test the function in an excel sheet for clarification. Enter the formula into Cell C1, and place your values in A1 & B1 to play with it.

 

I've not looked into the workings of the function, but expect that the *100 followed by /100 is to get the resulting value to 2 decimal places (i.e. a sample result of 11.531262 when multiplied by 100 and rounded gives you 1153, this then provides 11.53 when divided again), it's quite a common way of working in code particularly when storing into a variable that could potentially store far more precise values.

 

LN (ln) is a computation to return natural logirithm for any given number, this is to base e (loge), not base 10 (log10), you use this in math to inverse an exponentiation (^). As you know from your previous calcs you had to raise OriginalBPM x2 to the power of (Semis/12).

 

0.05776227 is the value they're using for steps between semis. Not sure how they've arrived at that, suggests that using the tempered tuning formula is not accurate for this task perhaps? As i say, i've not looked into it.

 

However i've tried the function using the tempered intervals as Fuzz posted and the difference is:-

 

120BPM >240BPM = 12 Semis (@ 0.05776227)

120BPM >240BPM = 11.66 Semis (@ 0.059463094)

 

i.e.

=ROUND((LN(B1/A1)/0.05776227)*100, 0)/100
=ROUND((LN(B1/A1)/0.059463094)*100, 0)/100

So i'm guessing they're using an equal temp val or something which equates better to semitonal results for the purposes of pitch shifting?

 

12 semis is what you'd expect the correct val to be so appears to be the correct factor to be using. This is all rushed off the top of my head so don't go quoting as fact! haha :)

Link to comment
Share on other sites

The excel part is if you wanted to test the function in an excel sheet for clarification. Enter the formula into Cell C1, and place your values in A1 & B1 to play with it.

 

I've not looked into the workings of the function, but expect that the *100 followed by /100 is to get the resulting value to 2 decimal places (i.e. a sample result of 11.531262 when multiplied by 100 and rounded gives you 1153, this then provides 11.53 when divided again), it's quite a common way of working in code particularly when storing into a variable that could potentially store far more precise values.

 

LN (ln) is a computation to return natural logirithm for any given number, this is to base e (loge), not base 10 (log10), you use this in math to inverse an exponentiation (^). As you know from your previous calcs you had to raise OriginalBPM x2 to the power of (Semis/12).

 

0.05776227 is the value they're using for steps between semis. Not sure how they've arrived at that, suggests that using the tempered tuning formula is not accurate for this task perhaps? As i say, i've not looked into it.

 

However i've tried the function using the tempered intervals as Fuzz posted and the difference is:-

 

120BPM >240BPM = 12 Semis (@ 0.05776227)

120BPM >240BPM = 11.66 Semis (@ 0.059463094)

 

i.e.

=ROUND((LN(B1/A1)/0.05776227)*100, 0)/100
=ROUND((LN(B1/A1)/0.059463094)*100, 0)/100

So i'm guessing they're using an equal temp val or something which equates better to semitonal results for the purposes of pitch shifting?

 

12 semis is what you'd expect the correct val to be so appears to be the correct factor to be using. This is all rushed off the top of my head so don't go quoting as fact! haha :)

 

You lost me completely with this post hahaha

I wish I could understand all of that. But I tried it and it worked on a spreadsheet, so that's good! :)

 

Now I guess I just need to find the right formula for the last section. The Closest Musical Note function. You don't happen to have an idea of how that could be achieved, do you? ;)

Link to comment
Share on other sites

So - if neither your programmer nor you can grok this, maybe gardening is a better pastime than developing plugins ? :mrgreen:

 

I've never said he doesn't know it haha I'm assuming he does. I just met him.

But yeah, gardening could be another option. Or maybe an app that lets you take care of virtual plants, like back in the day with the Tamagotchi...

You never know.

 

But for every plugin, there's more than just coding. Being great at coding doesn't make it a great plugin. You need great ideas, great design, great promotion, etc.

That's why we are building a team. At what he excels, I don't and vice versa ;)

Link to comment
Share on other sites

The code for closest musical note function is in that javascript file. (http://www.thewhippinpost.co.uk/js/sample-calculator.js)

 

It's the last function, and It starts at:

function deternote(notemid){

and goes to the end of the file.

 

Let your coder look at that function to digest, if they're not sure of the following:-

var notetest=eval(notemid.notefreq.value);

All that is doing is setting variable 'notetest' to be the 'notefreq' .value from html form 'notemid', i.e. the user input in hz.

 

So effectively, if he passed the hz value direct to the function deternote() it would be:-

var notetest=notemid;

 

The function generates both Note Name and MIDI Note values and places them in the following vars:

noteton = Note Name

nmidi = MIDI Note Number

 

It should be really straight forward for them with that as a guide,

Link to comment
Share on other sites

The code for closest musical note function is in that javascript file. (http://www.thewhippinpost.co.uk/js/sample-calculator.js)

 

It's the last function, and It starts at:

function deternote(notemid){

and goes to the end of the file.

 

Let your coder look at that function to digest, if they're not sure of the following:-

var notetest=eval(notemid.notefreq.value);

All that is doing is setting variable 'notetest' to be the 'notefreq' .value from html form 'notemid', i.e. the user input in hz.

 

So effectively, if he passed the hz value direct to the function deternote() it would be:-

var notetest=notemid;

 

The function generates both Note Name and MIDI Note values and places them in the following vars:

noteton = Note Name

nmidi = MIDI Note Number

 

It should be really straight forward for them with that as a guide,

 

Oh great! I will definitely have him look at that.

Really appreciate your help! :)

Link to comment
Share on other sites

Ok so now the question is how are you going to handle non equal temperament tunings - of which there are many. :mrgreen: And then you also have instruments that don’t have 440Hz A as standard (pipe organs particularly).
Link to comment
Share on other sites

Ok so now the question is how are you going to handle non equal temperament tunings - of which there are many. :mrgreen: And then you also have instruments that don’t have 440Hz A as standard (pipe organs particularly).

 

You can’t always build something that covers ALL options otherwise you would have to build something massive and complex. This will be a tool for the “standard” instruments that use 440 since it’s the one that the majority of people are used to. It’s just a quick tool to help in the studio with delay calculations and stuff. Not something too specific ;)

 

who knows if in the future some math genius joins us and contributes with those specific equations and code...? ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...