2
/////////////////////////////////////////////////////////////////
3
/// getID3() by James Heinrich <info@getid3.org> //
4
// available at http://getid3.sourceforge.net //
5
// or http://www.getid3.org //
6
/////////////////////////////////////////////////////////////////
7
// See readme.txt for more details //
8
/////////////////////////////////////////////////////////////////
10
// module.audio.shorten.php //
11
// module for analyzing Shorten Audio files //
12
// dependencies: NONE //
14
/////////////////////////////////////////////////////////////////
17
class getid3_shorten extends getid3_handler
21
$info = &$this->getid3->info;
23
fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
25
$ShortenHeader = fread($this->getid3->fp, 8);
27
if (substr($ShortenHeader, 0, 4) != $magic) {
28
$info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($ShortenHeader, 0, 4)).'"';
31
$info['fileformat'] = 'shn';
32
$info['audio']['dataformat'] = 'shn';
33
$info['audio']['lossless'] = true;
34
$info['audio']['bitrate_mode'] = 'vbr';
36
$info['shn']['version'] = getid3_lib::LittleEndian2Int(substr($ShortenHeader, 4, 1));
38
fseek($this->getid3->fp, $info['avdataend'] - 12, SEEK_SET);
39
$SeekTableSignatureTest = fread($this->getid3->fp, 12);
40
$info['shn']['seektable']['present'] = (bool) (substr($SeekTableSignatureTest, 4, 8) == 'SHNAMPSK');
41
if ($info['shn']['seektable']['present']) {
42
$info['shn']['seektable']['length'] = getid3_lib::LittleEndian2Int(substr($SeekTableSignatureTest, 0, 4));
43
$info['shn']['seektable']['offset'] = $info['avdataend'] - $info['shn']['seektable']['length'];
44
fseek($this->getid3->fp, $info['shn']['seektable']['offset'], SEEK_SET);
45
$SeekTableMagic = fread($this->getid3->fp, 4);
47
if ($SeekTableMagic != $magic) {
49
$info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['shn']['seektable']['offset'].', found "'.getid3_lib::PrintHexBytes($SeekTableMagic).'"';
54
// typedef struct tag_TSeekEntry
56
// unsigned long SampleNumber;
57
// unsigned long SHNFileByteOffset;
58
// unsigned long SHNLastBufferReadPosition;
59
// unsigned short SHNByteGet;
60
// unsigned short SHNBufferOffset;
61
// unsigned short SHNFileBitOffset;
62
// unsigned long SHNGBuffer;
63
// unsigned short SHNBitShift;
70
$SeekTableData = fread($this->getid3->fp, $info['shn']['seektable']['length'] - 16);
71
$info['shn']['seektable']['entry_count'] = floor(strlen($SeekTableData) / 80);
72
//$info['shn']['seektable']['entries'] = array();
73
//$SeekTableOffset = 0;
74
//for ($i = 0; $i < $info['shn']['seektable']['entry_count']; $i++) {
75
// $SeekTableEntry['sample_number'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
76
// $SeekTableOffset += 4;
77
// $SeekTableEntry['shn_file_byte_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
78
// $SeekTableOffset += 4;
79
// $SeekTableEntry['shn_last_buffer_read_position'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
80
// $SeekTableOffset += 4;
81
// $SeekTableEntry['shn_byte_get'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
82
// $SeekTableOffset += 2;
83
// $SeekTableEntry['shn_buffer_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
84
// $SeekTableOffset += 2;
85
// $SeekTableEntry['shn_file_bit_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
86
// $SeekTableOffset += 2;
87
// $SeekTableEntry['shn_gbuffer'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
88
// $SeekTableOffset += 4;
89
// $SeekTableEntry['shn_bit_shift'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
90
// $SeekTableOffset += 2;
91
// for ($j = 0; $j < 3; $j++) {
92
// $SeekTableEntry['cbuf0'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
93
// $SeekTableOffset += 4;
95
// for ($j = 0; $j < 3; $j++) {
96
// $SeekTableEntry['cbuf1'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
97
// $SeekTableOffset += 4;
99
// for ($j = 0; $j < 4; $j++) {
100
// $SeekTableEntry['offset0'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
101
// $SeekTableOffset += 4;
103
// for ($j = 0; $j < 4; $j++) {
104
// $SeekTableEntry['offset1'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
105
// $SeekTableOffset += 4;
108
// $info['shn']['seektable']['entries'][] = $SeekTableEntry;
115
if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
116
$info['error'][] = 'PHP running in Safe Mode - backtick operator not available, cannot run shntool to analyze Shorten files';
120
if (GETID3_OS_ISWINDOWS) {
122
$RequiredFiles = array('shorten.exe', 'cygwin1.dll', 'head.exe');
123
foreach ($RequiredFiles as $required_file) {
124
if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) {
125
$info['error'][] = GETID3_HELPERAPPSDIR.$required_file.' does not exist';
129
$commandline = GETID3_HELPERAPPSDIR.'shorten.exe -x "'.$info['filenamepath'].'" - | '.GETID3_HELPERAPPSDIR.'head.exe -c 64';
130
$commandline = str_replace('/', '\\', $commandline);
134
static $shorten_present;
135
if (!isset($shorten_present)) {
136
$shorten_present = file_exists('/usr/local/bin/shorten') || `which shorten`;
138
if (!$shorten_present) {
139
$info['error'][] = 'shorten binary was not found in path or /usr/local/bin';
142
$commandline = (file_exists('/usr/local/bin/shorten') ? '/usr/local/bin/' : '' ) . 'shorten -x '.escapeshellarg($info['filenamepath']).' - | head -c 64';
146
$output = `$commandline`;
148
if (!empty($output) && (substr($output, 12, 4) == 'fmt ')) {
150
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
152
$fmt_size = getid3_lib::LittleEndian2Int(substr($output, 16, 4));
153
$DecodedWAVFORMATEX = getid3_riff::RIFFparseWAVEFORMATex(substr($output, 20, $fmt_size));
154
$info['audio']['channels'] = $DecodedWAVFORMATEX['channels'];
155
$info['audio']['bits_per_sample'] = $DecodedWAVFORMATEX['bits_per_sample'];
156
$info['audio']['sample_rate'] = $DecodedWAVFORMATEX['sample_rate'];
158
if (substr($output, 20 + $fmt_size, 4) == 'data') {
160
$info['playtime_seconds'] = getid3_lib::LittleEndian2Int(substr($output, 20 + 4 + $fmt_size, 4)) / $DecodedWAVFORMATEX['raw']['nAvgBytesPerSec'];
164
$info['error'][] = 'shorten failed to decode DATA chunk to expected location, cannot determine playtime';
169
$info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8;
173
$info['error'][] = 'shorten failed to decode file to WAV for parsing';
b'\\ No newline at end of file'