## Calculation Algorithm

The heart of The Whistle Calculator is the algorithm that calculates the placement of the tone holes.  All the rest is just there to make it easy for the user to access and control the calculation.
Historically there have been two main free sources of this calculation.  Flutomat, by Pete Kosel, and TWCalc by Daniel Bingamon.  Both of these authors were kind enough to allow me to copy their algorithms for use in this program.  Without this generosity The Whistle Calculator would not exist, because I know almost nothing about the physics of whistle music making.  I do not think that it is any secret that these algorithms are approximations.  That is, there is sometimes a discrepancy between the hole positions suggested by the Whistle Calculator and the positions that are actually needed.  For some combinations of whistle size and key they work very well, but for other sizes, or keys they may not work nearly as well.  One goal of The Whistle Calculator is to allow the user to select the most appropriate version of the algorithm for the whistle being designed.

I have replicated the algorithms of both Flutomat and TWCalc as separate pieces of code, and these can be selected on the GUI of The Whistle Calculator.

I have found a minor flaw in the 'live' flutomat code on Pete Kosel's website.  The flaw does not lead to significant differences in the hole placements until the holes get large relative to the tube bore, or the tube wall thickness gets large.  Even then the differences are small.  The correct algorithm is, however, easier to implement so you will see a 'corrected flutomat' calculator in the list.

Hans Bracker at Soft Flute has been working on the fine tuning of the alorithm and I have created a version of the calculator with his modifications to the algorithm.

As a further development I have now created one calculator that implements all the others as sub-classes.  This is because much of the mechanism is common between them, with the differences between then expressed in seven functions.

As a specialised subclass of this 'Unified' calculator I have created a calculator that allows the user to express the contents of these functions in JavaScript.  The user can then alter the behavious of the calculator in an attempt to find an algorithm that better matches reality.  The JavaScript calculator has defined for it seven functions:
•     closedCorrection: Closed hole for tone hole n.  The length of the vibrating air column is effectively increased by each closed tone hole which exists above the first open tone hole.  This function is called C_c(n) in the Flutomat code.
•     cutoffFrequency: Calculates the cutoff frequency above which the open hole correction is not valid.  Instrument should be designed so that all second register notes are well below this frequency. This function is called f_c(n) in the Flutomat code.
•  endCorrection: Calculates the distance from physical open end of flute  to effective end of vibrating air column. The vibrating air column ends beyond the end of the flute and C_end is always positive. This function is called C_end() in the Flutomat code.
• embouchureCorrection: Calculates the distance from theoretical start of air column to the center of embouchure hole; the air column effectively extends beyond the blow hole center by this distance. This function is called C_emb() in the Flutomat code.
• effectiveThickness: Effective wall thickness, i.e. height of air column at open finger holes; air column extends out past end of hole a fraction of the hole diameter. This function is called te(n) in the Flutomat code.\n" ;
• firstHoleDistance: Calculates the effective distance from the first (\"single\") tone hole to the end of the vibrating air column when only that hole is open. This function is called C_s() in Flutomat code. It is only used in iterative mode.
• subsequentHoleDistance: Calculates the effective distance from the second and subsequent tone holes to the end of the vibrating air column when all holes below are open. NOTE: the value of this correction is invalid if the frequency of the note played is above the cutoff frequency. This function is called C_o(n) in Flutomat code. It is only used in iterative mode.;
The base version of these functions are functionally equivalent to the "Corrected Flutomat" algorithm.

There are two other sets of functions, Those defined by Hans Bracker, and those that were part of TWCalc.  These extra two sets each only replace part of the set of functions.  Where a function replaces one in the set, the replacement function is used wherever needed.  So TWCalc redefines effectiveThickness for example.  So wherever effectiveThickness is called when using TWCalc set of functions, the version supplied by the TWCalc set is used.  We say that the TWCalc version of this function 'overrides' the base version.