ultrus Posted October 16, 2006 Share Posted October 16, 2006 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 Quote Link to comment Share on other sites More sharing options...
ultrus Posted October 18, 2006 Author Share Posted October 18, 2006 Answered my own question. :) A great class that generates .wav files from scratch can be found at:http://www.phpclasses.org/browse/package/1932.htmlIt currently only generates sine waves, but it's a great start! Hope someone else enjoys this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.