summaryrefslogtreecommitdiffstats
path: root/modules/getid3/module.audio.aac_adts.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules/getid3/module.audio.aac_adts.php')
-rw-r--r--modules/getid3/module.audio.aac_adts.php66
1 files changed, 33 insertions, 33 deletions
diff --git a/modules/getid3/module.audio.aac_adts.php b/modules/getid3/module.audio.aac_adts.php
index 1b98c4c6..bf252997 100644
--- a/modules/getid3/module.audio.aac_adts.php
+++ b/modules/getid3/module.audio.aac_adts.php
@@ -22,43 +22,43 @@
//
// $Id: module.audio.aac_adts.php,v 1.4 2006/11/02 10:48:01 ah Exp $
-
-
+
+
class getid3_aac_adts extends getid3_handler
{
public $option_max_frames_to_scan = 1000000;
public $option_return_extended_info = false;
-
+
private $decbin_cache;
private $bitrate_cache;
-
+
public function __construct(getID3 $getid3) {
-
+
parent::__construct($getid3);
-
+
// Populate bindec_cache
for ($i = 0; $i < 256; $i++) {
$this->decbin_cache[chr($i)] = str_pad(decbin($i), 8, '0', STR_PAD_LEFT);
}
-
+
// Init cache
$this->bitrate_cache = array ();
-
+
// Fast scanning?
if (!$getid3->option_accurate_results) {
$this->option_max_frames_to_scan = 200;
$getid3->warning('option_accurate_results set to false - bitrate and playing time are not accurate.');
}
}
-
-
+
+
public function Analyze() {
-
+
$getid3 = $this->getid3;
// based loosely on code from AACfile by Jurgen Faul <jfaulØgmx.de>
@@ -97,7 +97,7 @@ class getid3_aac_adts extends getid3_handler
$byte_offset = $frame_number = 0;
while (true) {
-
+
// Breaks out when end-of-file encountered, or invalid data found,
// or MaxFramesToScan frames have been scanned
@@ -117,10 +117,10 @@ class getid3_aac_adts extends getid3_handler
for ($i = 0; $i < 10; $i++) {
$aac_header_bitstream .= $this->decbin_cache[$sub_string[$i]];
}
-
+
$sync_test = bindec(substr($aac_header_bitstream, 0, 12));
$bit_offset = 12;
-
+
if ($sync_test != 0x0FFF) {
throw new getid3_exception('Synch pattern (0x0FFF) not found at offset '.(ftell($getid3->fp) - 10).' (found 0x0'.strtoupper(dechex($sync_test)).' instead)');
}
@@ -130,8 +130,8 @@ class getid3_aac_adts extends getid3_handler
// MPEG-4: 20, // MPEG-2: 18
$bit_offset += $aac_header_bitstream[$bit_offset] ? 18 : 20;
- }
-
+ }
+
// Gather info for first frame only - this takes time to do 1000 times!
else {
@@ -143,30 +143,30 @@ class getid3_aac_adts extends getid3_handler
$info_aac_header['mpeg_version'] = $aac_header_bitstream{$bit_offset++} == '0' ? 4 : 2;
$info_aac_header['layer'] = bindec(substr($aac_header_bitstream, $bit_offset, 2));
$bit_offset += 2;
-
+
if ($info_aac_header['layer'] != 0) {
throw new getid3_exception('Layer error - expected 0x00, found 0x'.dechex($info_aac_header['layer']).' instead');
}
-
+
$info_aac_header['crc_present'] = $aac_header_bitstream{$bit_offset++} == '0' ? true : false;
-
+
$info_aac_header['profile_id'] = bindec(substr($aac_header_bitstream, $bit_offset, 2));
$bit_offset += 2;
-
+
$info_aac_header['profile_text'] = getid3_aac_adts::AACprofileLookup($info_aac_header['profile_id'], $info_aac_header['mpeg_version']);
$info_aac_header['sample_frequency_index'] = bindec(substr($aac_header_bitstream, $bit_offset, 4));
$bit_offset += 4;
-
+
$info_aac_header['sample_frequency'] = getid3_aac_adts::AACsampleRateLookup($info_aac_header['sample_frequency_index']);
-
+
$getid3->info['audio']['sample_rate'] = $info_aac_header['sample_frequency'];
$info_aac_header['private'] = $aac_header_bitstream{$bit_offset++} == 1;
-
+
$info_aac_header['channel_configuration'] = $getid3->info['audio']['channels'] = bindec(substr($aac_header_bitstream, $bit_offset, 3));
$bit_offset += 3;
-
+
$info_aac_header['original'] = $aac_header_bitstream{$bit_offset++} == 1;
$info_aac_header['home'] = $aac_header_bitstream{$bit_offset++} == 1;
@@ -194,12 +194,12 @@ class getid3_aac_adts extends getid3_handler
$info_aac[$frame_number]['aac_frame_length'] = $frame_length;
$bit_offset += 13;
-
+
$info_aac[$frame_number]['adts_buffer_fullness'] = bindec(substr($aac_header_bitstream, $bit_offset, 11));
$bit_offset += 11;
-
+
$getid3->info['audio']['bitrate_mode'] = ($info_aac[$frame_number]['adts_buffer_fullness'] == 0x07FF) ? 'vbr' : 'cbr';
-
+
$info_aac[$frame_number]['num_raw_data_blocks'] = bindec(substr($aac_header_bitstream, $bit_offset, 2));
$bit_offset += 2;
@@ -230,10 +230,10 @@ class getid3_aac_adts extends getid3_handler
}
}
-
-
+
+
public static function AACsampleRateLookup($samplerate_id) {
-
+
static $lookup = array (
0 => 96000,
1 => 88200,
@@ -258,14 +258,14 @@ class getid3_aac_adts extends getid3_handler
public static function AACprofileLookup($profile_id, $mpeg_version) {
-
+
static $lookup = array (
- 2 => array (
+ 2 => array (
0 => 'Main profile',
1 => 'Low Complexity profile (LC)',
2 => 'Scalable Sample Rate profile (SSR)',
3 => '(reserved)'
- ),
+ ),
4 => array (
0 => 'AAC_MAIN',
1 => 'AAC_LC',