Fix checking vbr for 2.5 codec

This commit is contained in:
wapmorgan 2019-12-03 03:57:41 +03:00
parent 91b9ab254c
commit acfbcfb5d2

View File

@ -62,13 +62,22 @@ class Mp3Info {
*/ */
static private $_sampleRateTable; static private $_sampleRateTable;
/**
* @var array
*/
static private $_vbrOffsets = [
self::MPEG_1 => [21, 36],
self::MPEG_2 => [13, 21],
self::MPEG_25 => [13, 21],
];
/** /**
* @var int Limit in bytes for seeking a mpeg header in file * @var int Limit in bytes for seeking a mpeg header in file
*/ */
public static $headerSeekLimit = 2048; public static $headerSeekLimit = 2048;
/** /**
* MPEG codec version (1 or 2) * MPEG codec version (1 or 2 or 2.5 or undefined)
* @var int * @var int
*/ */
public $codecVersion; public $codecVersion;
@ -344,15 +353,10 @@ class Mp3Info {
case 0b11: $this->channel = self::MONO; break; case 0b11: $this->channel = self::MONO; break;
} }
switch ($this->codecVersion.($this->channel == self::MONO ? 'mono' : 'stereo')) { $vbr_offset = self::$_vbrOffsets[$this->codecVersion][$this->channel == self::MONO ? 0 : 1];
case '1stereo': $offset = 36; break;
case '1mono': $offset = 21; break;
case '2stereo': $offset = 21; break;
case '2mono': $offset = 13; break;
}
// check for VBR // check for VBR
fseek($fp, $pos + $offset); fseek($fp, $pos + $vbr_offset);
if (fread($fp, 4) == self::VBR_SYNC) { if (fread($fp, 4) == self::VBR_SYNC) {
$this->isVbr = true; $this->isVbr = true;
$flagsBytes = $this->readBytes($fp, 4); $flagsBytes = $this->readBytes($fp, 4);