11.07.2014 Views

Flute acoustics: measurement, modelling and design - School of ...

Flute acoustics: measurement, modelling and design - School of ...

Flute acoustics: measurement, modelling and design - School of ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

APPENDIX B. PROGRAM LISTINGS 271<br />

frequency = A4;<br />

/* search for input ratio against A4 to the nearest cent<br />

in range -49 to +50 cents around closest note */<br />

if(input >= frequency) {<br />

while(input >= r*frequency) {<br />

frequency = r*frequency;<br />

r_index++;<br />

}<br />

}<br />

else {<br />

while(input < frequency) {<br />

frequency = frequency/r;<br />

r_index--;<br />

}<br />

}<br />

while(input >= cent*frequency) {<br />

frequency = cent*frequency;<br />

cent_index++;<br />

}<br />

if((cent*frequency - input) < (input - frequency))<br />

cent_index++;<br />

if(cent_index > 50) {<br />

r_index++;<br />

cent_index = 100 - cent_index;<br />

if(cent_index != 0)<br />

side = MINUS;<br />

else<br />

side = PLUS;<br />

}<br />

else<br />

side = PLUS;<br />

if(round) {<br />

/* round cents to nearest 5 cents */<br />

switch(cent_index%5) {<br />

case 1:<br />

cent_index = cent_index - 1;<br />

break;<br />

case 2:<br />

cent_index = cent_index - 2;<br />

break;<br />

case 3:<br />

cent_index = cent_index + 2;<br />

break;<br />

case 4:<br />

cent_index = cent_index + 1;<br />

break;<br />

default:<br />

break;<br />

}<br />

if(cent_index == 0)<br />

side = PLUS;<br />

}<br />

/* fill string buffer with note information <strong>and</strong> return */<br />

n->name = (char*)malloc(BUFSIZ*size<strong>of</strong>(char));<br />

sprintf(n->name, "%s", notes[A4_INDEX + r_index]);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!