how to round value to...

If you require help or assistance with anything then please post here

Moderators: electrogear, exonerate

how to round value to...

Postby tester on Sun Mar 04, 2012 11:03 pm

I'm making a small "which-octave" detector, and have following problem. If the value compared to the reference produces positive octaves difference (let say, that a value 5621 is higher than 256, thus it is few octaves higher), then situation is simple. But if the value compared to the reference producs negative octaves (let say, that 123 is lower than 256, thus it is a few octaves lower), then such free comparison must be rounded to lower (more negative) integer. Can be this done without cheating? Adding "-1" or "-0.999..." is insecure when octave difference is a negative integer or very close around.
Need to take a break? Looking for relaxing sounds? I have something right for you.
(by purchasing, you are also supporting further development of related projects).
Thank you for your contribution.
tester
smanatic
 
Posts: 689
Joined: Wed Jan 18, 2012 9:52 pm
Location: Poland, internet

Re: how to round value to...

Postby oddson on Mon Mar 05, 2012 2:18 am

tester wrote:Can be this done without cheating?
What's wrong with cheating?

You could store the sign and magnitude separately and round the absolute value.
capture.png
oddson
wiki guru
 
Posts: 3883
Joined: Sun Jul 03, 2005 6:44 pm

Re: how to round value to...

Postby tester on Mon Mar 05, 2012 9:00 am

For example - if the compared value is exact N octaves lower than reference, then "cheating" I described above - would show that the value is -1 octave less than it is. That why I'm interested in roudning to up or down without adding an "almost 1 constant" on negative side. So "-2 = -2", but "-2.00...01 = -3". Values are compared using log10 process, so I just want to avoid math misunderstandings inside the detector (which works on Hz, not midi).

What's in your rounding box?
Last edited by tester on Mon Mar 05, 2012 10:19 am, edited 1 time in total.
Need to take a break? Looking for relaxing sounds? I have something right for you.
(by purchasing, you are also supporting further development of related projects).
Thank you for your contribution.
tester
smanatic
 
Posts: 689
Joined: Wed Jan 18, 2012 9:52 pm
Location: Poland, internet

Re: how to round value to...

Postby tester on Mon Mar 05, 2012 10:18 am

I think I made it.

When you type positive values on input (float; calculated octave ratio may look like 2.54), then "which octave" is rounded to lower integer (2.54 => 2). When you type negative values, then they are rounded to greater lower integer (float too; -2 => -2, but -2.1 => -3). Thus - you can estimate in which octave is your input frequency in relation to your reference point.
Attachments
selective-rounding.png
selective-rounding.png (26.2 KiB) Viewed 660 times
rounding-octaves.osm
(347 Bytes) Downloaded 39 times
Last edited by tester on Mon Mar 05, 2012 4:27 pm, edited 1 time in total.
Need to take a break? Looking for relaxing sounds? I have something right for you.
(by purchasing, you are also supporting further development of related projects).
Thank you for your contribution.
tester
smanatic
 
Posts: 689
Joined: Wed Jan 18, 2012 9:52 pm
Location: Poland, internet

Re: how to round value to...

Postby oddson on Mon Mar 05, 2012 4:07 pm

I haven't looked at your OSM (not at my SynthMaker machine) but why don't you just convert to pitch (midi) and do simple comparisons or integer division to get the octave?
oddson
wiki guru
 
Posts: 3883
Joined: Sun Jul 03, 2005 6:44 pm

Re: how to round value to...

Postby tester on Mon Mar 05, 2012 4:18 pm

I'm not working with midi, but with Hz, seconds, decibels, microtunings andl all kind of strange values and (representative) cycles you can imagine; even my octaves are dynamic, sometimes 2:1 and sometimes enharmonic ;-) So I'm developing universal modules for on-going and my further projects. On the other hand - I just do what I do understand and know; I don't know too much about midi related modules, and not necessarily understand them correctly.
Need to take a break? Looking for relaxing sounds? I have something right for you.
(by purchasing, you are also supporting further development of related projects).
Thank you for your contribution.
tester
smanatic
 
Posts: 689
Joined: Wed Jan 18, 2012 9:52 pm
Location: Poland, internet

Re: how to round value to...

Postby oddson on Mon Mar 05, 2012 8:51 pm

Pitch values don't have to go through MIDI but they are based on the same note values.

So if you have a frequency value (normalized) and you have a F2P converter (see: viewtopic.php?f=4&t=5452) then you can calculate octaves by integer division by 12.

[edit] It occurs to me that if you're using non-equal tunings and 'enharmonic octaves' --whatever that is-- pitch comparsions may not be that helpful. If you are interetested I'd be happy to elaborate further on what I thought your issue was but if I'm way off from what you're trying to do I'll just let it drop. [/edit]
oddson
wiki guru
 
Posts: 3883
Joined: Sun Jul 03, 2005 6:44 pm

Re: how to round value to...

Postby tester on Tue Mar 06, 2012 9:58 am

Regarding this particular topic - the rounding scheme I made seems to work correctly. Regarding "which octave" calculation - I made it with this scheme: logA(B) = log10(B) / log10(A), where A = reloctavesize, B = frequency ratio (current to reference).

Short explanation to other topics. Enharmonic octave is an octave that is detuned a little bit (different from 2:1) and depending of instruments and arrangements - can still sound fine. Within an octave, basically tunings can involve equal ratio (standard 12-TET or 24-TET scale), harmonic series (distance based, divisions by 2^N, like X/16 or X/32) or other free ratio (like pythagorean tuning). And - all tunings have their relative base, like A=440Hz or A=432Hz, and so on. In the world of melodic music - usually we live in the scheme based on 12-TET (equal ratio) scale, at A=440Hz and octave = 2:1.
Need to take a break? Looking for relaxing sounds? I have something right for you.
(by purchasing, you are also supporting further development of related projects).
Thank you for your contribution.
tester
smanatic
 
Posts: 689
Joined: Wed Jan 18, 2012 9:52 pm
Location: Poland, internet

Re: how to round value to...

Postby trogluddite on Tue Mar 06, 2012 7:10 pm

tester wrote:can still sound fine.

Can even sound better sometimes - perception of sound is not perfectly mathematical. Hence the very best piano tuners are highly paid - they can "stretch tune" the instrument with bass notes a little flat (compared to the maths) and high notes a little sharp. When done right, this compensates for anomalies in human pitch perception and makes the instrument sound more "in tune".
Feel free to use any schematics and algorithms I post on the forum in your own designs - a credit is appreciated (but not a requirement).
Don't stagnate, mutate to create. Without randomness and serendipity the earth would be just another barren rock.
User avatar
trogluddite
smychopath
 
Posts: 3024
Joined: Mon Oct 20, 2008 3:52 pm
Location: Yorkshire, UK


Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest