Example #1
0
 /**
  * Constructs the class with given parameters and reads object related data
  * from the bitstream.
  *
  * @param HausDesign_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 (HausDesign_Bit_Twiddling::testAnyBits($flags, 0x1)) {
         $this->_frames = $this->_reader->readUInt32BE();
     }
     if (HausDesign_Bit_Twiddling::testAnyBits($flags, 0x2)) {
         $this->_bytes = $this->_reader->readUInt32BE();
     }
     if (HausDesign_Bit_Twiddling::testAnyBits($flags, 0x4)) {
         $this->_toc = array_merge(unpack('C*', $this->_reader->read(100)));
     }
     if (HausDesign_Bit_Twiddling::testAnyBits($flags, 0x8)) {
         $this->_qualityIndicator = $this->_reader->readUInt32BE();
     }
 }
Example #2
0
 /**
  * Constructs the class with given parameters and reads object related data
  * from the bitstream.
  *
  * @param HausDesign_Io_Reader $reader The reader object.
  * @param Array $options Array of options.
  */
 public function __construct($reader, &$options = array())
 {
     parent::__construct($reader, $options);
     $offset = $this->_reader->getOffset();
     $this->_version = $this->_reader->readUInt16BE();
     $this->_delay = $this->_reader->readUInt16BE();
     $this->_qualityIndicator = $this->_reader->readUInt16BE();
     $this->_bytes = $this->_reader->readUInt32BE();
     $this->_frames = $this->_reader->readUInt32BE();
     $tocEntries = $this->_reader->readUInt16BE();
     $tocEntryScale = $this->_reader->readUInt16BE();
     $tocEntrySize = $this->_reader->readUInt16BE();
     $this->_tocFramesPerEntry = $this->_reader->readUInt16BE();
     $this->_toc = array_merge(unpack($tocEntrySize == 1 ? 'C*' : $tocEntrySize == 2 ? 'n*' : 'N*', $this->_reader->read($tocCount * $tocEntrySize)));
     foreach ($this->_toc as $key => $value) {
         $this->_toc[$key] = $tocEntryScale * $value;
     }
     $this->_length = $this->_reader->getOffset() - $offset;
 }
Example #3
0
 /**
  * Constructs the class with given parameters and reads object related data
  * from the frame.
  *
  * @param HausDesign_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 = null;
     for ($i = 0; $i < 5775; $i++) {
         $header = $this->_reader->readUInt32BE();
         if (HausDesign_Bit_Twiddling::testAllBits(HausDesign_Bit_Twiddling::getValue($header, 21, 32), 0xffe)) {
             break;
         }
         $this->_reader->setOffset(++$this->_offset + 1);
         if ($this->_offset == $this->_reader->getSize() || $i == 5775 - 1) {
             require_once 'HausDesign/Media/Mpeg/Exception.php';
             throw new HausDesign_Media_Mpeg_Exception('File does not contain a valid MPEG Audio Bit Stream (Invalid frame sync and resynchronization failed)');
         }
     }
     $this->_version = HausDesign_Bit_Twiddling::getValue($header, 19, 20);
     $this->_frequencyType = HausDesign_Bit_Twiddling::testBit($header, 19);
     $this->_layer = HausDesign_Bit_Twiddling::getValue($header, 17, 18);
     $this->_redundancy = !HausDesign_Bit_Twiddling::testBit($header, 16);
     $this->_bitrate = isset(self::$bitrates[$this->_frequencyType][$this->_layer][$index = HausDesign_Bit_Twiddling::getValue($header, 12, 15)]) ? self::$bitrates[$this->_frequencyType][$this->_layer][$index] : false;
     $this->_samplingFrequency = isset(self::$samplingFrequencies[$this->_version][$index = HausDesign_Bit_Twiddling::getValue($header, 10, 11)]) ? self::$samplingFrequencies[$this->_version][$index] : false;
     $this->_padding = HausDesign_Bit_Twiddling::testBit($header, 9);
     $this->_mode = HausDesign_Bit_Twiddling::getValue($header, 6, 7);
     $this->_modeExtension = HausDesign_Bit_Twiddling::getValue($header, 4, 5);
     $this->_copyright = HausDesign_Bit_Twiddling::testBit($header, 3);
     $this->_original = HausDesign_Bit_Twiddling::testBit($header, 2);
     $this->_emphasis = HausDesign_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);
 }
Example #4
0
 /**
  * Constructs the class with given parameters and reads object related data
  * from the bitstream.
  *
  * @param HausDesign_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 = HausDesign_Bit_Twiddling::getValue($tmp, 4, 8);
     $this->_vbrMethod = HausDesign_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' => HausDesign_Bit_Twiddling::getValue($tmp, 0, 2), 'originator' => HausDesign_Bit_Twiddling::getValue($tmp, 3, 5), 'absoluteGainAdjustment' => HausDesign_Bit_Twiddling::getValue($tmp, 7, 15) / 10);
     $tmp = $this->_reader->readUInt16BE();
     $this->_audiophileReplayGain = array('name' => HausDesign_Bit_Twiddling::getValue($tmp, 0, 2), 'originator' => HausDesign_Bit_Twiddling::getValue($tmp, 3, 5), 'absoluteGainAdjustment' => HausDesign_Bit_Twiddling::getValue($tmp, 7, 15) / 10);
     $tmp = $this->_reader->readUInt8();
     $this->_encodingFlags = HausDesign_Bit_Twiddling::getValue($tmp, 4, 8);
     $this->_athType = HausDesign_Bit_Twiddling::getValue($tmp, 0, 3);
     $this->_bitrate = $this->_reader->readUInt8();
     $tmp = $this->_reader->readUInt32BE();
     // Encoder delay fields
     $this->_encoderDelaySamples = HausDesign_Bit_Twiddling::getValue($tmp, 20, 31);
     $this->_paddedSamples = HausDesign_Bit_Twiddling::getValue($tmp, 8, 19);
     // Misc field
     $this->_sourceSampleFrequency = HausDesign_Bit_Twiddling::getValue($tmp, 6, 7);
     $this->_unwiseSettingsUsed = HausDesign_Bit_Twiddling::testBit($tmp, 5);
     $this->_mode = HausDesign_Bit_Twiddling::getValue($tmp, 2, 4);
     $this->_noiseShaping = HausDesign_Bit_Twiddling::getValue($tmp, 0, 1);
     $this->_mp3Gain = pow(2, $this->_reader->readInt8() / 4);
     $tmp = $this->_reader->readUInt16BE();
     $this->_surroundInfo = HausDesign_Bit_Twiddling::getValue($tmp, 11, 14);
     $this->_presetUsed = HausDesign_Bit_Twiddling::getValue($tmp, 0, 10);
     $this->_musicLength = $this->_reader->readUInt32BE();
     $this->_musicCrc = $this->_reader->readUInt16BE();
     $this->_crc = $this->_reader->readUInt16BE();
 }