24?24:$pbrsemitones; $pbrcents=$pbrcents<0?0:$pbrcents; $pbrcents=$pbrcents>100?100:$pbrcents; $tunenote=$tunenote<0?0:$tunenote; $tunenote=$tunenote>127?127:$tunenote; $tunefreq=$tunefreq<1?1:$tunefreq; $tunefreq=$tunefreq>22000?22000:$tunefreq; $basefreq=$tunefreq/pow(2,(($tunenote)/12)); $precisenote=12*(log($freq/$basefreq)/log(2)); $note=round($precisenote); // past assumption that I needed to center the wheel at 8192 to avoid negatives // must have been wrong // $pb=round(819200*($precisenote-$note)/((100*$pbrsemitones)+$pbrcents))+8192; $pb=round(819200*($precisenote-$note)/((100*$pbrsemitones)+$pbrcents))+0; return array('note'=>$note,'pb'=>$pb); } ?>