Jump to content

Generating .wav files using php


ultrus

Recommended Posts

PHP amazed me yet again with the ability to generate .wav files. One can take two or more .wav files and merge them together as seen at http://articles.techrepublic.com.com/5100-3513_11-5810215.html . It is also possible to apply effects to audio files like echo, fade, and crop like seen in the great php class at http://www.pviet.com/wavedit/test_wavedit.html.php (even comes with a wave form image maker!). More info on the actual .wav format can be seen at
http://ccrma.stanford.edu/CCRMA/Courses/422/projects/WaveFormat/ (still a bit greek to me)

I want to expand on this in my own fun projects. Using the second example from above, how can I generate my own audio files from scratch? It would be cool to generate raw audio data arrays using mathmatic equations, and create a file that will play in an audio player. Here is what I have added to the class so far with further questions  commented:

[code]
function makeFile($dataArray) {
//set name
$this->afiles[0]['name'] = "scratchFile.wav";
$this->wavs['ChunkID'] = "RIFF";
$this->wavs['ChunkSize'] = 83140; //how do I set this? I just pulled this number from an existing file. How do I  get this for one that does not exsist yet?
$this->wavs['Format'] = "WAVE";
$this->wavs['Subchunk1ID'] = "fmt";
$this->wavs['SubChunk1Size'] = 16;
$this->wavs['AudioFormat'] = 1;
$this->wavs['NumChannels'] = 1;
$this->wavs['SampleRate']  = 16000;
$this->wavs['ByteRate'] = 32000;
$this->wavs['BlockAlign'] = 2;
$this->wavs['BitsPerSample'] = 16;

$this->wavs['Subchunk2ID'] = "data";
$this->wavs['SubChunk2Size'] = 83104; //how do I set this?  This is an example from an exsisting file.
//$this->wavs['Data']= ""; //how? is a string, from data above? Can I skip this? assuming yes for now

$this->wavs['NumberSamples']= ($this->wavs['SubChunk2Size']*8)/($this->wavs['NumChannels']*$this->wavs['BitsPerSample']);

                $this->afiles[0]['structure'] = $this->wavs;
//$this->getDataArr($this->unpackData($this->wavs['Data']));
$this->afiles[0]['arrdata']= $dataArray;
}
[/code]

This is a bit of an odd request compared to what I normally experiment with. Any feedback from the smart or inspired people out there would be greatly appriciated. :)

Thank you,

Ultrus
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.