Edit File by line
/home/barbar84/public_h.../wp-inclu.../ID3
File: module.audio-video.riff.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/////////////////////////////////////////////////////////////////
[2] Fix | Delete
/// getID3() by James Heinrich <info@getid3.org> //
[3] Fix | Delete
// available at https://github.com/JamesHeinrich/getID3 //
[4] Fix | Delete
// or https://www.getid3.org //
[5] Fix | Delete
// or http://getid3.sourceforge.net //
[6] Fix | Delete
// see readme.txt for more details //
[7] Fix | Delete
/////////////////////////////////////////////////////////////////
[8] Fix | Delete
// //
[9] Fix | Delete
// module.audio-video.riff.php //
[10] Fix | Delete
// module for analyzing RIFF files //
[11] Fix | Delete
// multiple formats supported by this module: //
[12] Fix | Delete
// Wave, AVI, AIFF/AIFC, (MP3,AC3)/RIFF, Wavpack v3, 8SVX //
[13] Fix | Delete
// dependencies: module.audio.mp3.php //
[14] Fix | Delete
// module.audio.ac3.php //
[15] Fix | Delete
// module.audio.dts.php //
[16] Fix | Delete
// ///
[17] Fix | Delete
/////////////////////////////////////////////////////////////////
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* @todo Parse AC-3/DTS audio inside WAVE correctly
[21] Fix | Delete
* @todo Rewrite RIFF parser totally
[22] Fix | Delete
*/
[23] Fix | Delete
[24] Fix | Delete
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
[25] Fix | Delete
exit;
[26] Fix | Delete
}
[27] Fix | Delete
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
[28] Fix | Delete
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, true);
[29] Fix | Delete
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.dts.php', __FILE__, true);
[30] Fix | Delete
[31] Fix | Delete
class getid3_riff extends getid3_handler
[32] Fix | Delete
{
[33] Fix | Delete
protected $container = 'riff'; // default
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* @return bool
[37] Fix | Delete
*
[38] Fix | Delete
* @throws getid3_exception
[39] Fix | Delete
*/
[40] Fix | Delete
public function Analyze() {
[41] Fix | Delete
$info = &$this->getid3->info;
[42] Fix | Delete
[43] Fix | Delete
// initialize these values to an empty array, otherwise they default to NULL
[44] Fix | Delete
// and you can't append array values to a NULL value
[45] Fix | Delete
$info['riff'] = array('raw'=>array());
[46] Fix | Delete
[47] Fix | Delete
// Shortcuts
[48] Fix | Delete
$thisfile_riff = &$info['riff'];
[49] Fix | Delete
$thisfile_riff_raw = &$thisfile_riff['raw'];
[50] Fix | Delete
$thisfile_audio = &$info['audio'];
[51] Fix | Delete
$thisfile_video = &$info['video'];
[52] Fix | Delete
$thisfile_audio_dataformat = &$thisfile_audio['dataformat'];
[53] Fix | Delete
$thisfile_riff_audio = &$thisfile_riff['audio'];
[54] Fix | Delete
$thisfile_riff_video = &$thisfile_riff['video'];
[55] Fix | Delete
$thisfile_riff_WAVE = array();
[56] Fix | Delete
[57] Fix | Delete
$Original['avdataoffset'] = $info['avdataoffset'];
[58] Fix | Delete
$Original['avdataend'] = $info['avdataend'];
[59] Fix | Delete
[60] Fix | Delete
$this->fseek($info['avdataoffset']);
[61] Fix | Delete
$RIFFheader = $this->fread(12);
[62] Fix | Delete
$offset = $this->ftell();
[63] Fix | Delete
$RIFFtype = substr($RIFFheader, 0, 4);
[64] Fix | Delete
$RIFFsize = substr($RIFFheader, 4, 4);
[65] Fix | Delete
$RIFFsubtype = substr($RIFFheader, 8, 4);
[66] Fix | Delete
[67] Fix | Delete
switch ($RIFFtype) {
[68] Fix | Delete
[69] Fix | Delete
case 'FORM': // AIFF, AIFC
[70] Fix | Delete
//$info['fileformat'] = 'aiff';
[71] Fix | Delete
$this->container = 'aiff';
[72] Fix | Delete
$thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize);
[73] Fix | Delete
$thisfile_riff[$RIFFsubtype] = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4));
[74] Fix | Delete
break;
[75] Fix | Delete
[76] Fix | Delete
case 'RIFF': // AVI, WAV, etc
[77] Fix | Delete
case 'SDSS': // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com)
[78] Fix | Delete
case 'RMP3': // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s
[79] Fix | Delete
//$info['fileformat'] = 'riff';
[80] Fix | Delete
$this->container = 'riff';
[81] Fix | Delete
$thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize);
[82] Fix | Delete
if ($RIFFsubtype == 'RMP3') {
[83] Fix | Delete
// RMP3 is identical to WAVE, just renamed. Used by [unknown program] when creating RIFF-MP3s
[84] Fix | Delete
$RIFFsubtype = 'WAVE';
[85] Fix | Delete
}
[86] Fix | Delete
if ($RIFFsubtype != 'AMV ') {
[87] Fix | Delete
// AMV files are RIFF-AVI files with parts of the spec deliberately broken, such as chunk size fields hardcoded to zero (because players known in hardware that these fields are always a certain size
[88] Fix | Delete
// Handled separately in ParseRIFFAMV()
[89] Fix | Delete
$thisfile_riff[$RIFFsubtype] = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4));
[90] Fix | Delete
}
[91] Fix | Delete
if (($info['avdataend'] - $info['filesize']) == 1) {
[92] Fix | Delete
// LiteWave appears to incorrectly *not* pad actual output file
[93] Fix | Delete
// to nearest WORD boundary so may appear to be short by one
[94] Fix | Delete
// byte, in which case - skip warning
[95] Fix | Delete
$info['avdataend'] = $info['filesize'];
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
$nextRIFFoffset = $Original['avdataoffset'] + 8 + $thisfile_riff['header_size']; // 8 = "RIFF" + 32-bit offset
[99] Fix | Delete
while ($nextRIFFoffset < min($info['filesize'], $info['avdataend'])) {
[100] Fix | Delete
try {
[101] Fix | Delete
$this->fseek($nextRIFFoffset);
[102] Fix | Delete
} catch (getid3_exception $e) {
[103] Fix | Delete
if ($e->getCode() == 10) {
[104] Fix | Delete
//$this->warning('RIFF parser: '.$e->getMessage());
[105] Fix | Delete
$this->error('AVI extends beyond '.round(PHP_INT_MAX / 1073741824).'GB and PHP filesystem functions cannot read that far, playtime may be wrong');
[106] Fix | Delete
$this->warning('[avdataend] value may be incorrect, multiple AVIX chunks may be present');
[107] Fix | Delete
break;
[108] Fix | Delete
} else {
[109] Fix | Delete
throw $e;
[110] Fix | Delete
}
[111] Fix | Delete
}
[112] Fix | Delete
$nextRIFFheader = $this->fread(12);
[113] Fix | Delete
if ($nextRIFFoffset == ($info['avdataend'] - 1)) {
[114] Fix | Delete
if (substr($nextRIFFheader, 0, 1) == "\x00") {
[115] Fix | Delete
// RIFF padded to WORD boundary, we're actually already at the end
[116] Fix | Delete
break;
[117] Fix | Delete
}
[118] Fix | Delete
}
[119] Fix | Delete
$nextRIFFheaderID = substr($nextRIFFheader, 0, 4);
[120] Fix | Delete
$nextRIFFsize = $this->EitherEndian2Int(substr($nextRIFFheader, 4, 4));
[121] Fix | Delete
$nextRIFFtype = substr($nextRIFFheader, 8, 4);
[122] Fix | Delete
$chunkdata = array();
[123] Fix | Delete
$chunkdata['offset'] = $nextRIFFoffset + 8;
[124] Fix | Delete
$chunkdata['size'] = $nextRIFFsize;
[125] Fix | Delete
$nextRIFFoffset = $chunkdata['offset'] + $chunkdata['size'];
[126] Fix | Delete
[127] Fix | Delete
switch ($nextRIFFheaderID) {
[128] Fix | Delete
case 'RIFF':
[129] Fix | Delete
$chunkdata['chunks'] = $this->ParseRIFF($chunkdata['offset'] + 4, $nextRIFFoffset);
[130] Fix | Delete
if (!isset($thisfile_riff[$nextRIFFtype])) {
[131] Fix | Delete
$thisfile_riff[$nextRIFFtype] = array();
[132] Fix | Delete
}
[133] Fix | Delete
$thisfile_riff[$nextRIFFtype][] = $chunkdata;
[134] Fix | Delete
break;
[135] Fix | Delete
[136] Fix | Delete
case 'AMV ':
[137] Fix | Delete
unset($info['riff']);
[138] Fix | Delete
$info['amv'] = $this->ParseRIFFAMV($chunkdata['offset'] + 4, $nextRIFFoffset);
[139] Fix | Delete
break;
[140] Fix | Delete
[141] Fix | Delete
case 'JUNK':
[142] Fix | Delete
// ignore
[143] Fix | Delete
$thisfile_riff[$nextRIFFheaderID][] = $chunkdata;
[144] Fix | Delete
break;
[145] Fix | Delete
[146] Fix | Delete
case 'IDVX':
[147] Fix | Delete
$info['divxtag']['comments'] = self::ParseDIVXTAG($this->fread($chunkdata['size']));
[148] Fix | Delete
break;
[149] Fix | Delete
[150] Fix | Delete
default:
[151] Fix | Delete
if ($info['filesize'] == ($chunkdata['offset'] - 8 + 128)) {
[152] Fix | Delete
$DIVXTAG = $nextRIFFheader.$this->fread(128 - 12);
[153] Fix | Delete
if (substr($DIVXTAG, -7) == 'DIVXTAG') {
[154] Fix | Delete
// DIVXTAG is supposed to be inside an IDVX chunk in a LIST chunk, but some bad encoders just slap it on the end of a file
[155] Fix | Delete
$this->warning('Found wrongly-structured DIVXTAG at offset '.($this->ftell() - 128).', parsing anyway');
[156] Fix | Delete
$info['divxtag']['comments'] = self::ParseDIVXTAG($DIVXTAG);
[157] Fix | Delete
break 2;
[158] Fix | Delete
}
[159] Fix | Delete
}
[160] Fix | Delete
$this->warning('Expecting "RIFF|JUNK|IDVX" at '.$nextRIFFoffset.', found "'.$nextRIFFheaderID.'" ('.getid3_lib::PrintHexBytes($nextRIFFheaderID).') - skipping rest of file');
[161] Fix | Delete
break 2;
[162] Fix | Delete
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
}
[166] Fix | Delete
if ($RIFFsubtype == 'WAVE') {
[167] Fix | Delete
$thisfile_riff_WAVE = &$thisfile_riff['WAVE'];
[168] Fix | Delete
}
[169] Fix | Delete
break;
[170] Fix | Delete
[171] Fix | Delete
default:
[172] Fix | Delete
$this->error('Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?) - expecting "FORM|RIFF|SDSS|RMP3" found "'.$RIFFsubtype.'" instead');
[173] Fix | Delete
//unset($info['fileformat']);
[174] Fix | Delete
return false;
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
$streamindex = 0;
[178] Fix | Delete
switch ($RIFFsubtype) {
[179] Fix | Delete
[180] Fix | Delete
// http://en.wikipedia.org/wiki/Wav
[181] Fix | Delete
case 'WAVE':
[182] Fix | Delete
$info['fileformat'] = 'wav';
[183] Fix | Delete
[184] Fix | Delete
if (empty($thisfile_audio['bitrate_mode'])) {
[185] Fix | Delete
$thisfile_audio['bitrate_mode'] = 'cbr';
[186] Fix | Delete
}
[187] Fix | Delete
if (empty($thisfile_audio_dataformat)) {
[188] Fix | Delete
$thisfile_audio_dataformat = 'wav';
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
if (isset($thisfile_riff_WAVE['data'][0]['offset'])) {
[192] Fix | Delete
$info['avdataoffset'] = $thisfile_riff_WAVE['data'][0]['offset'] + 8;
[193] Fix | Delete
$info['avdataend'] = $info['avdataoffset'] + $thisfile_riff_WAVE['data'][0]['size'];
[194] Fix | Delete
}
[195] Fix | Delete
if (isset($thisfile_riff_WAVE['fmt '][0]['data'])) {
[196] Fix | Delete
[197] Fix | Delete
$thisfile_riff_audio[$streamindex] = self::parseWAVEFORMATex($thisfile_riff_WAVE['fmt '][0]['data']);
[198] Fix | Delete
$thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag'];
[199] Fix | Delete
if (!isset($thisfile_riff_audio[$streamindex]['bitrate']) || ($thisfile_riff_audio[$streamindex]['bitrate'] == 0)) {
[200] Fix | Delete
$this->error('Corrupt RIFF file: bitrate_audio == zero');
[201] Fix | Delete
return false;
[202] Fix | Delete
}
[203] Fix | Delete
$thisfile_riff_raw['fmt '] = $thisfile_riff_audio[$streamindex]['raw'];
[204] Fix | Delete
unset($thisfile_riff_audio[$streamindex]['raw']);
[205] Fix | Delete
$thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex];
[206] Fix | Delete
[207] Fix | Delete
$thisfile_audio = (array) getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]);
[208] Fix | Delete
if (substr($thisfile_audio['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') {
[209] Fix | Delete
$this->warning('Audio codec = '.$thisfile_audio['codec']);
[210] Fix | Delete
}
[211] Fix | Delete
$thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate'];
[212] Fix | Delete
[213] Fix | Delete
if (empty($info['playtime_seconds'])) { // may already be set (e.g. DTS-WAV)
[214] Fix | Delete
$info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']);
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
$thisfile_audio['lossless'] = false;
[218] Fix | Delete
if (isset($thisfile_riff_WAVE['data'][0]['offset']) && isset($thisfile_riff_raw['fmt ']['wFormatTag'])) {
[219] Fix | Delete
switch ($thisfile_riff_raw['fmt ']['wFormatTag']) {
[220] Fix | Delete
[221] Fix | Delete
case 0x0001: // PCM
[222] Fix | Delete
$thisfile_audio['lossless'] = true;
[223] Fix | Delete
break;
[224] Fix | Delete
[225] Fix | Delete
case 0x2000: // AC-3
[226] Fix | Delete
$thisfile_audio_dataformat = 'ac3';
[227] Fix | Delete
break;
[228] Fix | Delete
[229] Fix | Delete
default:
[230] Fix | Delete
// do nothing
[231] Fix | Delete
break;
[232] Fix | Delete
[233] Fix | Delete
}
[234] Fix | Delete
}
[235] Fix | Delete
$thisfile_audio['streams'][$streamindex]['wformattag'] = $thisfile_audio['wformattag'];
[236] Fix | Delete
$thisfile_audio['streams'][$streamindex]['bitrate_mode'] = $thisfile_audio['bitrate_mode'];
[237] Fix | Delete
$thisfile_audio['streams'][$streamindex]['lossless'] = $thisfile_audio['lossless'];
[238] Fix | Delete
$thisfile_audio['streams'][$streamindex]['dataformat'] = $thisfile_audio_dataformat;
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
if (isset($thisfile_riff_WAVE['rgad'][0]['data'])) {
[242] Fix | Delete
[243] Fix | Delete
// shortcuts
[244] Fix | Delete
$rgadData = &$thisfile_riff_WAVE['rgad'][0]['data'];
[245] Fix | Delete
$thisfile_riff_raw['rgad'] = array('track'=>array(), 'album'=>array());
[246] Fix | Delete
$thisfile_riff_raw_rgad = &$thisfile_riff_raw['rgad'];
[247] Fix | Delete
$thisfile_riff_raw_rgad_track = &$thisfile_riff_raw_rgad['track'];
[248] Fix | Delete
$thisfile_riff_raw_rgad_album = &$thisfile_riff_raw_rgad['album'];
[249] Fix | Delete
[250] Fix | Delete
$thisfile_riff_raw_rgad['fPeakAmplitude'] = getid3_lib::LittleEndian2Float(substr($rgadData, 0, 4));
[251] Fix | Delete
$thisfile_riff_raw_rgad['nRadioRgAdjust'] = $this->EitherEndian2Int(substr($rgadData, 4, 2));
[252] Fix | Delete
$thisfile_riff_raw_rgad['nAudiophileRgAdjust'] = $this->EitherEndian2Int(substr($rgadData, 6, 2));
[253] Fix | Delete
[254] Fix | Delete
$nRadioRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT);
[255] Fix | Delete
$nAudiophileRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT);
[256] Fix | Delete
$thisfile_riff_raw_rgad_track['name'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3));
[257] Fix | Delete
$thisfile_riff_raw_rgad_track['originator'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3));
[258] Fix | Delete
$thisfile_riff_raw_rgad_track['signbit'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1));
[259] Fix | Delete
$thisfile_riff_raw_rgad_track['adjustment'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9));
[260] Fix | Delete
$thisfile_riff_raw_rgad_album['name'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3));
[261] Fix | Delete
$thisfile_riff_raw_rgad_album['originator'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3));
[262] Fix | Delete
$thisfile_riff_raw_rgad_album['signbit'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1));
[263] Fix | Delete
$thisfile_riff_raw_rgad_album['adjustment'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9));
[264] Fix | Delete
[265] Fix | Delete
$thisfile_riff['rgad']['peakamplitude'] = $thisfile_riff_raw_rgad['fPeakAmplitude'];
[266] Fix | Delete
if (($thisfile_riff_raw_rgad_track['name'] != 0) && ($thisfile_riff_raw_rgad_track['originator'] != 0)) {
[267] Fix | Delete
$thisfile_riff['rgad']['track']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_track['name']);
[268] Fix | Delete
$thisfile_riff['rgad']['track']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_track['originator']);
[269] Fix | Delete
$thisfile_riff['rgad']['track']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_track['adjustment'], $thisfile_riff_raw_rgad_track['signbit']);
[270] Fix | Delete
}
[271] Fix | Delete
if (($thisfile_riff_raw_rgad_album['name'] != 0) && ($thisfile_riff_raw_rgad_album['originator'] != 0)) {
[272] Fix | Delete
$thisfile_riff['rgad']['album']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_album['name']);
[273] Fix | Delete
$thisfile_riff['rgad']['album']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_album['originator']);
[274] Fix | Delete
$thisfile_riff['rgad']['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_album['adjustment'], $thisfile_riff_raw_rgad_album['signbit']);
[275] Fix | Delete
}
[276] Fix | Delete
}
[277] Fix | Delete
[278] Fix | Delete
if (isset($thisfile_riff_WAVE['fact'][0]['data'])) {
[279] Fix | Delete
$thisfile_riff_raw['fact']['NumberOfSamples'] = $this->EitherEndian2Int(substr($thisfile_riff_WAVE['fact'][0]['data'], 0, 4));
[280] Fix | Delete
[281] Fix | Delete
// This should be a good way of calculating exact playtime,
[282] Fix | Delete
// but some sample files have had incorrect number of samples,
[283] Fix | Delete
// so cannot use this method
[284] Fix | Delete
[285] Fix | Delete
// if (!empty($thisfile_riff_raw['fmt ']['nSamplesPerSec'])) {
[286] Fix | Delete
// $info['playtime_seconds'] = (float) $thisfile_riff_raw['fact']['NumberOfSamples'] / $thisfile_riff_raw['fmt ']['nSamplesPerSec'];
[287] Fix | Delete
// }
[288] Fix | Delete
}
[289] Fix | Delete
if (!empty($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'])) {
[290] Fix | Delete
$thisfile_audio['bitrate'] = getid3_lib::CastAsInt($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'] * 8);
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
if (isset($thisfile_riff_WAVE['bext'][0]['data'])) {
[294] Fix | Delete
// shortcut
[295] Fix | Delete
$thisfile_riff_WAVE_bext_0 = &$thisfile_riff_WAVE['bext'][0];
[296] Fix | Delete
[297] Fix | Delete
$thisfile_riff_WAVE_bext_0['title'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 0, 256));
[298] Fix | Delete
$thisfile_riff_WAVE_bext_0['author'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 256, 32));
[299] Fix | Delete
$thisfile_riff_WAVE_bext_0['reference'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 288, 32));
[300] Fix | Delete
$thisfile_riff_WAVE_bext_0['origin_date'] = substr($thisfile_riff_WAVE_bext_0['data'], 320, 10);
[301] Fix | Delete
$thisfile_riff_WAVE_bext_0['origin_time'] = substr($thisfile_riff_WAVE_bext_0['data'], 330, 8);
[302] Fix | Delete
$thisfile_riff_WAVE_bext_0['time_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 338, 8));
[303] Fix | Delete
$thisfile_riff_WAVE_bext_0['bwf_version'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 346, 1));
[304] Fix | Delete
$thisfile_riff_WAVE_bext_0['reserved'] = substr($thisfile_riff_WAVE_bext_0['data'], 347, 254);
[305] Fix | Delete
$thisfile_riff_WAVE_bext_0['coding_history'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_bext_0['data'], 601)));
[306] Fix | Delete
if (preg_match('#^([0-9]{4}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_date'], $matches_bext_date)) {
[307] Fix | Delete
if (preg_match('#^([0-9]{2}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_time'], $matches_bext_time)) {
[308] Fix | Delete
list($dummy, $bext_timestamp['year'], $bext_timestamp['month'], $bext_timestamp['day']) = $matches_bext_date;
[309] Fix | Delete
list($dummy, $bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second']) = $matches_bext_time;
[310] Fix | Delete
$thisfile_riff_WAVE_bext_0['origin_date_unix'] = gmmktime($bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second'], $bext_timestamp['month'], $bext_timestamp['day'], $bext_timestamp['year']);
[311] Fix | Delete
} else {
[312] Fix | Delete
$this->warning('RIFF.WAVE.BEXT.origin_time is invalid');
[313] Fix | Delete
}
[314] Fix | Delete
} else {
[315] Fix | Delete
$this->warning('RIFF.WAVE.BEXT.origin_date is invalid');
[316] Fix | Delete
}
[317] Fix | Delete
$thisfile_riff['comments']['author'][] = $thisfile_riff_WAVE_bext_0['author'];
[318] Fix | Delete
$thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_bext_0['title'];
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
if (isset($thisfile_riff_WAVE['MEXT'][0]['data'])) {
[322] Fix | Delete
// shortcut
[323] Fix | Delete
$thisfile_riff_WAVE_MEXT_0 = &$thisfile_riff_WAVE['MEXT'][0];
[324] Fix | Delete
[325] Fix | Delete
$thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 0, 2));
[326] Fix | Delete
$thisfile_riff_WAVE_MEXT_0['flags']['homogenous'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0001);
[327] Fix | Delete
if ($thisfile_riff_WAVE_MEXT_0['flags']['homogenous']) {
[328] Fix | Delete
$thisfile_riff_WAVE_MEXT_0['flags']['padding'] = ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0002) ? false : true;
[329] Fix | Delete
$thisfile_riff_WAVE_MEXT_0['flags']['22_or_44'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0004);
[330] Fix | Delete
$thisfile_riff_WAVE_MEXT_0['flags']['free_format'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0008);
[331] Fix | Delete
[332] Fix | Delete
$thisfile_riff_WAVE_MEXT_0['nominal_frame_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 2, 2));
[333] Fix | Delete
}
[334] Fix | Delete
$thisfile_riff_WAVE_MEXT_0['anciliary_data_length'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 6, 2));
[335] Fix | Delete
$thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 8, 2));
[336] Fix | Delete
$thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_left'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0001);
[337] Fix | Delete
$thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_free'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0002);
[338] Fix | Delete
$thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_right'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0004);
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
if (isset($thisfile_riff_WAVE['cart'][0]['data'])) {
[342] Fix | Delete
// shortcut
[343] Fix | Delete
$thisfile_riff_WAVE_cart_0 = &$thisfile_riff_WAVE['cart'][0];
[344] Fix | Delete
[345] Fix | Delete
$thisfile_riff_WAVE_cart_0['version'] = substr($thisfile_riff_WAVE_cart_0['data'], 0, 4);
[346] Fix | Delete
$thisfile_riff_WAVE_cart_0['title'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 4, 64));
[347] Fix | Delete
$thisfile_riff_WAVE_cart_0['artist'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 68, 64));
[348] Fix | Delete
$thisfile_riff_WAVE_cart_0['cut_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 132, 64));
[349] Fix | Delete
$thisfile_riff_WAVE_cart_0['client_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 196, 64));
[350] Fix | Delete
$thisfile_riff_WAVE_cart_0['category'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 260, 64));
[351] Fix | Delete
$thisfile_riff_WAVE_cart_0['classification'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 324, 64));
[352] Fix | Delete
$thisfile_riff_WAVE_cart_0['out_cue'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 388, 64));
[353] Fix | Delete
$thisfile_riff_WAVE_cart_0['start_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 452, 10));
[354] Fix | Delete
$thisfile_riff_WAVE_cart_0['start_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 462, 8));
[355] Fix | Delete
$thisfile_riff_WAVE_cart_0['end_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 470, 10));
[356] Fix | Delete
$thisfile_riff_WAVE_cart_0['end_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 480, 8));
[357] Fix | Delete
$thisfile_riff_WAVE_cart_0['producer_app_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 488, 64));
[358] Fix | Delete
$thisfile_riff_WAVE_cart_0['producer_app_version'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 552, 64));
[359] Fix | Delete
$thisfile_riff_WAVE_cart_0['user_defined_text'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 616, 64));
[360] Fix | Delete
$thisfile_riff_WAVE_cart_0['zero_db_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 680, 4), true);
[361] Fix | Delete
for ($i = 0; $i < 8; $i++) {
[362] Fix | Delete
$thisfile_riff_WAVE_cart_0['post_time'][$i]['usage_fourcc'] = substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8), 4);
[363] Fix | Delete
$thisfile_riff_WAVE_cart_0['post_time'][$i]['timer_value'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8) + 4, 4));
[364] Fix | Delete
}
[365] Fix | Delete
$thisfile_riff_WAVE_cart_0['url'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 748, 1024));
[366] Fix | Delete
$thisfile_riff_WAVE_cart_0['tag_text'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_cart_0['data'], 1772)));
[367] Fix | Delete
$thisfile_riff['comments']['tag_text'][] = substr($thisfile_riff_WAVE_cart_0['data'], 1772);
[368] Fix | Delete
[369] Fix | Delete
$thisfile_riff['comments']['artist'][] = $thisfile_riff_WAVE_cart_0['artist'];
[370] Fix | Delete
$thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_cart_0['title'];
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
if (isset($thisfile_riff_WAVE['SNDM'][0]['data'])) {
[374] Fix | Delete
// SoundMiner metadata
[375] Fix | Delete
[376] Fix | Delete
// shortcuts
[377] Fix | Delete
$thisfile_riff_WAVE_SNDM_0 = &$thisfile_riff_WAVE['SNDM'][0];
[378] Fix | Delete
$thisfile_riff_WAVE_SNDM_0_data = &$thisfile_riff_WAVE_SNDM_0['data'];
[379] Fix | Delete
$SNDM_startoffset = 0;
[380] Fix | Delete
$SNDM_endoffset = $thisfile_riff_WAVE_SNDM_0['size'];
[381] Fix | Delete
[382] Fix | Delete
while ($SNDM_startoffset < $SNDM_endoffset) {
[383] Fix | Delete
$SNDM_thisTagOffset = 0;
[384] Fix | Delete
$SNDM_thisTagSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4));
[385] Fix | Delete
$SNDM_thisTagOffset += 4;
[386] Fix | Delete
$SNDM_thisTagKey = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4);
[387] Fix | Delete
$SNDM_thisTagOffset += 4;
[388] Fix | Delete
$SNDM_thisTagDataSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2));
[389] Fix | Delete
$SNDM_thisTagOffset += 2;
[390] Fix | Delete
$SNDM_thisTagDataFlags = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2));
[391] Fix | Delete
$SNDM_thisTagOffset += 2;
[392] Fix | Delete
$SNDM_thisTagDataText = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, $SNDM_thisTagDataSize);
[393] Fix | Delete
$SNDM_thisTagOffset += $SNDM_thisTagDataSize;
[394] Fix | Delete
[395] Fix | Delete
if ($SNDM_thisTagSize != (4 + 4 + 2 + 2 + $SNDM_thisTagDataSize)) {
[396] Fix | Delete
$this->warning('RIFF.WAVE.SNDM.data contains tag not expected length (expected: '.$SNDM_thisTagSize.', found: '.(4 + 4 + 2 + 2 + $SNDM_thisTagDataSize).') at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')');
[397] Fix | Delete
break;
[398] Fix | Delete
} elseif ($SNDM_thisTagSize <= 0) {
[399] Fix | Delete
$this->warning('RIFF.WAVE.SNDM.data contains zero-size tag at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')');
[400] Fix | Delete
break;
[401] Fix | Delete
}
[402] Fix | Delete
$SNDM_startoffset += $SNDM_thisTagSize;
[403] Fix | Delete
[404] Fix | Delete
$thisfile_riff_WAVE_SNDM_0['parsed_raw'][$SNDM_thisTagKey] = $SNDM_thisTagDataText;
[405] Fix | Delete
if ($parsedkey = self::waveSNDMtagLookup($SNDM_thisTagKey)) {
[406] Fix | Delete
$thisfile_riff_WAVE_SNDM_0['parsed'][$parsedkey] = $SNDM_thisTagDataText;
[407] Fix | Delete
} else {
[408] Fix | Delete
$this->warning('RIFF.WAVE.SNDM contains unknown tag "'.$SNDM_thisTagKey.'" at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')');
[409] Fix | Delete
}
[410] Fix | Delete
}
[411] Fix | Delete
[412] Fix | Delete
$tagmapping = array(
[413] Fix | Delete
'tracktitle'=>'title',
[414] Fix | Delete
'category' =>'genre',
[415] Fix | Delete
'cdtitle' =>'album',
[416] Fix | Delete
);
[417] Fix | Delete
foreach ($tagmapping as $fromkey => $tokey) {
[418] Fix | Delete
if (isset($thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey])) {
[419] Fix | Delete
$thisfile_riff['comments'][$tokey][] = $thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey];
[420] Fix | Delete
}
[421] Fix | Delete
}
[422] Fix | Delete
}
[423] Fix | Delete
[424] Fix | Delete
if (isset($thisfile_riff_WAVE['iXML'][0]['data'])) {
[425] Fix | Delete
// requires functions simplexml_load_string and get_object_vars
[426] Fix | Delete
if ($parsedXML = getid3_lib::XML2array($thisfile_riff_WAVE['iXML'][0]['data'])) {
[427] Fix | Delete
$thisfile_riff_WAVE['iXML'][0]['parsed'] = $parsedXML;
[428] Fix | Delete
if (isset($parsedXML['SPEED']['MASTER_SPEED'])) {
[429] Fix | Delete
@list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['MASTER_SPEED']);
[430] Fix | Delete
$thisfile_riff_WAVE['iXML'][0]['master_speed'] = $numerator / ($denominator ? $denominator : 1000);
[431] Fix | Delete
}
[432] Fix | Delete
if (isset($parsedXML['SPEED']['TIMECODE_RATE'])) {
[433] Fix | Delete
@list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['TIMECODE_RATE']);
[434] Fix | Delete
$thisfile_riff_WAVE['iXML'][0]['timecode_rate'] = $numerator / ($denominator ? $denominator : 1000);
[435] Fix | Delete
}
[436] Fix | Delete
if (isset($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO']) && !empty($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) && !empty($thisfile_riff_WAVE['iXML'][0]['timecode_rate'])) {
[437] Fix | Delete
$samples_since_midnight = floatval(ltrim($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_HI'].$parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO'], '0'));
[438] Fix | Delete
$timestamp_sample_rate = (is_array($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) ? max($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) : $parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']); // XML could possibly contain more than one TIMESTAMP_SAMPLE_RATE tag, returning as array instead of integer [why? does it make sense? perhaps doesn't matter but getID3 needs to deal with it] - see https://github.com/JamesHeinrich/getID3/issues/105
[439] Fix | Delete
$thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] = $samples_since_midnight / $timestamp_sample_rate;
[440] Fix | Delete
$h = floor( $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] / 3600);
[441] Fix | Delete
$m = floor(($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600)) / 60);
[442] Fix | Delete
$s = floor( $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60));
[443] Fix | Delete
$f = ($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60) - $s) * $thisfile_riff_WAVE['iXML'][0]['timecode_rate'];
[444] Fix | Delete
$thisfile_riff_WAVE['iXML'][0]['timecode_string'] = sprintf('%02d:%02d:%02d:%05.2f', $h, $m, $s, $f);
[445] Fix | Delete
$thisfile_riff_WAVE['iXML'][0]['timecode_string_round'] = sprintf('%02d:%02d:%02d:%02d', $h, $m, $s, round($f));
[446] Fix | Delete
unset($samples_since_midnight, $timestamp_sample_rate, $h, $m, $s, $f);
[447] Fix | Delete
}
[448] Fix | Delete
unset($parsedXML);
[449] Fix | Delete
}
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
[453] Fix | Delete
[454] Fix | Delete
if (!isset($thisfile_audio['bitrate']) && isset($thisfile_riff_audio[$streamindex]['bitrate'])) {
[455] Fix | Delete
$thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate'];
[456] Fix | Delete
$info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']);
[457] Fix | Delete
}
[458] Fix | Delete
[459] Fix | Delete
if (!empty($info['wavpack'])) {
[460] Fix | Delete
$thisfile_audio_dataformat = 'wavpack';
[461] Fix | Delete
$thisfile_audio['bitrate_mode'] = 'vbr';
[462] Fix | Delete
$thisfile_audio['encoder'] = 'WavPack v'.$info['wavpack']['version'];
[463] Fix | Delete
[464] Fix | Delete
// Reset to the way it was - RIFF parsing will have messed this up
[465] Fix | Delete
$info['avdataend'] = $Original['avdataend'];
[466] Fix | Delete
$thisfile_audio['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
[467] Fix | Delete
[468] Fix | Delete
$this->fseek($info['avdataoffset'] - 44);
[469] Fix | Delete
$RIFFdata = $this->fread(44);
[470] Fix | Delete
$OrignalRIFFheaderSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 4, 4)) + 8;
[471] Fix | Delete
$OrignalRIFFdataSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44;
[472] Fix | Delete
[473] Fix | Delete
if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) {
[474] Fix | Delete
$info['avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize);
[475] Fix | Delete
$this->fseek($info['avdataend']);
[476] Fix | Delete
$RIFFdata .= $this->fread($OrignalRIFFheaderSize - $OrignalRIFFdataSize);
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
// move the data chunk after all other chunks (if any)
[480] Fix | Delete
// so that the RIFF parser doesn't see EOF when trying
[481] Fix | Delete
// to skip over the data chunk
[482] Fix | Delete
$RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8);
[483] Fix | Delete
$getid3_riff = new getid3_riff($this->getid3);
[484] Fix | Delete
$getid3_riff->ParseRIFFdata($RIFFdata);
[485] Fix | Delete
unset($getid3_riff);
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
if (isset($thisfile_riff_raw['fmt ']['wFormatTag'])) {
[489] Fix | Delete
switch ($thisfile_riff_raw['fmt ']['wFormatTag']) {
[490] Fix | Delete
case 0x0001: // PCM
[491] Fix | Delete
if (!empty($info['ac3'])) {
[492] Fix | Delete
// Dolby Digital WAV files masquerade as PCM-WAV, but they're not
[493] Fix | Delete
$thisfile_audio['wformattag'] = 0x2000;
[494] Fix | Delete
$thisfile_audio['codec'] = self::wFormatTagLookup($thisfile_audio['wformattag']);
[495] Fix | Delete
$thisfile_audio['lossless'] = false;
[496] Fix | Delete
$thisfile_audio['bitrate'] = $info['ac3']['bitrate'];
[497] Fix | Delete
$thisfile_audio['sample_rate'] = $info['ac3']['sample_rate'];
[498] Fix | Delete
}
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function