Guest User

Roland LP sample decoding

a guest
Dec 8th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. stream_sample_t rolandpcm_device::decode_sample(int8_t data)
  2. {
  3.     int16_t val;
  4.     int16_t sign;
  5.     uint8_t shift;
  6.     stream_sample_t result;
  7.    
  8.     if (data < 0)
  9.     {
  10.         sign = -1;
  11.         val = -data;
  12.     }
  13.     else
  14.     {
  15.         sign = +1;
  16.         val = data;
  17.     }
  18.    
  19.     // thanks to Sarayan for figuring out the decoding formula
  20.     shift = val >> 4;
  21.     val &= 0x0F;
  22.     if (! shift)
  23.         result = val;
  24.     else
  25.         result = (0x10 + val) << (shift - 1);
  26.     return result * sign;
  27. }
Add Comment
Please, Sign In to add comment