Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Buzz pattern value to volume factor

joachip May 16th, 2020 (edited) 1,512 in 350 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class VolumeHandler
  4. {
  5.     var $curvature = 2.9396385;
  6.     var $buzz_default_value = 0xA000;
  7.     var $buzz_max_value = 0xFFFE;
  8.  
  9.     function ShowPatternToAmp()
  10.     {
  11.         echo "Buzz\tFactor\n\n";
  12.         for ($slider = 0; $slider <= $this->buzz_max_value; $slider += 1024)
  13.         {
  14.             $factor = $this->PatternToAmp($slider);
  15.             printf("%04X\t%.4f\n", $slider, $factor);
  16.         }
  17.     }
  18.  
  19.     function ShowAmpToPattern()
  20.     {
  21.         echo "\n\nFactor\tSlider (going backward)\n\n";
  22.         for ($slider = 0; $slider <= $this->buzz_max_value; $slider += 1024)
  23.         {
  24.             $factor = $this->PatternToAmp($slider);
  25.             $slider_from_factor = $this->AmpToPattern($factor);
  26.             printf("%.4f\t%04X\n", $factor, $slider_from_factor);
  27.         }
  28.     }
  29.  
  30.     function PatternToAmp($pattern_value)
  31.     {
  32.         return pow($pattern_value / $this->buzz_default_value, $this->curvature);
  33.     }
  34.  
  35.     function AmpToPattern($factor)
  36.     {
  37.         return pow($factor, 1/$this->curvature) * $this->buzz_default_value;
  38.     }
  39. }
  40.  
  41.  
  42.  
  43.  
  44.  
  45. header('Content-Type: text/plain');
  46. $vol = new VolumeHandler();
  47. printf("The minimum is at %04X\n", 0);
  48. $zeropoint = round($vol->AmpToPattern(1.000));
  49. $maximum = $vol->PatternToAmp($vol->buzz_max_value);
  50. printf("The 0 dB point is approximately at %04X (%.12f)\n", $zeropoint, $vol->PatternToAmp($zeropoint));
  51. printf("The maximum is factor %.7f (%+.7f dB)\n\n\n", $maximum, 20 * log10($maximum));
  52.  
  53. $vol->ShowPatternToAmp();
  54. $vol->ShowAmpToPattern();
  55.  
  56. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top