How ORGs work

Feb 13, 2013 at 5:48 AM
Senior Member
"This is the greatest handgun ever made! You have to ask yourself, do I feel lucky?"
Join Date: Jun 12, 2011
Location: 0x00000000 0xC00E0FF0 0xFFFFEFD4 0xC0000000
Posts: 108
So I coded this one that will try to measure the perceived frequency of a wave given its base frequency and the "Freq" value. Please discuss and tell if what I am doing is correct.

The applet: FreqTest
 
Feb 15, 2013 at 5:05 AM
Senior Member
"This is the greatest handgun ever made! You have to ask yourself, do I feel lucky?"
Join Date: Jul 11, 2009
Location: Texas, USA
Posts: 90
EXE problems

When I ran your exe on my Windows XP computer it said "ORGStudioTestTools.exe is not a valid Win32 application." I tried to install Visual Studio Express 2012 to compile it myself, but the installer failed part of the way through with a similar error message that something was "not a valid Win32 application." I looked at your source code and saw there were only a handful of calculation functions, so I copied them (with small changes) into JavaScript in an HTML file and checked the calculation results in my browser. Later, I was able to successfully install Visual C# 2010 Express. When I opened your project it offered to convert from .NET Framework 4.5 to .NET Framework 4. I accepted that, compiled the code, and finally saw your intended program.

You can see I am very interested in this! But if other people have problems with your exe, you might want to figure out if it's possible to make it compatible with Windows XP, or figure out if a certain framework or other kind of library is needed to make the exe run properly.


Calculation comments

Your calculations seem correct to me. Here are some thoughts.

1. You may be doing some redundant calculations. For example, you start with an octave number and pitch class number, calculate a key number, then use the key number to re-calculate an octave number.

The formula below calculates the same final frequencies as your program, but might be simpler to understand.

C is the pitch class (pitch letter) from 0 to 11 (C to B).
O is the OrgMaker octave from 0 to 7. (middle C is OrgMaker C3, A440 is OrgMaker A3)
F is the OrgMaker Freq value from 100 to 1900.

The frequency of a pitch in hertz is

128 × 440 × 2 ( C – 9 ) / 12 + (F – 1000)
2 ( 10 – O )


