AudioFile.class.php
Upload User: feiyaoda
Upload Date: 2016-11-21
Package Size: 9556k
Code Size: 25k
Category:

WEB Mail

Development Platform:

PHP

  1. <?php
  2. // ************************************************************************
  3. // Class    AudioFile
  4. // Version: 0.5
  5. // Date:    12/08/2002
  6. // Author:  michael kamleitner (mika@ssw.co.at)
  7. //     reto gassmann (gassi@gassi.cx) - additional mp3-code
  8. // WWW:     http://www.entropy.at/forum.php?action=thread&t_id=15 
  9. //          (suggestions, bug-reports & general shouts are welcome)
  10. // ************************************************************************
  11. class AudioFile
  12. {
  13. var $wave_id;
  14. var $wave_type;
  15. var $wave_compression;
  16. var $wave_channels;
  17. var $wave_framerate;
  18. var $wave_byterate;
  19. var $wave_bits;
  20. var $wave_size;
  21. var $wave_filename;
  22. var $wave_length;
  23. var $id3_tag;
  24. var $id3_title;
  25. var $id3_artist;
  26. var $id3_album;
  27. var $id3_year;
  28. var $id3_comment;
  29. var $id3_genre;
  30. var $visual_graph_color; // HTML-Style: "#rrggbb"
  31. var $visual_background_color;
  32. var $visual_grid_color;
  33. var $visual_border_color;
  34. var $visual_grid; // true/false
  35. var $visual_border; // true/false
  36. var $visual_width; // width in pixel
  37. var $visual_height; // height in pixel
  38. var $visual_graph_mode; // 0|1
  39. var $visual_fileformat; // "jpeg","png", everything & else default = "png"
  40. // ************************************************************************
  41. // mp3info extracts the attributes of mp3-files
  42. // (code contributed by reto gassmann (gassi@gassi.cx)
  43. // ************************************************************************
  44. function mp3info()
  45. {
  46. $byte  = array();
  47. $version  = array("MPEG Version 2.5",false,"MPEG Version 2 (ISO/IEC 13818-3)","MPEG Version 1 (ISO/IEC 11172-3)");
  48. $version_bitrate = array(1,false,1,0);
  49. $version_sampling = array(2,false,1,0);
  50. $layer = array(false,"Layer III","Layer II","Layer I");
  51. $layer_bitrate = array(false,2,1,0);
  52. $layer_lengt = array(false,1,1,0);
  53. $protection  = array("Protected by CRC (16bit crc follows header)","Not protected");
  54. $byterate = array(
  55. array(
  56. array("free",32,64,96,128,160,192,224,256,288,320,352,384,416,448,"bad"),
  57. array("free",32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,"bad"),
  58. array("free",32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,"bad")
  59.      ),
  60. array(
  61. array("free",32,48,56, 64, 80, 96,112,128,144,160,176,192,224,256,"bad"),
  62. array("free", 8,16,24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160,"bad"),
  63. array("free", 8,16,24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160,"bad")
  64.      )
  65.        );
  66. $samplingrate = array(
  67. array(44100,48000,32000,false),
  68. array(22050,24000,16000,false),
  69. array(11025,12000, 8000,false)
  70.        );
  71. $cannel_mode = array("Stereo","Joint stereo (Stereo)","Dual channel (Stereo)","Single channel (Mono)");
  72. $copyright = array("Audio is not copyrighted","Audio is copyrighted ");
  73. $original = array("Copy of original media","Original media"); 
  74. $emphasis = array("none","50/15 ms",false,"CCIT J.17 ");
  75. //id3-stuff
  76. $genre = array
  77. ("Blues","Classic Rock","Country","Dance","Disco","Funk","Grunge","Hip-Hop","Jazz","Metal","New Age","Oldies","Other","Pop","R&B",
  78. "Rap","Reggae","Rock","Techno","Industrial","Alternative","Ska","Death Metal","Pranks","Soundtrack","Euro-Techno","Ambient","Trip-Hop",
  79. "Vocal","Jazz+Funk","Fusion","Trance","Classical","Instrumental","Acid","House","Game","Sound Clip","Gospel","Noise","Alternative Rock",
  80. "Bass","Soul","Punk","Space","Meditative","Instrumental Pop","Instrumental Rock","Ethnic","Gothic","Darkwave","Techno-Industrial",
  81. "Electronic","Pop-Folk","Eurodance","Dream","Southern Rock","Comedy","Cult","Gangsta","Top 40","Christian Rap","Pop/Funk","Jungle",
  82. "Native US","Cabaret","New Wave","Psychadelic","Rave","Showtunes","Trailer","Lo-Fi","Tribal","Acid Punk","Acid Jazz","Polka","Retro",
  83. "Musical","Rock & Roll","Hard Rock","Folk","Folk-Rock","National Folk","Swing","Fast Fusion","Bebob","Latin","Revival","Celtic","Bluegrass",
  84. "Avantgarde","Gothic Rock","Progressive Rock","Psychedelic Rock","Symphonic Rock","Slow Rock","Big Band","Chorus","Easy Listening","Acoustic",
  85. "Humour","Speech","Chanson","Opera","Chamber Music","Sonata","Symphony","Booty Bass","Primus","Porn Groove","Satire","Slow Jam","Club",
  86. "Tango","Samba","Folklore","Ballad","Power Ballad","Rhytmic Soul","Freestyle","Duet","Punk Rock","Drum Solo","Acapella","Euro-House",
  87. "Dance Hall","Goa","Drum & Bass","Club-House","Hardcore","Terror","Indie","BritPop","Negerpunk","Polsk Punk","Beat","Christian Gangsta Rap",
  88. "Heavy Metal","Black Metal","Crossover","Contemporary Christian","Christian Rock","Merengue","Salsa","Trash Metal","Anime","Jpop","Synthpop");
  89. //id3v2 check----------------------------
  90. $footer = 0;
  91. $header = 0;
  92. $v1tag = 0;
  93. $fp = fopen($this->wave_filename,"r");
  94. $tmp = fread($fp,3);
  95. if($tmp == "ID3")
  96. {
  97. $tmp  = ord(fread($fp,1));
  98. $tmp2  = ord(fread($fp,1));
  99. $info["mpeg_id3v2_tag"]["version"] = "ID3v2.".$tmp.".".$tmp2;
  100. $tmp  = ord(fread($fp,1));
  101. if($tmp & 128)$info["mpeg_id3v2_tag"]["flag"]["unsync"] = "set";
  102. if($tmp & 64) $info["mpeg_id3v2_tag"]["flag"]["extended"] = "set";
  103. if($tmp & 32) $info["mpeg_id3v2_tag"]["flag"]["experimental"] = "set";
  104. if($tmp & 16)
  105. {
  106. $info["mpeg_id3v2_tag"]["flag"]["footer"] = "set";
  107. $footer = 10;
  108. }
  109. $tmp  = ord(fread($fp,1))& 127;
  110. $tmp2  = ord(fread($fp,1))& 127;
  111. $tmp3 = ord(fread($fp,1))& 127;
  112. $tmp4  = ord(fread($fp,1))& 127;
  113. $info["mpeg_id3v2_tag"]["header_lenght"] = ($tmp * 2097152) + ($tmp2 * 16384) + ($tmp3 * 128) + $tmp4 + 10 + $footer;
  114. fseek ($fp,$info["mpeg_id3v2_tag"]["header_lenght"]);
  115. $header = $info["mpeg_id3v2_tag"]["header_lenght"];
  116. } else {
  117. fseek ($fp,0);
  118. $info["mpeg_id3v2_tag"] = false;
  119. }
  120. for ($x=0;$x<4;$x++)
  121. {
  122. $byte[$x] = ord(fread($fp,1));
  123. }
  124. fseek ($fp, -128 ,SEEK_END);
  125. $TAG = fread($fp,128);
  126. fclose($fp);
  127. //id tag?-------------------------------
  128. if(substr($TAG,0,3) == "TAG")
  129. {
  130. $v1tag = 128;
  131. $info["mpeg_id3v1_tag"]["title"]  = substr($TAG,3,30);
  132. $info["mpeg_id3v1_tag"]["artist"]  = substr($TAG,33,30);
  133. $info["mpeg_id3v1_tag"]["album"]  = substr($TAG,63,30);
  134. $info["mpeg_id3v1_tag"]["year"]  = substr($TAG,93,4);
  135. $info["mpeg_id3v1_tag"]["comment"]  = substr($TAG,97,30);
  136. $info["mpeg_id3v1_tag"]["genre"] = "";
  137. $tmp = ord(substr($TAG,127,1));
  138. if($tmp < count($genre))
  139. {
  140. $info["mpeg_id3v1_tag"]["genre"] = $genre[$tmp];
  141. }
  142. } else {
  143. $info["mpeg_id3v1_tag"] = false;
  144. }
  145. //version-------------------------------
  146. $tmp = $byte[1] & 24;
  147. $tmp = $tmp >> 3;
  148. $info_i["mpeg_version"] = $tmp;
  149. $byte_v = $version_bitrate[$tmp];
  150. $byte_vs = $version_sampling[$tmp];
  151. $info["mpeg_version"] = $version[$tmp];
  152. //layer---------------------------------
  153. $tmp = $byte[1] & 6;
  154. $tmp = $tmp >> 1;
  155. $info_i["mpeg_layer"] = $tmp;
  156. $byte_l = $layer_bitrate[$tmp];
  157. $byte_len = $layer_lengt[$tmp];
  158. $info["mpeg_layer"] = $layer[$tmp];
  159. //bitrate-------------------------------
  160. $tmp = $byte[2] & 240;
  161. $tmp = $tmp >> 4;
  162. $info_i["mpeg_bitrate"] = $tmp;
  163. $info["mpeg_bitrate"] = $byterate[$byte_v][$byte_l][$tmp]." Kbits/sec.";
  164. //samplingrate--------------------------
  165. $tmp = $byte[2] & 12;
  166. $tmp = $tmp >> 2;
  167. $info["mpeg_sampling_rate"] = $samplingrate[$byte_vs][$tmp];
  168. //protection----------------------------
  169. $tmp = $byte[1] & 1;
  170. $info["mpeg_protection"] = $protection[$tmp];
  171. //paddingbit----------------------------
  172. $tmp = $byte[2] & 2;
  173. $tmp = $tmp >> 1;
  174. $byte_pad = $tmp;
  175. $info["mpeg_padding_bit"] = $tmp;
  176. //privatebit----------------------------
  177. $tmp = $byte[2] & 1;
  178. $byte_prv = $tmp;
  179. //channel_mode--------------------------
  180. $tmp = $byte[3] & 192;
  181. $tmp = $tmp >> 6;
  182. $info["mpeg_channel_mode"] = $cannel_mode[$tmp];
  183. //copyright-----------------------------
  184. $tmp = $byte[3] & 8;
  185. $tmp = $tmp >> 3;
  186. $info["mpeg_copyright"] = $copyright[$tmp];
  187. //original------------------------------
  188. $tmp = $byte[3] & 4;
  189. $tmp = $tmp >> 2;
  190. $info["mpeg_original"] = $original[$tmp];
  191. //emphasis------------------------------
  192. $tmp = $byte[3] & 3;
  193. $info["mpeg_emphasis"] = $emphasis[$tmp];
  194. //framelenght---------------------------
  195. if($byte_len == 0)
  196. {
  197. $rate_tmp = $info["mpeg_bitrate"] * 1000;
  198. $info["mpeg_framelenght"] = (12 * $rate_tmp / $info["mpeg_sampling_rate"] + $byte_pad) * 4 ;
  199. } elseif($byte_len == 1) {
  200. $rate_tmp = $info["mpeg_bitrate"] * 1000;
  201. $info["mpeg_framelenght"] = 144 * $rate_tmp / 
  202. $info["mpeg_sampling_rate"] + $byte_pad;
  203. }
  204. //duration------------------------------
  205. $tmp = filesize($this->wave_filename);
  206. $tmp = $tmp - $header - 4 - $v1tag;
  207. $tmp2 = ((8 * $tmp) / 1000) / $info["mpeg_bitrate"];
  208. $info["mpeg_frames"] = floor($tmp/$info["mpeg_framelenght"]);
  209. $tmp = $tmp * 8;
  210. $info["mpeg_playtime"] = $tmp/$rate_tmp;
  211. $info["mpeg_playtime"] = $tmp2;
  212. // transfer the extracted data into classAudioFile-structure
  213. $this->wave_id = "MPEG";
  214. $this->wave_type = $info["mpeg_version"];
  215. $this->wave_compression = $info["mpeg_layer"];
  216. $this->wave_channels = $info["mpeg_channel_mode"];
  217. $this->wave_framerate = $info["mpeg_sampling_rate"];
  218. $this->wave_byterate = $info["mpeg_bitrate"];
  219. $this->wave_bits = "n/a";
  220. $this->wave_size = filesize($this->wave_filename);
  221. $this->wave_length = $info["mpeg_playtime"];
  222. $this->id3_tag = $info["mpeg_id3v1_tag"];
  223. if ($this->id3_tag)
  224. {
  225. $this->id3_title = $info["mpeg_id3v1_tag"]["title"];
  226. $this->id3_artist = $info["mpeg_id3v1_tag"]["artist"];
  227. $this->id3_album = $info["mpeg_id3v1_tag"]["album"];
  228. $this->id3_year = $info["mpeg_id3v1_tag"]["year"];
  229. $this->id3_comment = $info["mpeg_id3v1_tag"]["comment"];
  230. $this->id3_genre = $info["mpeg_id3v1_tag"]["genre"];
  231. }
  232. }
  233. // ************************************************************************
  234. // longCalc calculates the decimal value of 4 bytes
  235. // mode = 0 ... b1 is the byte with least value
  236. // mode = 1 ... b1 is the byte with most value
  237. // ************************************************************************
  238. function longCalc ($b1,$b2,$b3,$b4,$mode)
  239. {
  240. $b1 = hexdec(bin2hex($b1));    
  241. $b2 = hexdec(bin2hex($b2));    
  242. $b3 = hexdec(bin2hex($b3));    
  243. $b4 = hexdec(bin2hex($b4));    
  244. if ($mode == 0)
  245. {
  246. return ($b1 + ($b2*256) + ($b3 * 65536) + ($b4 * 16777216));
  247. } else {
  248. return ($b4 + ($b3*256) + ($b2 * 65536) + ($b1 * 16777216));
  249. }
  250. }
  251. // ************************************************************************
  252. // shortCalc calculates the decimal value of 2 bytes
  253. // mode = 0 ... b1 is the byte with least value
  254. // mode = 1 ... b1 is the byte with most value
  255. // ************************************************************************
  256. function shortCalc ($b1,$b2,$mode)
  257. {
  258. $b1 = hexdec(bin2hex($b1));    
  259. $b2 = hexdec(bin2hex($b2));    
  260. if ($mode == 0)
  261. {
  262. return ($b1 + ($b2*256));
  263. } else {
  264. return ($b2 + ($b1*256));
  265. }
  266. }
  267. // ************************************************************************
  268. // getCompression delivers a string which identifies the compression-mode 
  269. // of the AudioFile-Object 
  270. // ************************************************************************
  271. function getCompression ($id)
  272. {
  273. if ($this->wave_id <> "MPEG")
  274. {
  275. $append = "($id)";
  276. switch ($id)
  277. {
  278. case 0:  return ("unknown $append"); break;
  279. case 1:  return ("pcm/uncompressed $append"); break;
  280. case 2:  return ("microsoft adpcm $append"); break;
  281. case 6:  return ("itu g.711 a-law $append"); break;
  282. case 7:  return ("itu g.711 u-law $append"); break;
  283. case 17:   return ("ima adpcm $append"); break;
  284. case 20:   return ("itu g.723 adpcm (yamaha) $append"); break;
  285. case 49:   return ("gsm 6.10 $append"); break;
  286. case 64:   return ("itu g.721 adpcm $append"); break;
  287. case 80:   return ("mpeg $append"); break;
  288. case 65536:return ("experimental $append"); break;
  289. default:   return ("not defined $append"); break;
  290. }
  291. } else {
  292. return ($id);
  293. }
  294. }
  295. // ************************************************************************
  296. // getVisualization creates a graphical visualization of the audio-sample
  297. //                  (works ONLY * for uncompressed waves!
  298. //                              * files with 1 or 2 channels
  299. //                              * 8/16/24/32 bit sample-resolution )
  300. // ************************************************************************
  301. function getVisualization ($output)
  302. {
  303. $width=$this->visual_width;
  304. $height=$this->visual_height;
  305. $height_channel = $height / $this->wave_channels;
  306. if ($this->wave_filename<>"" && $this->wave_id == "RIFF" && $this->wave_type == "WAVE" && ($this->wave_channels>=1 && $this->wave_channels<=2) && $this->wave_bits%8==0)
  307. {
  308. $file = fopen ($this->wave_filename,"r");
  309. // read the first 12 bytes (RIFF- & WAVE-chunk)
  310. for ($i=0;$i<12;$i++)
  311. {
  312. $null = fgetc ($file);
  313. }
  314. // Read the next chunk-id, supposed to be "fmt "
  315. $chunk_id_3 = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
  316. if ($chunk_id_3 == "fmt ")
  317. {
  318. $chunk_size_3 = $this->longCalc (fgetc($file) , fgetc($file) , fgetc($file) , fgetc($file),0);
  319. for ($i=0;$i<$chunk_size_3;$i++)
  320. {
  321. $null = fgetc($file);
  322. }
  323. // Read the next chunk-id, supposed to be "data"
  324. $chunk_id_4 = "";
  325. while ($chunk_id_4 <> "data" && !feof($file))
  326. {
  327. $chunk_id_4 = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
  328. if ($chunk_id_4 <> "data")
  329. {
  330. $chunk_size_4 = $this->longCalc (fgetc($file) , fgetc($file) , fgetc($file) , fgetc($file),0);
  331. for ($i=0;$i<$chunk_size_4;$i++)
  332. {
  333. $null = fgetc($file);
  334. }
  335. }
  336. }
  337. if ($chunk_id_4 == "data")
  338. {
  339. $chunk_size_4 = $this->longCalc (fgetc($file) , fgetc($file) , fgetc($file) , fgetc($file),0);
  340. $visualData = array();
  341. $bytes_per_frame = ($this->wave_bits/8)*($this->wave_channels);
  342. $bytes_per_channel = ($this->wave_bits/8);
  343. $frames = $chunk_size_4 / $bytes_per_frame;
  344. $visual_frames = ceil($frames / $width);
  345. $frame_index = 1;
  346. $data_index = 1;
  347. while (!feof($file))
  348. {
  349. for ($j=0;$j<$this->wave_channels;$j++)
  350. {
  351. $bytes = array();
  352. for ($i=0;$i<$bytes_per_channel;$i++)
  353. {
  354. $bytes[$i] = fgetc($file);
  355. }
  356. if ($frame_index == $visual_frames)
  357. {
  358. switch ($bytes_per_channel)
  359. {
  360. case 1: $visualData[$j][$data_index]= $this->shortCalc($bytes[0],$bytes[1],0); 
  361. break;
  362. case 2: $f=128;
  363. if (ord($bytes[1])&128) $f = 0;
  364. $x=chr((ord($bytes[1])&127) + $f);
  365. $visualData[$j][$data_index]= floor($this->shortCalc($bytes[0],$x,0)/256); 
  366. break;
  367. }
  368. if (($j+1) == $this->wave_channels)
  369. {
  370. $data_index++;
  371. $frame_index = 1;
  372. }
  373. } else {
  374. if (($j+1) == $this->wave_channels) $frame_index++;
  375. }
  376. }
  377. }
  378. //$im = @ImageCreate ($width, (256*$this->wave_channels)+1) or die ("Cannot Initialize new GD image stream!");
  379. $im = @ImageCreate ($width, $height) or die ("Cannot Initialize new GD image stream!");
  380. $background_color = ImageColorAllocate ($im, hexdec(substr($this->visual_background_color,1,2)),hexdec(substr($this->visual_background_color,3,2)),hexdec(substr($this->visual_background_color,5,2)));
  381. $cBlack = ImageColorAllocate ($im, hexdec(substr($this->visual_background_color,1,2)),hexdec(substr($this->visual_background_color,3,2)),hexdec(substr($this->visual_background_color,5,2)));
  382. $cGreen = ImageColorAllocate ($im, hexdec(substr($this->visual_graph_color,1,2)),hexdec(substr($this->visual_graph_color,3,2)),hexdec(substr($this->visual_graph_color,5,2)));
  383. $cRed = ImageColorAllocate ($im, hexdec(substr($this->visual_border_color,1,2)),hexdec(substr($this->visual_border_color,3,2)),hexdec(substr($this->visual_border_color,5,2)));
  384. $cBlue = ImageColorAllocate ($im, hexdec(substr($this->visual_grid_color,1,2)),hexdec(substr($this->visual_grid_color,3,2)),hexdec(substr($this->visual_grid_color,5,2)));
  385. if ($this->visual_border)
  386. {
  387. ImageRectangle ($im,0,0,($width-1),($height-1),$cRed);
  388. for ($i=0;$i<=$this->wave_channels;$i++)
  389. {
  390. ImageLine ($im,1,($i*($height_channel/2))+($height_channel/2),$width,($i*($height_channel/2))+($height_channel/2),$cRed);
  391. }
  392. }
  393. if ($this->visual_grid)
  394. {
  395. for ($i=1;$i<=($width/100*2);$i++)
  396. {
  397. ImageLine ($im,$i*50,0,$i*50,(256*$this->wave_channels),$cBlue);
  398. }
  399. }
  400. // this for-loop draws a graph for every channel
  401. for ($j=0;$j<sizeof($visualData);$j++)
  402. {
  403. $last_x = 1;
  404. $last_y = $height_channel / 2;
  405. // this for-loop draws the graphs itself
  406. for ($i=1;$i<sizeof($visualData[$j]);$i++)
  407. {
  408. $faktor = 128 / ($height_channel / 2);
  409. $val = $visualData[$j][$i] / $faktor;
  410. if ($this->visual_graph_mode == 0)
  411. {
  412. ImageLine ($im,$last_x,($last_y+($j*$height_channel)),$i,($val+($j*$height_channel)),$cGreen);
  413. } else {
  414. ImageLine ($im,$i,(($height_channel/2)+($j*$height_channel)),$i,($val+($j*$height_channel)),$cGreen);
  415. }
  416. $last_x = $i;
  417. $last_y = $val;
  418. }
  419. }
  420. // change this to generate JPG or direct output to browser
  421. if (strtolower($this->visual_fileformat) == "jpeg")
  422. {
  423. ImageJpeg ($im,$output);
  424. } else {
  425. ImagePng ($im,$output);
  426. }
  427. }
  428. }
  429. fclose ($file);
  430. } else {
  431. // AudioSample - AudioFile-Object not initialized!
  432. }
  433. }
  434. // ************************************************************************
  435. // getSampleInfo extracts the attributes of the AudioFile-Object
  436. // ************************************************************************
  437. function getSampleInfo ()
  438. {
  439. $valid = true;
  440. if (strstr(strtoupper($this->wave_filename),"MP3"))
  441. {
  442. $this->mp3info ();
  443. } else {
  444. $this->wave_size = filesize ($this->wave_filename);
  445. if ($this->wave_size > 16)
  446. {
  447. $file = fopen ($this->wave_filename,"r");
  448. $chunk_id = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
  449. $null = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
  450. $chunk_id_2 = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
  451. $this->wave_id = $chunk_id;
  452. $this->wave_type = $chunk_id_2;
  453. if (substr($chunk_id,0,2)=="PK")
  454. {
  455. // it's a ZIP-file
  456. $this->wave_id = "ZIP";
  457. $this->wave_type = "ZIP";
  458. $this->valid = true;
  459. } else {
  460. if ($this->wave_id == "RIFF" && $this->wave_type == "WAVE")
  461. {
  462. // it's a Wave-File
  463. $chunk_id = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
  464. $chunk_size = $this->longCalc (fgetc($file) , fgetc($file) , fgetc($file) , fgetc($file),0);
  465. if ($chunk_id == "fmt ")
  466. {
  467. $format_len = $chunk_size;
  468. $this->wave_compression = $this->shortCalc (fgetc ($file), fgetc ($file),0);
  469. $this->wave_channels = $this->shortCalc (fgetc ($file), fgetc ($file),0);
  470. $this->wave_framerate = $this->longCalc (fgetc ($file), fgetc ($file), fgetc ($file), fgetc ($file),0);
  471. $this->wave_byterate = $this->longCalc (fgetc ($file), fgetc ($file), fgetc ($file), fgetc ($file),0);
  472. $null = fgetc($file) . fgetc($file);
  473. $this->wave_bits = $this->shortCalc (fgetc ($file), fgetc ($file),0);
  474. $read = 16;
  475. if ($read < $format_len)
  476. {
  477. $extra_bytes = $this->shortCalc (fgetc ($file), fgetc ($file),1);
  478. $j = 0;
  479. while ($j < $extra_bytes && !feof($file))
  480. {
  481. $null = fgetc ($file);
  482. $j++;
  483. }
  484. }
  485. $chunk_id = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
  486. $chunk_size = $this->longCalc (fgetc($file) , fgetc($file) , fgetc($file) , fgetc($file),0);
  487. if ($chunk_id == "data")
  488. {
  489. $this->wave_length = (($chunk_size / $this->wave_channels) / ($this->wave_bits/8)) / $this->wave_framerate;
  490. } else {
  491. while ($chunk_id <> "data" && !feof($file))
  492. {
  493. $j = 1;
  494. while ($j <= $chunk_size && !feof($file))
  495. {
  496. $null = fgetc ($file);
  497. $j++;
  498. }
  499. $chunk_id = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
  500. //print "<br>$chunk_id*";
  501. $chunk_size = $this->longCalc (fgetc($file) , fgetc($file) , fgetc($file) , fgetc($file),0);
  502. }
  503. if ($chunk_id == "data")
  504. {
  505. $this->wave_length = (($chunk_size / $this->wave_channels) / ($this->wave_bits/8)) / $this->wave_framerate;
  506. }
  507. }
  508. } else {
  509. $valid = false;
  510. }
  511. } else {
  512. if ($this->wave_id == "FORM" && $this->wave_type == "AIFF")
  513. {
  514. // we have a AIFF file here
  515. $chunk_id = fgetc($file) . fgetc($file) . fgetc($file) . fgetc($file);
  516. $chunk_size = $this->longCalc (fgetc($file) , fgetc($file) , fgetc($file) , fgetc($file),0);
  517. if ($chunk_id == "COMM")
  518. {
  519. $format_len = $chunk_size;
  520. $this->wave_channels = $this->shortCalc (fgetc ($file), fgetc ($file),1);
  521. $null = $this->longCalc (fgetc ($file), fgetc ($file), fgetc ($file), fgetc ($file),1);
  522. $this->wave_bits = $this->shortCalc (fgetc ($file), fgetc ($file),1);
  523. $null = fgetc ($file) . fgetc ($file);
  524. $this->wave_framerate = $this->shortCalc (fgetc ($file), fgetc ($file),1);
  525. $read = 16;
  526. } else {
  527. $valid = false;
  528. }
  529. } else {
  530. // probably crap
  531. $valid = false;
  532. }
  533. }
  534. }
  535. fclose ($file);
  536. } else {
  537. $valid = false;
  538. }
  539. return ($valid);
  540. }
  541. }
  542. // ************************************************************************
  543. // printSampleInfo prints the attributes of the AudioFile-Object
  544. // ************************************************************************
  545. function printSampleInfo()
  546. {
  547. print "<table width=100% border=1>";
  548. print "<tr><td align=right>filename</td> <td>&nbsp;$this->wave_filename</td></tr>";
  549. print "<tr><td align=right>id</td> <td>&nbsp;$this->wave_id</td></tr>";
  550. print "<tr><td align=right>type</td> <td>&nbsp;$this->wave_type</td></tr>";
  551. print "<tr><td align=right>size</td> <td>&nbsp;$this->wave_size</td></tr>";
  552. print "<tr><td align=right>compression</td> <td>&nbsp;".$this->getCompression ($this->wave_compression)."</td></tr>";
  553. print "<tr><td align=right>channels</td> <td>&nbsp;$this->wave_channels</td></tr>";
  554. print "<tr><td align=right>framerate</td> <td>&nbsp;$this->wave_framerate</td></tr>";
  555. print "<tr><td align=right>byterate</td> <td>&nbsp;$this->wave_byterate</td></tr>";
  556. print "<tr><td align=right>bits</td> <td>&nbsp;$this->wave_bits</td></tr>";
  557. print "<tr><td align=right>length</td> <td>&nbsp;".number_format ($this->wave_length,"2")." sec.<br>&nbsp;".date("i:s", mktime(0,0,round($this->wave_length)))."</td></tr>";
  558. if ($this->id3_tag)
  559. {
  560. print "<tr><td align=right>id3v1-tags</td><td>";
  561. print "<table width=100% border=1>";
  562. print "<tr><td width=70 align=right>title</td><td>&nbsp;$this->id3_title</td></tr>";
  563. print "<tr><td align=right>artist</td><td>&nbsp;$this->id3_artist</td></tr>";
  564. print "<tr><td align=right>album</td><td>&nbsp;$this->id3_album</td></tr>";
  565. print "<tr><td align=right>year</td><td>&nbsp;$this->id3_year</td></tr>";
  566. print "<tr><td align=right>comment</td><td>&nbsp;$this->id3_comment</td></tr>";
  567. print "<tr><td align=right>genre</td><td>&nbsp;$this->id3_genre</td></tr>";
  568. print "</table>";
  569. print "</td></tr>";
  570. }
  571. else
  572. {
  573. print "<tr><td align=right>id3v1-tags</td><td>Not found</td></tr>";
  574. }
  575. print "</table>";
  576. }
  577. // ************************************************************************
  578. // loadFile initializes the AudioFile-Object
  579. // ************************************************************************
  580. function loadFile ($loadFilename)
  581. {
  582. $this->wave_filename = $loadFilename;
  583. $this->getSampleInfo ();
  584. $this->visual_graph_color = "#18F3AD";
  585. $this->visual_background_color = "#000000";
  586. $this->visual_grid_color = "#002C4A";
  587. $this->visual_border_color = "#A52421";
  588. $this->visual_grid = true;
  589. $this->visual_border = true;
  590. $this->visual_width = 600;
  591. $this->visual_height = 512;
  592. $this->visual_graph_mode = 1;
  593. $this->visual_fileformat = "png";
  594. }
  595. }
  596. ?>