kvarnerexpress 0 Report post Posted January 17, 2006 hi! i'm having problem reading 16 bit wav files with php and it is starting to drive me crazy!i have written a small and simple script that will read wav file and create graph from it.now, it works as it should with 8 bit wav files. i'm getting all data as i'm supose to, but when it comes to 16 bit files i'm getting crap.i thought that in wav file you read chuncks as it is marked in header - so at 8 bit wav chunck is 8 bit long, at 16 bit wav 16 bit...anyway, here is part of the script where i read wav and put that in array:PHP Code: $filename = $_GET['wav']; $handle = fopen ($filename, "r"); //dohvačanje zaglavlja wav datoteke //here i read wav headers $zaglavlje[] = bin2hex (fread ($handle, 4)); $zaglavlje[] = bin2hex (fread ($handle, 4)); $zaglavlje[] = bin2hex (fread ($handle, 4)); $zaglavlje[] = bin2hex (fread ($handle, 4)); $zaglavlje[] = bin2hex (fread ($handle, 4)); $zaglavlje[] = bin2hex (fread ($handle, 2)); $zaglavlje[] = bin2hex (fread ($handle, 2)); $zaglavlje[] = bin2hex (fread ($handle, 4)); $zaglavlje[] = bin2hex (fread ($handle, 4)); $zaglavlje[] = bin2hex (fread ($handle, 2)); $zaglavlje[] = bin2hex (fread ($handle, 2)); $zaglavlje[] = bin2hex (fread ($handle, 4)); $zaglavlje[] = bin2hex (fread ($handle, 4)); //bitrate wav datoteke //this is wav bitrate $peek = hexdec(substr($zaglavlje[10], 0, 2)); //provjera da li se radi o mono ili stereo wavu //here i check if it's stereo or mono wav $kanala = hexdec(substr($zaglavlje[6], 0, 2)); if($kanala == 2){ $omjer = 20; } else{ $omjer = 40; } //čitanje podataka iz datoteke - čita se samo 600 elemenata za mono wav ili 1200 za stereo radi utede na memoriji i procesorskom vremenu while(!feof($handle)){ //read number of bytes determend by bitrate $bps = fread($handle, $peek / 8); if(strlen($bps) == 0){ break; } //put value of wav chunk in array $data[] = hexdec(bin2hex($bps)); //skip some chunks for memory optimization fread($handle, ($peek / 8) * $omjer); } fclose ($handle); i'm doing something wrong with reading wavs just i don't knaw what! thanx for any help! Share this post Link to post Share on other sites