herobrinethree

musictest

Aug 7th, 2022
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. local dfpwm = require("cc.audio.dfpwm")
  2.  
  3. local encoder = dfpwm.make_encoder()
  4. local decoder = dfpwm.make_decoder()
  5.  
  6. local out = fs.open("speedy.dfpwm", "wb")
  7. for input in io.lines("data/example.dfpwm", 16 * 1024 * 2) do
  8. local decoded = decoder(input)
  9. local output = {}
  10.  
  11. -- Read two samples at once and take the average.
  12. for i = 1, #decoded, 2 do
  13. local value_1, value_2 = decoded[i], decoded[i + 1]
  14. output[(i + 1) / 2] = (value_1 + value_2) / 2
  15. end
  16.  
  17. out.write(encoder(output))
  18.  
  19. sleep(0) -- This program takes a while to run, so we need to make sure we yield.
  20. end
  21. out.close()
Add Comment
Please, Sign In to add comment