"); } if ($soundShape == "square"){ //square $wavePeriod = floor((22050/$soundFreq)/2); //half up the other down for ($n = 0; $n < $soundLength; $n++){ if (floor($n / $wavePeriod)%2 == 0){ $data[$n] =-127*255; }else{ $data[$n] =127*255; } } //print("make square
"); } if ($soundShape == "sin"){ //square $wavePeriod = floor((22050/$soundFreq)/1); //half up the other down for ($n = 0; $n < $soundLength; $n++){ $data[$n] = sin( (($n % $wavePeriod)/$wavePeriod)*6.28)*127*255; } //print("make sin
"); } if ($soundShape == "noise"){ //square $wavePeriod = floor((22050/$soundFreq)/1); //half up the other down for ($n = 0; $n < $soundLength; $n++){ $data[$n] = rand(1,255*255); } //print("make noise
"); } //print("no modulate
/n"); } if ($isModulate){ if ($soundShape == "saw"){ //saw $sinPlace = 0; $sinPeriod = (22050/$modulateFreq); for ($n = 0; $n < $soundLength; $n++){ $wavePeriod = 22050/($soundFreq+sin(($n % $sinPeriod)/$sinPeriod *6.28)*$modulateDepth); $sinShift = (1/$wavePeriod)*1000; $sinPlace += $sinShift; if (($sinPlace % 1000)< 500){ $data[$n] = ((($sinPlace % 1000)/500) - .5)*255*255; }else{ $data[$n] = (((500-(($sinPlace % 1000 )- 500))/500)-.5)*255*255; } } //print("make mod saw
"); } if ($soundShape == "square"){ //square $sinPlace = 0; $sinPeriod = (22050/$modulateFreq); for ($n = 0; $n < $soundLength; $n++){ $wavePeriod = 22050/($soundFreq+sin(($n % $sinPeriod)/$sinPeriod *6.28)*$modulateDepth); $sinShift = (1/$wavePeriod)*6.28; $sinPlace+=$sinShift; if (sin($sinPlace) < 0){ $data[$n] = 127 * 255; }else{ $data[$n] = -127 * 255; } } //print("make mod square
"); } if ($soundShape == "sin"){ //sin $sinPlace = 0; $sinPeriod = (22050/$modulateFreq); for ($n = 0; $n < $soundLength; $n++){ $wavePeriod = 22050/($soundFreq+sin(($n % $sinPeriod)/$sinPeriod *6.28)*$modulateDepth); $sinShift = (1/$wavePeriod)*6.28; $sinPlace+=$sinShift; $data[$n] = sin($sinPlace)*127*255; } //print("make mod sin
"); } if ($soundShape == "noise"){ //square $wavePeriod = floor((22050/$soundFreq)/1); //half up the other down for ($n = 0; $n < $soundLength; $n++){ $data[$n] = rand(1,255*255); } //print("make mod noise
"); } //print("yes modulate
/n"); } ////////////////////////////////////////// // envelope volume ////////////////////////////////////////// if ($envelopeShape == "easyOut"){ for ($n = 0; $n < $soundLength; $n++){ $data[$n] = $data[$n]*sqrt ((($soundLength-$n)/$soundLength)); } //print("easyOut
"); } if ($envelopeShape == "easyIn"){ for ($n = 0; $n < $soundLength; $n++){ $data[$n] = $data[$n]*sqrt ((($n)/$soundLength)); } //print("easyIn
"); } if ($envelopeShape == "hardOut"){ for ($n = 0; $n < $soundLength; $n++){ $data[$n] = $data[$n]* ((($soundLength-$n)/$soundLength)*(($soundLength-$n)/$soundLength)); } //print("hardOut
"); } if ($envelopeShape == "hardIn"){ for ($n = 0; $n < $soundLength; $n++){ $data[$n] = $data[$n]* ((($n)/$soundLength)*(($n)/$soundLength)); } //print("hardIn
"); } ////////////////////////////////////////// // create the fx ////////////////////////////////////////// //fx echo if ($isEcho){ $echoDelayS = $echoDelay*22050; $soundLength = $soundLength*2 + $echoDelay; for ($n = 0; $n < $soundLength; $n++){ $data[$n] = $data[$n]/2; } for ($n = 0; $n < $soundLength; $n++){ $data[$n+$echoDelayS] = ($data[$n]*$echoDepth + $data[$n+$echoDelayS]); } //print("fxEcho
"); } //fx warble if ($isWarble){ //square $wavePeriod = floor(22050/$warbleDelay); //half up the other down for ($n = 0; $n < $soundLength; $n++){ $data[$n] = $data[$n] * ((sin ((($n % $wavePeriod)/$wavePeriod)*6.28)*$warbleDepth*.5) + .5); } //print("fxWarble
"); } //fx distorto if ($isDistort){ for ($n = 0; $n < $soundLength; $n++){ $sample= $data[$n]; //if (fabs(sample)< 1000) sample = 0; if ($sample>=0){ $part1 = 32000; }else{ $part1 = -32000; } if ($sample == 0)$sample = 1; $part2 = pow(abs($sample)/32000,(1-$distortDepth/10)); $total = $part1*$part2; $data[$n] = $total; } //print("distort it
"); } ////////////////////////////////////////// // smooth in/out ////////////////////////////////////////// $start = .075 * 22050; //.075 seconds for ($n = 0; $n < $start; $n++){ $data[$n] = $data[$n]* (($n)/$start) ; } //print("smooth in
"); for ($n = 0; $n < $start; $n++){ $data[$soundLength-$n-1] = $data[$soundLength-$n-1]* (($n)/$start); } //print("smooth out
"); ////////////////////////////////////////// // format as 8bit ////////////////////////////////////////// /* for ($n = 0; $n < $soundLength; $n++){ $data[$n] = ($data[$n]*.75)/255;//+128; } print("format 8bit
"); */ ////////////////////////////////////////// // create audio file ////////////////////////////////////////// //http://www.technology.niagarac.on.ca/courses/comp630/WavFileFormat.html // info on the wav file format $bits = 16; if ($bits == 8){ //8bit $soundLengthHigh256 = floor($soundLength/256); $soundLengthLow256 = $soundLength % 256; $packageLength = $soundLength + 36; $packageLengthHigh256 = floor($packageLength/256); $packageLengthLow256 = $packageLength % 256; //print ("$soundLength, $soundLengthHigh256, $soundLengthLow256
\n"); //print ("$packageLength, $packageLengthHigh256, $packageLengthLow256\n"); //create the file $fp = fopen ("made.wav", "wb"); //RIFF Chunk fwrite($fp, "RIFF"); //riff //fwrite($fp, chr(0x46).chr(0x2d));//length (little edians) //fwrite($fp, chr(0x00).chr(0x00));//extra length; (big edieans) fwrite($fp, chr($packageLengthLow256).chr($packageLengthHigh256).chr(0x00).chr(0x00)); fwrite($fp, "WAVE"); //WAVE //FORMAT Chunk fwrite($fp, "fmt "); //fmt fwrite($fp, chr(0x10).chr(0x00).chr(0x00).chr(0x00));//always fwrite($fp, chr(0x01).chr(0x00));//always fwrite($fp, chr(0x01).chr(0x00));//mono fwrite($fp, chr(0x22).chr(0x56).chr(0x00).chr(0x00));//sampler rate fwrite($fp, chr(0x22).chr(0x56).chr(0x00).chr(0x00));//bytes per sec same at 8mono fwrite($fp, chr(0x01).chr(0x00)); //bytes per sample fwrite($fp, chr(0x08).chr(0x00)); //bits per sample //DATA Chunk fwrite($fp, "data"); //data //fwrite($fp, chr(0x22).chr(0x2d).chr(0x00).chr(0x00)); //length (11 554) fwrite($fp, chr($soundLengthLow256).chr($soundLengthHigh256).chr(0x00).chr(0x00)); //Copy Data for ($n =0; $n < count($data); $n++){ fwrite($fp,chr($data[$n])); } //Close file fclose($fp); }else{ //16 bit //$soundLengthHigh256 = floor(($soundLength*2)/256); //$soundLengthLow256 = ($soundLength*2) % 256; $soundLengthHigher256 = (($soundLength*2) & 0x00FF0000)>>16; $soundLengthHigh256 = (($soundLength*2) & 0x0000FF00)>>8; $soundLengthLow256 = ($soundLength*2) & 0x000000FF; //print("sound length in bytes: $soundLength*2
"); //print("$soundLengthHigher256, $soundLengthHigh256, $soundLengthLow256"); $packageLength = ($soundLength*2) + 36; //$packageLengthHigh256 = floor($packageLength/256); //$packageLengthLow256 = $packageLength % 256; $packageLengthHigher256 = ($packageLength & 0x00FF0000) >> 16; $packageLengthHigh256 = ($packageLength & 0x0000FF00) >> 8; $packageLengthLow256 = $packageLength & 0x000000FF; //print ("$soundLength, $soundLengthHigh256, $soundLengthLow256
\n"); //print ("$packageLength, $packageLengthHigh256, $packageLengthLow256\n"); //create the file $fp = fopen ("made.wav", "wb"); //RIFF Chunk fwrite($fp, "RIFF"); //riff //fwrite($fp, chr(0x46).chr(0x2d));//length (little edians) //fwrite($fp, chr(0x00).chr(0x00));//extra length; (big edieans) fwrite($fp, chr($packageLengthLow256).chr($packageLengthHigh256).chr($packageLengthHigher256).chr(0x00)); fwrite($fp, "WAVE"); //WAVE //FORMAT Chunk fwrite($fp, "fmt "); //fmt fwrite($fp, chr(0x10).chr(0x00).chr(0x00).chr(0x00));//always fwrite($fp, chr(0x01).chr(0x00));//always fwrite($fp, chr(0x01).chr(0x00));//mono fwrite($fp, chr(0x22).chr(0x56).chr(0x00).chr(0x00));//sampler rate fwrite($fp, chr(0x22).chr(0xac).chr(0x00).chr(0x00));//bytes per sec 2x sampler rate at 16mono fwrite($fp, chr(0x02).chr(0x00)); //bytes per sample fwrite($fp, chr(0x10).chr(0x00)); //bits per sample //DATA Chunk fwrite($fp, "data"); //data //fwrite($fp, chr(0x22).chr(0x2d).chr(0x00).chr(0x00)); //length (11 554) fwrite($fp, chr($soundLengthLow256).chr($soundLengthHigh256).chr($soundLengthHigher256).chr(0x00)); //Copy Data for ($n =0; $n < count($data); $n++){ $low = ($data[$n]*.75)%255; fwrite($fp,chr($low)); $high = ($data[$n]*.75)/255; fwrite($fp,chr($high)); } //Close file fclose($fp); exec("cp made.wav vkBeep.wav"); exec("rm vkBeep.wav.gz"); exec("gzip vkBeep.wav"); exec("mv vkBeep.wav.gz vkBeep.wav.zip"); } }//end of master if. ?> Volcano Kit Beep Maker
" ALT="" name="squareImg" WIDTH=40 HEIGHT=20 id="squareImg" onClick="VK_handleButton('square');">
" ALT="" name="sinImg" WIDTH=40 HEIGHT=20 id="sinImg" onClick="VK_handleButton('sin');">
" ALT="" name="sawImg" WIDTH=40 HEIGHT=20 id="sawImg" onClick="VK_handleButton('saw');">
" ALT="" name="noiseImg" WIDTH=40 HEIGHT=20 id="noiseImg" onClick="VK_handleButton('noise');">
" ALT="" name="hardInImg" WIDTH=40 HEIGHT=20 id="hardInImg" onClick="VK_handleButton('hardIn');">
" ALT="" name="easyInImg" WIDTH=40 HEIGHT=20 id="easyInImg" onClick="VK_handleButton('easyIn');">
" ALT="" name="hardOutImg" WIDTH=40 HEIGHT=20 id="hardOutImg" onClick="VK_handleButton('hardOut');">
" ALT="" name="easyOutImg" WIDTH=40 HEIGHT=20 id="easyOutImg" onClick="VK_handleButton('easyOut');">
" ALT="" name="delayCheckImg" WIDTH=20 HEIGHT=20 id="delayCheckImg" onClick="VK_handleButton('delayCheck');">
" ALT="" name="warbleCheckImg" WIDTH=20 HEIGHT=20 id="warbleCheckImg" onClick="VK_handleButton('warbleCheck');">
" ALT="" name="modulCheckImg" WIDTH=20 HEIGHT=20 id="modulCheckImg" onClick="VK_handleButton('modulCheck');">