Beispiel #1
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);
 }
Beispiel #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);
     $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();
 }