2. You are calculating the base pitch frequency precisely (the part highlighted in red above). When I investigated OrgMaker with a debugger, I found it ends up using an integer number of hertz for the octave with middle C and A440 (OrgMaker octave 3).
Code:
/*
         pitch   precise  OrgMaker    difference
                   (Hz)     (Hz)     (Hz)  (cents)
  =============  =======  ========  ==============
  (middle C) C    261.63   261.00   –0.63    –4
             C#   277.18   278.00   +0.82    +5
             D    293.66   294.00   +0.34    +2
             D#   311.13   311.00   –0.13    –1
             E    329.63   329.00   –0.63    –3
             F    349.23   349.00   –0.23    –1
             F#   369.99   371.00   +1.01    +5
             G    392.00   391.00   –1.00    –4
             G#   415.30   414.00   –1.30    –5
      (A440) A    440.00   440.00
             A#   466.16   466.00   –0.16    –1
             B    493.88   494.00   +0.12    +0
Each higher octave is double the frequency. Each lower octave is half the frequency. The cents values are the same for every octave.

Note that the OrgMaker frequencies above are not the same as rounded versions of the precise values. I guess OrgMaker calculates its base pitch values via some estimation method, but I don't know exactly how.

When I measured actual OrgMaker audio with a tuner, I got values very close to the OrgMaker column above for most audio performance settings.

These base frequencies affect the pitch slightly. In case you want to emulate the OrgMaker pitch more exactly, you could use the following formula instead:

B is an array B0 to B11 containing the values from the OrgMaker column above.

The frequency of a pitch in hertz is

128 × BC + (F – 1000)
2 ( 10 – O )
 
Last edited by a moderator:
Feb 15, 2013 at 11:50 AM
Senior Member
"This is the greatest handgun ever made! You have to ask yourself, do I feel lucky?"
Join Date: Jun 12, 2011
Location: 0x00000000 0xC00E0FF0 0xFFFFEFD4 0xC0000000
Posts: 108
I once thought the Freq parameter in OrgMaker is expressed in Hz. And I wasn't sure if the Freq parameter acts differently on each octave, let alone an individual note, so I tried reading your notes and yes, I had to compute the note to point frequency and v.v. I do found out that Freq is indeed some kind of offset. And I forgot the fact that increasing/decreasing the octave doubles/halves the frequency so I used the point size for my computations.

Next time, I'll try rebuilding the EXEs I present. I do them in VS 2012, and I haven't tried running executables written from there to older versions of .NET (except .NET 4.0).
 
Feb 15, 2013 at 9:11 PM
Senior Member
"I, Ikachan. The Life and Documentary of the OrigiNAL SQuiD."
Join Date: Jan 2, 2013
Location: Wright and Co. Law Offices
Posts: 179
Age: 124
Eek! So much math, it's almost intolerable! (Tried out the program, it didn't work on my copy of Windows 8 for some reason...)
 
Feb 16, 2013 at 5:17 AM
Senior Member
"This is the greatest handgun ever made! You have to ask yourself, do I feel lucky?"
Join Date: Jun 12, 2011
Location: 0x00000000 0xC00E0FF0 0xFFFFEFD4 0xC0000000
Posts: 108
ChimeApple said:
Eek! So much math, it's almost intolerable! (Tried out the program, it didn't work on my copy of Windows 8 for some reason...)
Argh--very, very sorry :toroko2: , next time I'll reupload this, really (or just make a applet of this).

I'll try the other formula, then.
 
Feb 16, 2013 at 6:38 AM
Senior Member
"This is the greatest handgun ever made! You have to ask yourself, do I feel lucky?"
Join Date: Jul 11, 2009
Location: Texas, USA
Posts: 90
>I wasn't sure if the Freq parameter acts differently on each octave

I also encountered the same confusion. I originally tried to understand the OrgMaker Freq value using the org2xm README file "Note frequencies" melody formula, but I learned it was wrong.

Imagine OrgMaker stores a tone for a specific instrument in a sound file. The key points I discovered are:
1. OrgMaker resizes the sound file depending on what octave it's going to play.
2. OrgMaker chooses the playback rate of the sound file based on the pitch class (the pitch letter) of the note it's going to play. It uses the same playback rate for every C (or C#, or D, or so on) no matter what octave it's in.
3. The Freq value from 100 to 1900 is shifted to -900 to +900 then added to the playback rate.

The org2xm README formula is wrong because:
1. It implies the sound file OrgMaker plays is always the same size. This is wrong.
2. It implies the playback rate is always 256 times the pitch rate. This is wrong.
3. It shows the Freq value from 100 to 1900 is shifted to -900 to +900 then added to the playback rate, but because it gets steps 1 and 2 wrong, the formula incorrectly implies the Freq value's effect in semitones is wider for lower octaves and tiny for higher octaves.


>I once thought the Freq parameter in OrgMaker is expressed in Hz

Well, be aware that hertz just means something per second. You have to keep track of exactly what that something is.

When we're talking about pitch, we're talking about how many periods (cycles of the periodic wave) happen in a second.
When we're talking about playback rate, we're talking about how many points or "pixels" of the sound are played in a second.
You could call either one of these a value in hertz.

The Freq value is added to the playback rate so you could say the Freq value is in hertz, but you have to know more than that to understand how it works. In the formulas in my post above, the numerator calculates the playback rate (in Hz or points per second). The denominator calculates the period size (in points). The result of the division is the pitch frequency (in Hz or periods per second).


>I used the point size for my computations

Your program correctly uses the Freq value to shift the pitch the same way OrgMaker does. But I got lost in the calculations it did, so thought I'd explain a possibly simpler way.
 
Feb 18, 2013 at 10:04 AM
Senior Member
"This is the greatest handgun ever made! You have to ask yourself, do I feel lucky?"
Join Date: Jun 12, 2011
Location: 0x00000000 0xC00E0FF0 0xFFFFEFD4 0xC0000000
Posts: 108
I turned the program into an applet instead. See first post.

Yeah, the page contains nothing but the applet itself, but anyway I'll be placing it somewhere when it's finished.
 
Top