/**
  * Constructs the class with given parameters and parses object related data.
  *
  * @param Zend_Io_Reader $reader The reader object.
  */
 public function __construct($reader)
 {
     parent::__construct($reader);
     $this->_minimumBlockSize = $this->_reader->readUInt16BE();
     $this->_maximumBlockSize = $this->_reader->readUInt16BE();
     $this->_minimumFrameSize = $this->_reader->readUInt24BE();
     $this->_maximumFrameSize = $this->_reader->readUInt24BE();
     $this->_sampleRate = Zend_Bit_Twiddling::getValue($tmp = $this->_reader->readUInt32BE(), 12, 31);
     $this->_numberOfChannels = Zend_Bit_Twiddling::getValue($tmp, 9, 11) + 1;
     $this->_bitsPerSample = Zend_Bit_Twiddling::getValue($tmp, 4, 8) + 1;
     $this->_numberOfSamples = Zend_Bit_Twiddling::getValue($tmp, 0, 3) << 32 | $this->_reader->readUInt32BE();
     $this->_md5Signature = bin2hex($this->_reader->read(16));
 }
示例#2
0
 /**
  * Constructs the class with given parameters and reads object related data
  * from the bitstream.
  *
  * @param Zend_Io_Reader $reader The reader object.
  * @param Array $options Array of options.
  */
 public function __construct($reader, &$options = array())
 {
     parent::__construct($reader, $options);
     $flags = $reader->readUInt32BE();
     if (Zend_Bit_Twiddling::testAnyBits($flags, 0x1)) {
         $this->_frames = $this->_reader->readUInt32BE();
     }
     if (Zend_Bit_Twiddling::testAnyBits($flags, 0x2)) {
         $this->_bytes = $this->_reader->readUInt32BE();
     }
     if (Zend_Bit_Twiddling::testAnyBits($flags, 0x4)) {
         $this->_toc = array_merge(unpack('C*', $this->_reader->read(100)));
     }
     if (Zend_Bit_Twiddling::testAnyBits($flags, 0x8)) {
         $this->_qualityIndicator = $this->_reader->readUInt32BE();
     }
 }
示例#3
0
 /**
  * Constructs the class with given parameters and reads object related data
  * from the frame.
  *
  * @param Zend_Io_Reader $reader The reader object.
  * @param Array          $options Array of options.
  */
 public function __construct($reader, &$options = array())
 {
     parent::__construct($reader, $options);
     $this->_offset = $this->_reader->getOffset();
     $header = $this->_reader->readUInt32BE();
     $this->_version = Zend_Bit_Twiddling::getValue($header, 19, 20);
     $this->_frequencyType = Zend_Bit_Twiddling::testBit($header, 19);
     $this->_layer = Zend_Bit_Twiddling::getValue($header, 17, 18);
     $this->_redundancy = !Zend_Bit_Twiddling::testBit($header, 16);
     $this->_bitrate = isset(self::$bitrates[$this->_frequencyType][$this->_layer][$index = Zend_Bit_Twiddling::getValue($header, 12, 15)]) ? self::$bitrates[$this->_frequencyType][$this->_layer][$index] : false;
     $this->_samplingFrequency = isset(self::$samplingFrequencies[$this->_version][$index = Zend_Bit_Twiddling::getValue($header, 10, 11)]) ? self::$samplingFrequencies[$this->_version][$index] : false;
     $this->_padding = Zend_Bit_Twiddling::testBit($header, 9);
     $this->_mode = Zend_Bit_Twiddling::getValue($header, 6, 7);
     $this->_modeExtension = Zend_Bit_Twiddling::getValue($header, 4, 5);
     $this->_copyright = Zend_Bit_Twiddling::testBit($header, 3);
     $this->_original = Zend_Bit_Twiddling::testBit($header, 2);
     $this->_emphasis = Zend_Bit_Twiddling::getValue($header, 0, 1);
     $this->_length = (int) (self::$coefficients[$this->_frequencyType][$this->_layer] * ($this->_bitrate * 1000) / $this->_samplingFrequency + ($this->_padding ? 1 : 0)) * self::$slotsizes[$this->_layer];
     $this->_samples = self::$samples[$this->_frequencyType][$this->_layer];
     if ($this->getOption('readmode', 'lazy') == 'full') {
         $this->_readCrc();
         $this->_readData();
     }
     $this->_reader->skip($this->_length - 4);
 }
