Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Volume slider logic

joachip May 16th, 2020 (edited) 1,284 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 $headroom = 3.9810717055349725077025230508775204348767703729738044;
  6.     var $curvature = 2.9395621565;
  7.     var $buzz_max_value = 65534;
  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_max_value, $this->curvature) * $this->headroom;
  33.     }
  34.  
  35.     function AmpToPattern($factor)
  36.     {
  37.         return pow($factor / $this->headroom, 1/$this->curvature) * $this->buzz_max_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. printf("The 0 dB point is approximately at %04X (%.12f)\n", $zeropoint, $vol->PatternToAmp($zeropoint));
  50. printf("The maximum is at %04X\n\n\n", $vol->AmpToPattern($vol->headroom));
  51.  
  52. $vol->ShowPatternToAmp();
  53. $vol->ShowAmpToPattern();
  54.  
  55. ?>
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