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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

APPENDIX B. PROGRAM LISTINGS 322<br />

int n = 0, cellCount = 0;<br />

UnitCell cell;<br />

BoreSegment s;<br />

double radius;<br />

if(x == 0) {<br />

*Z0 = charZ(w->head->embouchureHole->c,<br />

w->head->embouchureHole->rho,<br />

w->head->embouchureHole->boreRadius);<br />

*c = w->head->embouchureHole->c;<br />

return 1;<br />

}<br />

if (x > 0) {<br />

/* find the bore or hole at the point x */<br />

bore = w->head->downstreamBore;<br />

/* if x is outside <strong>of</strong> the current bore, try the next one */<br />

while(x >= boreLength(bore) && cellCount < sizeVector(w->cells)) {<br />

/* subtract from x the length <strong>of</strong> the previous bore */<br />

x -= boreLength(bore);<br />

/* find the next bore */<br />

cell = (UnitCell)elementAt(w->cells, cellCount++);<br />

bore = cell->bore;<br />

}<br />

}<br />

else if (x < 0) {<br />

bore = w->head->upstreamBore;<br />

x = -x;<br />

}<br />

/* if we are at a hole */<br />

if(x == 0) {<br />

*Z0 = charZ(cell->hole->c, cell->hole->rho,<br />

cell->hole->boreRadius);<br />

*c = cell->hole->c;<br />

return 1;<br />

}<br />

/* otherwise, find the correct BoreSegment */<br />

else {<br />

s = (BoreSegment)elementAt(bore, n);<br />

while(x > s->length) {<br />

/* subtract from x the length <strong>of</strong> the previous segment */<br />

x -= s->length;<br />

/* get the next segment */<br />

s = (BoreSegment)elementAt(bore, ++n);<br />

}<br />

}<br />

/* if x is outside the BoreSegment, return 0 */<br />

if(x > s->length) return 0;<br />

/* otherwise do a linear interpolation */<br />

else {<br />

radius = (s->radius2 * x + s->radius1 * (s->length - x))<br />

/ (s->length);<br />

}<br />

*Z0 = charZ(s->c, s->rho, radius);<br />

*c = s->c;<br />

return 1;<br />

}<br />

double boreLength(Vector bore) {

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

Saved successfully!

Ooh no, something went wrong!