mardi 21 avril 2015

php check wav file format?

I'm using the following code to check a wav file in php.

$fp=$d=$data=$format=$bit=$chn="0"; 
$fp = fopen('ppk.wav', 'r'); fseek($fp, 20); $d = fread($fp, 18);

$data = unpack('vfmt/vch/Vsr/Vdr/vbs/vbis/vext', $d);  
$format = array(0x0001 => 'PCM',0x0003 => 'IEEE Float',0x0006 => 'A-LAW',0x0007 => 'MuLAW',0xFFFE => 'Extensible',);
$bit = rtrim($data['sr'],"0") * rtrim($data['dr'],"0");  
$chn = ($data['ch'] = 1) ? "Mono" : "Stereo"; 
fclose($fp); 

echo "{$format[$data['fmt']]} {$data['sr']}Hz {$bit}bit {$chn}";    

    if ($format[$data['fmt']]!="A-LAW" || $data['ch']>1 || $data['dr']>8000 || $bit>64) {

        echo "wrong format";

    } 

This works well and shows if the file is the wrong format.

I'd now like to check for another wav file..

So the wav file can be either A-LAW mono 8khz 64bits OR PCM mono 16khz 512bits.

But I'm not sure how to write the if statement to check for both ?

eg:

if ( Alaw mon 8khz <64bit || pcm mono 16khz <512) 

Any ideas ? Thanks

Aucun commentaire:

Enregistrer un commentaire