Lanzr

auplay.lua

Oct 28th, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. local aukit = require "aukit"
  2. local speaker = peripheral.find "speaker"
  3.  
  4. local path = shell.resolve(...)
  5. local file = fs.open(path, "rb")
  6. local data = file.readAll()
  7. file.close()
  8.  
  9. print("Loading file...")
  10. local audio
  11. if path:match("%.dfpwm$") then audio = aukit.dfpwm(data, 1, 48000)
  12. elseif path:match("%.wav$") then audio = aukit.wav(data)
  13. elseif path:match("%.aiff?$") then audio = aukit.aiff(data)
  14. elseif path:match("%.au$") then audio = aukit.au(data)
  15. elseif path:match("%.flac$") then audio = aukit.flac(data)
  16. else error("Unknown file type!") end
  17. sleep(0)
  18.  
  19. print("Resampling...")
  20. local resamp = audio:resample(48000)
  21. sleep(0)
  22. print("Converting to mono...")
  23. local mono = resamp:mono()
  24. sleep(0)
  25. print("Normalizing...")
  26. aukit.effects.normalize(mono, 0.8)
  27. sleep(0)
  28. print("Applying filter...")
  29. aukit.effects.lowpass(mono, audio.sampleRate / 2)
  30. sleep(0)
  31.  
  32. print("Playing.")
  33. aukit.play(mono:stream(48000), speaker)
Add Comment
Please, Sign In to add comment