PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am a student scientist working on animated holograms controlled with stereo sound (ok, it's not that amazing) and want to use php to generate wave files. I know how to read/write files in text format, but how do I write plain data in an encoded format? I'm familiar with the WAV format - just need to figure out how to write the data in bytes, not stings.
I promise any code I develop with help from this forum will be publicly available.
General Idea:
<?php
function soundDataL($frame){
//function to output
return $value;
}
function soundDataR($frame){
//function to output
return $value;
}
function writeSound($file, $header, $maxFrames){
$snd=fopen($file, "x");
fwrite($snd,$header);
for($i=0; $i<$maxFrames; $i++){
$right=soundDataR($i);
$left=soundDataL($i);
//write this data as data, not text
}
fclose($snd);
}
?>
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
You'll probably need to use PCM WAV files, which could get large!
Have you considered midi as an alternative?
Wait, there is an ogg vorbis extension you can install... it seems to be an encoder/decoder wrapper that gives you access to the raw PCM WAV. Could save file space.
There's a constant (ALLOW_UPLOADS) that you can set to 1 to put a little form in so you can upload wavs. That's switched off on the online version for reasons of saving space.
You'll need to create a couple of subdirectories:
/wavs (needs to be writable if you enable uploads.)
/images (needs to be writable so the script can cache waveform pngs.)