示例#4
0
 /**
  * Constructs the class with given file and options.
  *
  * @param string|resource|Zend_Io_Reader $filename The path to the file,
  *  file descriptor of an opened file, or a {@link Zend_Io_Reader} instance.
  * @param Array                          $options  The options array.
  */
 public function __construct($filename, $options = array())
 {
     if ($filename instanceof Zend_Io_Reader) {
         $this->_reader =& $filename;
     } else {
         require_once 'Zend/Io/FileReader.php';
         try {
             $this->_reader = new Zend_Io_FileReader($filename);
         } catch (Zend_Io_Exception $e) {
             $this->_reader = null;
             require_once 'Zend/Media/Mpeg/Exception.php';
             throw new Zend_Media_Mpeg_Exception($e->getMessage());
         }
     }
     $this->setOptions($options);
     $startCode = 0;
     $startTime = 0;
     $pictureCount = 0;
     $pictureRate = 0;
     $rates = array(0, 23.976, 24, 25, 29.97, 30, 50, 59.94, 60);
     $foundSeqHdr = false;
     $foundGOP = false;
     do {
         do {
             $startCode = $this->nextStartCode();
             echo "STARTCODE: {$startCode}\n";
         } while ($startCode != 0x1b3 && $startCode != 0x1b8);
         if ($startCode == 0x1b3 && $pictureRate == 0) {
             $i1 = $this->_reader->readUInt32BE();
             $i2 = $this->_reader->readUInt32BE();
             if (!Zend_Bit_Twiddling::testAllBits($i2, 0x2000)) {
                 throw new RuntimeException('Invalid mark');
             }
             $pictureRate = $rates[Zend_Bit_Twiddling::getValue($i1, 4, 8)];
             $foundSeqHdr = true;
         }
         if ($startCode == 0x1b8) {
             $tmp = $this->_reader->readUInt32BE();
             $startTime = ($tmp >> 26 & 0x1f) * 60 * 60 * 1000 + ($tmp >> 20 & 0x3f) * 60 * 1000 + ($tmp >> 13 & 0x3f) * 1000 + (int) (1 / $pictureRate * ($tmp >> 7 & 0x3f) * 1000);
             $foundGOP = true;
         }
     } while (!$foundSeqHdr || !$foundGOP);
     $this->_reader->setOffset($this->_reader->getSize());
     do {
         if (($startCode = $this->prevStartCode()) == 0x100) {
             $pictureCount++;
         }
     } while ($startCode != 0x1b8);
     $this->_reader->skip(4);
     $tmp = $this->_reader->readUInt32BE();
     $this->_length = (($tmp >> 26 & 0x1f) * 60 * 60 * 1000 + ($tmp >> 20 & 0x3f) * 60 * 1000 + ($tmp >> 13 & 0x3f) * 1000 + (int) (1 / $pictureRate * ($tmp >> 7 & 0x3f) * 1000) - $startTime + (int) (1 / $pictureRate * $pictureCount * 1000)) / 1000;
 }
示例#5
0
 /**
  * Constructs the class with given parameters and reads object related data
  * from the frame.
  *
  * @param Zend_Io_Reader $reader The reader object.
  * @param Array          $options Array of options.
  */
 public function __construct($reader, &$options = array())
 {
     parent::__construct($reader, $options);
     $this->_offset = $this->_reader->getOffset();
     $header = $this->_reader->readUInt32BE();
     if (!Zend_Bit_Twiddling::testAllBits(Zend_Bit_Twiddling::getValue($header, 21, 32), 0xffe)) {
         require_once 'Zend/Media/Mpeg/Exception.php';
         throw new Zend_Media_Mpeg_Exception('File does not contain a valid MPEG Audio Bit Stream (Invalid frame sync)');
     }
     $this->_version = Zend_Bit_Twiddling::getValue($header, 19, 20);
     $this->_frequencyType = Zend_Bit_Twiddling::testBit($header, 19);
     $this->_layer = Zend_Bit_Twiddling::getValue($header, 17, 18);
     $this->_redundancy = !Zend_Bit_Twiddling::testBit($header, 16);
     $this->_bitrate = isset(self::$bitrates[$this->_frequencyType][$this->_layer][$index = Zend_Bit_Twiddling::getValue($header, 12, 15)]) ? self::$bitrates[$this->_frequencyType][$this->_layer][$index] : false;
     $this->_samplingFrequency = isset(self::$samplingFrequencies[$this->_version][$index = Zend_Bit_Twiddling::getValue($header, 10, 11)]) ? self::$samplingFrequencies[$this->_version][$index] : false;
     $this->_padding = Zend_Bit_Twiddling::testBit($header, 9);
     $this->_mode = Zend_Bit_Twiddling::getValue($header, 6, 7);
     $this->_modeExtension = Zend_Bit_Twiddling::getValue($header, 4, 5);
     $this->_copyright = Zend_Bit_Twiddling::testBit($header, 3);
     $this->_original = Zend_Bit_Twiddling::testBit($header, 2);
     $this->_emphasis = Zend_Bit_Twiddling::getValue($header, 0, 1);
     $this->_length = (int) (self::$coefficients[$this->_frequencyType][$this->_layer] * ($this->_bitrate * 1000) / $this->_samplingFrequency + ($this->_padding ? 1 : 0)) * self::$slotsizes[$this->_layer];
     $this->_samples = self::$samples[$this->_frequencyType][$this->_layer];
     if ($this->getOption('readmode', 'lazy') == 'full') {
         $this->_readCrc();
         $this->_readData();
     }
     $this->_reader->skip($this->_length - 4);
 }
