|
Size: | 2096 |
Storage flags: | strip |
<?php
class getid3_amr extends getid3_handler
{
public function Analyze() {
$info = &$this->getid3->info;
$this->fseek($info['avdataoffset']);
$AMRheader = $this->fread(6);
$magic = '#!AMR'."\x0A";
if (substr($AMRheader, 0, 6) != $magic) {
$info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($AMRheader, 0, 6)).'"';
return false;
}
$info['amr'] = array();
$thisfile_amr = &$info['amr'];
$info['fileformat'] = 'amr';
$info['audio']['dataformat'] = 'amr';
$info['audio']['bitrate_mode'] = 'vbr';
$info['audio']['bits_per_sample'] = 13;
$info['audio']['sample_rate'] = 8000;
$info['audio']['channels'] = 1;
$thisfile_amr['frame_mode_count'] = array(0=>0, 1=>0, 2=>0, 3=>0, 4=>0, 5=>0, 6=>0, 7=>0);
$buffer = '';
do {
if ((strlen($buffer) < $this->getid3->fread_buffer_size()) && !feof($this->getid3->fp)) {
$buffer .= $this->fread($this->getid3->fread_buffer_size() * 2);
}
$AMR_frame_header = ord(substr($buffer, 0, 1));
$codec_mode_request = ($AMR_frame_header & 0x78) >> 3;
if ($codec_mode_request > 7) {
$info['error'][] = '';
break;
}
$thisfile_amr['frame_mode_count'][$codec_mode_request]++;
$buffer = substr($buffer, $this->amr_mode_bytes_per_frame($codec_mode_request));
} while (strlen($buffer) > 0);
$info['playtime_seconds'] = array_sum($thisfile_amr['frame_mode_count']) * 0.020;
$info['audio']['bitrate'] = (8 * ($info['avdataend'] - $info['avdataoffset'])) / $info['playtime_seconds'];
$info['bitrate'] = $info['audio']['bitrate'];
return true;
}
public function amr_mode_bitrate($key) {
static $amr_mode_bitrate = array(
0 => 4750,
1 => 5150,
2 => 5900,
3 => 6700,
4 => 7400,
5 => 7950,
6 => 10200,
7 => 12200,
);
return (isset($amr_mode_bitrate[$key]) ? $amr_mode_bitrate[$key] : false);
}
public function amr_mode_bytes_per_frame($key) {
static $amr_mode_bitrate = array(
0 => 13,
1 => 14,
2 => 16,
3 => 18,
4 => 20,
5 => 21,
6 => 27,
7 => 32,
);
return (isset($amr_mode_bitrate[$key]) ? $amr_mode_bitrate[$key] : false);
}
}