Writing sound files
Posted: Wed Feb 21, 2007 3:18 pm
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
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:Code: Select all
<?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);
}
?>feyd | Please use
Code: Select all
,Code: Select all
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]