|
|
Beeps
Experiments with a javascript tone generator
Chromatic scale intervals
[01] 1.05946 [02] 1.12246 [03] 1.18921 [04] 1.25992 [05] 1.33484 [06] 1.41421 [07] 1.49831 [08] 1.58740 [09] 1.68179 [10] 1.78180 [11] 1.88775 [12] 2.00000
<div align="center" >
<p style="font: 30px Courier ; color: #CC6060 ; " ><br>Beeps</p>
<p style="font: 16px Courier ; color: #606060 ; " >Experiments with a javascript tone generator<br></p>
<div align="center" style="font: 20px Courier ; color: #606060 ; " >
<?php
$jw = '/home/esand/public_html' ;
$noFile = 1 ;
$noteLen = "1d" ;
$parm = $_REQUEST[ 'play' ] ;
$mult = $_REQUEST[ 'mult' ] ;
if ( $mult <> '' ) { $mult = str_replace( '"', '', $mult ) ; $mult = str_replace( "'", "", $mult ) ; }
if ( $parm == '' ) { print( 'Please make a selection.<br>' ) ; }
else {
print( 'File is "'.$parm.'"<br>' ) ;
$filePath = $jw.'/commons/'.$parm ;
if ( ( $externalFile = fopen( $filePath, 'r' ) ) == false ) { print( 'Cannot open '.$filePath.'.<br>' ) ; }
else { $noFile = 0 ; }}
?>
<br><br>
<form name="Factor" action="#" >
<input name="mult" maxlength="10" size="10" type="text" value="" >
<input class="form" value="Set factor" onClick="javascript: window.location.assign( 'http://franklinseiberling.com/?pg=beeps&play=<?php print( $parm ) ; ?>&mult=' + document.Factor.mult.value ) ; " name="button" type="button">
</form>
<script type="text/javascript">
document.Factor.mult.focus() ;
</script>
<br><br>
Play Bach <a href="https://franklinseiberling.com/?pg=beeps&play=BACH-1.txt&mult=<?php print( $mult ) ; ?>" class="u" >1</a>·<a href="https://franklinseiberling.com/?pg=beeps&play=BACH-2.txt&mult=<?php print( $mult ) ; ?>" class="u" >2</a>·<a href="https://franklinseiberling.com/?pg=beeps&play=BACH-3.txt&mult=<?php print( $mult ) ; ?>" class="u" >3</a>·<a href="https://franklinseiberling.com/?pg=beeps" class="u" >Reset</a>·<a href="https://franklinseiberling.com/?pg=beeps&play=TAKE-5.txt&mult=<?php print( $mult ) ; ?>" class="u" >Take 5</a>
<?php
if ( $noFile == 0 ) {
print( '
<script type="text/javascript">
var noteLen = " " ;
var N = new Array(
"8d08f", ' ) ;
while ( ( $line = fgets( $externalFile ) ) != false ) {
if ( !feof( $externalFile ) ) {
$linePos = 0 ;
$dlm = 1 ;
$line =strtolower( $line ) ;
$dlm = strpos( substr( $line, $linePos ), 'f' ) ;
while( $dlm > 0 ) {
$lineElement = trim( substr( $line, $linePos, $dlm + 1 ) ) ;
$noteLenDlm = strpos( $lineElement, 'd' ) ;
if ( $noteLenDlm > 0 ) { $noteLen = substr( $lineElement, 0, $noteLenDlm + 1 ) ; }
else { $lineElement = $noteLen.$lineElement ; }
print( '"'.$lineElement.'", ' ) ;
$linePos = $linePos + $dlm + 1 ;
$dlm = strpos( substr( $line, $linePos ), 'f' ) ;
}
}}
print( '"LAST" ) ; </script> ' ) ;
fclose( $externalFile ) ;
}
?>
<script type="text/javascript">
var fInc = 1 / 16.81715361 ;
var cScale = new Array() ;
cScale[ 0 ] = 1.000 ;
var cix = 1 ;
while ( cix < 12 ) {
cScale[ cix ] = cScale[ cix-1 ] * ( 1 + fInc ) ;
cix ++ ;
}
var cNote = new Array(0) ;
cNote[ 1 ] = 55.0000 ;
var sIx = 1 ;
var cIx = 1 ;
var nIx = 1 ;
while ( sIx < 7 ) {
while ( cIx < 12 ) {
nIx ++ ;
cNote[ nIx ] = cNote[ nIx - 1 ] * ( 1 + fInc ) ;
cIx ++ ;
}
cIx = 1 ;
sIx ++ ;
}
function nFreq ( n ) {
if ( ( n < 55 ) ) { return 0 ; }
var sIx = 1 ;
var cIx = 1 ;
var nIx = 1 ;
var bf = 55 ;
while ( bf < n ) {
cIx ++ ;
bf = bf * cIx ;
}
nIx = cIx * 12 ;
tFr = Math.floor( cNote[ nIx ] ) ;
while ( tFr < n ) {
nIx ++
fFr = Math.floor( cNote[ nIx ] ) ;
}
return cNote[ nIx ] ;
}
function beep( freq, dur, aud ) {
if ( freq < 50 ) { setTimeout( function(){ return ; }, dur ) ; }
else {
var attack = 10,
decay = 250,
gain = aud.createGain(),
osc = aud.createOscillator() ;
gain.connect( aud.destination ) ;
gain.gain.value = 0.2 ;
osc.type = 'sine' ;
osc.detune.value = 0 ;
osc.frequency.value = freq ;
osc.connect( gain ) ;
osc.start(0) ;
setTimeout( function(){ osc.stop(0) ; osc.disconnect( gain ) ; gain.disconnect( aud.destination ) ; }, dur ) ;
}
}
var noFile = <?php print( $noFile ) ; ?> ;
if ( noFile ) {
var N = new Array ( "8d08f", "4d466f", "2d440f", "4d466f", "2d440f", "4d466f", "2d349f", "4d392f", "14d311f", "2d622f", "4d00f", "LAST" ) ;
}
var a = new window.AudioContext() ;
var d = 1 ;
var m = 1 ;
<?php
if ( $mult <> "" ) {
if ( !is_numeric( $mult ) | ( $mult < .1 ) | ( $mult >= 5 ) ) { print( 'document.write( "<div style=\'font: 14px courier ; color: #CC6060 ; \' ><br><center>multiplication factor \"'.$mult.'\" isn\'t valid.<br>Value must be > 0.1 and < 5.0 </center></div>" ) ; ' ) ; }
else { print( 'm = '.$mult.' ; ' ) ; }
}
print( 'document.write( "<div style=\'font: 14px Courier ; color: #606060 ; \' ><br><center>multiplication factor is " + m + "</center></div>" ) ; ' ) ;
if ( $parm == "BACH-2.TXT" ) { print ( 'm = m * 0.5 ; ' ) ; }
?>
var ix = 0 ;
function nxtBeep() {
var nxtNote = N[ ix ] ;
var pn = nxtNote.indexOf( 'd' ) ;
var d = nxtNote.substring( 0, pn ) ;
d = d * 60 ;
var pf = nxtNote.indexOf( 'f' ) ;
var fq = nxtNote.substring( pn + 1, pf ) * m ;
if ( fq == 0 ) { d = d / 4 ; }
else { if ( fq > 50 ) { beep( fq, d, a ) ; } }
ix ++ ;
if ( N[ ix ] != "LAST" ) { setTimeout ( 'nxtBeep()', d + d / 30 ) ; }
}
nxtBeep() ;
</script>
</div>
<p style="text-align: left ; padding-left: 10px ; font: 10px courier ; font-weight: bold ; " >
<br><br>
Chromatic scale intervals<br><br>
<?php
# PIT = 440: Z = 16.819: CRCL(1) = PIT
# FOR I = 2 TO 13: CRCL(I) = CRCL(I - 1) * (1 + (1 / Z)): NEXT I
$pit = 1 ;
$crcl = array() ;
$cix = 1 ;
$crcl[0] = $pit ;
while ( $cix < 13 ) {
$crcl[ $cix ] = $crcl[ $cix - 1 ] * ( 1 + ( 1 / 16.81715361 ) ) ;
$pn = round( $crcl[ $cix ], 5 ) ;
$strB = '[' ;
if ( $cix <= 9 ) { $strB = '[0' ; }
print( $strB.$cix.'] '.number_format( $pn, 5 ).' ' ) ;
if ( $cix % 6 == 0 ) { print( '<br>' ) ; }
$cix ++ ; }
?>
<br></p>
</div>
<div align="center" >
<br>
<img src="img/transparentHorizontal.png" alt="500" width="500" height="1" >
<a href="javascript: ToggleDisplay( 'sourceB' ) ; " class="w" >View/Hide source code</a>
<br>
</div>
<div id="sourceB" style="display: none ; " >
<?php
$filePath = $jw.'/FranklinSeiberling/toolbox/beeps.php' ;
viewSource( $filePath ) ;
?>
</div>
|
|