SynthMaker

how to round value to...

Archive · 2012 9 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

tester ·

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.

oddson ·

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.

tester ·

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?

tester ·

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.

oddson ·

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?

tester ·

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.

oddson ·

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: frequency to pitch) 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]

tester ·

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.

trogluddite ·

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".

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.