PHP Classes

File: examples/tone.php

Recommend this page to a friend!
  Classes of sk89q   WavForge   examples/tone.php   Download  
File: examples/tone.php
Role: Example script
Content type: text/plain
Description: An example
Class: WavForge
Generates audio data files in the WAV format
Author: By
Last change: Updated for 0.3
Date: 15 years ago
Size: 579 bytes
 

Contents

Class file image Download
<?php // $Id$
// WavForge example

require_once "../WavForge.php";

$wf = new WavForge();
$wf->setBitsPerSample(16);
$wf->synthesizeSine(440, 1, 1); // 440 Hz, 100% volume, 1 second
$wf->synthesizeSawtooth(440, 1, 1); // 400 Hz, 100% volume, 1 second
$wf->synthesizeNoise(1, 1); // 100% volume, 1 second

if (php_sapi_name() == 'cli') { // Command line?
   
$fp = fopen("tone_test.wav", "wb");
   
fwrite($fp, $wf->getWAVData());
   
fclose($fp);
    echo
"tone_test.wav written\n";
} else {
   
header("Content-Type: audio/wav");
    echo
$wf->getWAVData();
}