Beispiel #1
0
 /**
  *
  * @param type $compre
  * @return type
  */
 public static function heavyCompression($compre)
 {
     // The first four bits indicate gain changes in 6.02dB increments which can be
     // implemented with an arithmetic shift operation. The following four bits
     // indicate linear gain changes, and require a 5-bit multiply.
     // We will represent the two 4-bit fields of compr as follows:
     //   X0 X1 X2 X3 . Y4 Y5 Y6 Y7
     // The meaning of the X values is most simply described by considering X to represent a 4-bit
     // signed integer with values from –8 to +7. The gain indicated by X is then (X + 1) * 6.02 dB. The
     // following table shows this in detail.
     // Meaning of 4 msb of compr
     //  7    +48.16 dB
     //  6    +42.14 dB
     //  5    +36.12 dB
     //  4    +30.10 dB
     //  3    +24.08 dB
     //  2    +18.06 dB
     //  1    +12.04 dB
     //  0     +6.02 dB
     // -1         0 dB
     // -2     –6.02 dB
     // -3    –12.04 dB
     // -4    –18.06 dB
     // -5    –24.08 dB
     // -6    –30.10 dB
     // -7    –36.12 dB
     // -8    –42.14 dB
     $fourbit = str_pad(decbin(($compre & 0xf0) >> 4), 4, '0', STR_PAD_LEFT);
     if ($fourbit[0] == '1') {
         $log_gain = -8 + bindec(substr($fourbit, 1));
     } else {
         $log_gain = bindec(substr($fourbit, 1));
     }
     $log_gain = ($log_gain + 1) * GetId3_Lib_Helper::RGADamplitude2dB(2);
     // The value of Y is a linear representation of a gain change of up to –6 dB. Y is considered to
     // be an unsigned fractional integer, with a leading value of 1, or: 0.1 Y4 Y5 Y6 Y7 (base 2). Y can
     // represent values between 0.111112 (or 31/32) and 0.100002 (or 1/2). Thus, Y can represent gain
     // changes from –0.28 dB to –6.02 dB.
     $lin_gain = (16 + ($compre & 0xf)) / 32;
     // The combination of X and Y values allows compr to indicate gain changes from
     //  48.16 – 0.28 = +47.89 dB, to
     // –42.14 – 6.02 = –48.16 dB.
     return $log_gain - $lin_gain;
 }
Beispiel #2
0
 /**
  *
  * @return boolean
  */
 public function CalculateReplayGain()
 {
     if (isset($this->info['replay_gain'])) {
         if (!isset($this->info['replay_gain']['reference_volume'])) {
             $this->info['replay_gain']['reference_volume'] = (double) 89.0;
         }
         if (isset($this->info['replay_gain']['track']['adjustment'])) {
             $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment'];
         }
         if (isset($this->info['replay_gain']['album']['adjustment'])) {
             $this->info['replay_gain']['album']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['album']['adjustment'];
         }
         if (isset($this->info['replay_gain']['track']['peak'])) {
             $this->info['replay_gain']['track']['max_noclip_gain'] = 0 - GetId3_Lib_Helper::RGADamplitude2dB($this->info['replay_gain']['track']['peak']);
         }
         if (isset($this->info['replay_gain']['album']['peak'])) {
             $this->info['replay_gain']['album']['max_noclip_gain'] = 0 - GetId3_Lib_Helper::RGADamplitude2dB($this->info['replay_gain']['album']['peak']);
         }
     }
     return true;
 }