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, 36 + $ header ['headsize']-16 ); $ Raw = fread ($ fp, 8 ); $ Data = unpack ('a4data/VDataSize ', $ raw ); Foreach ($ data as $ k => $ v) $ Str. = $ k. ':'. $ v .''; $ B = $ header ['samples']; $ 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 = 200; $ f = pow (2, $ B-1)/$ h ;} If ($ w = 0) $ W = round ($ r/1000); // default to show 1 k 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, 1000 * $ 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 '); ?> |