示例#6
0
 /**
  * Constructs the class with given parameters and reads object related data
  * from the bitstream.
  *
  * @param Zend_Io_Reader $reader The reader object.
  * @param Array          $options Array of options.
  */
 public function __construct($reader, &$options = array())
 {
     parent::__construct($reader, $options);
     $this->_version = $this->_reader->readString8(5);
     $tmp = $this->_reader->readUInt8();
     $this->_revision = Zend_Bit_Twiddling::getValue($tmp, 4, 8);
     $this->_vbrMethod = Zend_Bit_Twiddling::getValue($tmp, 0, 3);
     $this->_lowpass = $this->_reader->readUInt8() * 100;
     $this->_peakSignalAmplitude = $this->_reader->readUInt32BE();
     $tmp = $this->_reader->readUInt16BE();
     $this->_radioReplayGain = array('name' => Zend_Bit_Twiddling::getValue($tmp, 0, 2), 'originator' => Zend_Bit_Twiddling::getValue($tmp, 3, 5), 'absoluteGainAdjustment' => Zend_Bit_Twiddling::getValue($tmp, 7, 15) / 10);
     $tmp = $this->_reader->readUInt16BE();
     $this->_audiophileReplayGain = array('name' => Zend_Bit_Twiddling::getValue($tmp, 0, 2), 'originator' => Zend_Bit_Twiddling::getValue($tmp, 3, 5), 'absoluteGainAdjustment' => Zend_Bit_Twiddling::getValue($tmp, 7, 15) / 10);
     $tmp = $this->_reader->readUInt8();
     $this->_encodingFlags = Zend_Bit_Twiddling::getValue($tmp, 4, 8);
     $this->_athType = Zend_Bit_Twiddling::getValue($tmp, 0, 3);
     $this->_bitrate = $this->_reader->readUInt8();
     $tmp = $this->_reader->readUInt32BE();
     // Encoder delay fields
     $this->_encoderDelaySamples = Zend_Bit_Twiddling::getValue($tmp, 20, 31);
     $this->_paddedSamples = Zend_Bit_Twiddling::getValue($tmp, 8, 19);
     // Misc field
     $this->_sourceSampleFrequency = Zend_Bit_Twiddling::getValue($tmp, 6, 7);
     $this->_unwiseSettingsUsed = Zend_Bit_Twiddling::testBit($tmp, 5);
     $this->_mode = Zend_Bit_Twiddling::getValue($tmp, 2, 4);
     $this->_noiseShaping = Zend_Bit_Twiddling::getValue($tmp, 0, 1);
     $this->_mp3Gain = pow(2, $this->_reader->readInt8() / 4);
     $tmp = $this->_reader->readUInt16BE();
     $this->_surroundInfo = Zend_Bit_Twiddling::getValue($tmp, 11, 14);
     $this->_presetUsed = Zend_Bit_Twiddling::getValue($tmp, 0, 10);
     $this->_musicLength = $this->_reader->readUInt32BE();
     $this->_musicCrc = $this->_reader->readUInt16BE();
     $this->_crc = $this->_reader->readUInt16BE();
 }