function Wav_graph ($file, $f =0, $w =0) { Global $DATA _dir; if (!is_file ($file)) return 0; $fp = fopen ($DATA _dir. $file, ' R '); $raw = Fread ($fp, 36); $str = "; $header = Unpack (' a4riff/vsize/a4wav/a4head/vheadsize/vpcm/vchannels/vsamplerate/vbyterate/vblockalign/ Vsamplebits ', $raw); foreach ($header as $k = $v) $str. = $k. ': '. $v. '; Fseek ($fp, + $header [' headsize ']-16); $raw = Fread ($fp, 8); $data = Unpack (' a4data/vdatasize ', $raw); foreach ($data as $k = $v) $str. = $k. ': '. $v. '; $b = $header [' samplebits ']; $c = $header [' Channels ']; $l = $b * $c/8; Sample frame length in bytes $s = $data [' datasize ']/$l; Total number of samples $r = $header [' samplerate ']; if ($f) $h = POW (2, $b)/$f; Else {$h = $, $f = POW (2, $b-1)/$h;} if ($w = = 0) $w = Round ($r/1000); Default to show 1k sample frames per minute Header ("Content-type:image/png"); $im = Imagecreate ($s/$w, $h * $c * 2); Imagecolorallocate ($im, 0xFF, 0xFF, 0xff); White BG $color = imagecolorallocate ($im, 0, 0, 255); Black Imagestring ($im, 5, 5, 5, $STR, $color); $x = 0; $y = Array (); $yn = Array (); for ($i = 0; $i < $c; $i + +) $y [$i] = $h * $i + $h; $n = $l * $W; while (1) { if ($s = = 0) Break if ($s < $n) $n = $s; $samples = Fread ($fp, $n); if ($samples = = = FALSE) Break $packed = Unpack ("s*", $samples); foreach ($packed as $k = $v) { $cnt = ($k-1)% ($w * $l); if ($cnt > $c-1) Continue $yn [$CNT] = $h * $cnt + $h-$v/$f; Imageline ($im, $x, $y [$cnt], $x +1, $yn [$cnt], $color); $y [$cnt] = $yn [$cnt]; $x + +; } $s-= $n; } Imagepng ($im); Imagedestroy ($im); } Wav_graph (' getwave.wav '); ?> |