Skip to content

Instantly share code, notes, and snippets.

@MineRobber9000
Created November 19, 2022 06:19
Show Gist options
  • Save MineRobber9000/7289a6f1e0749d157f5bb3c1a844eced to your computer and use it in GitHub Desktop.
Save MineRobber9000/7289a6f1e0749d157f5bb3c1a844eced to your computer and use it in GitHub Desktop.
Floppy Rockers! A system for ComputerCraft drag-and-drop audio playing
-- Floppy Rocker
-- by MineRobber___T
-- Requires aukit and an attached speaker
if not package.path:find("lib/?") then package.path=package.path..";lib/?;lib/?.lua;lib/?/init.lua" end
if not pcall(require,"aukit") then error"Requires aukit" end
local aukit=package.loaded.aukit
local fs=fs
local peripheral=peripheral
if _HOST:find("Recrafted") then -- nobody's gonna use this, let alone someone using Recrafted, but just in case
fs=require"fs"
peripheral=require"peripheral"
end
local speaker=peripheral.find"speaker"
if not speaker then error"Requires speaker" end
local disk=...
local filedata=""
if disk then
error"NYI"
else
print("Drag and drop a .fr file onto the screen.")
local ev, files = os.pullEvent("file_transfer")
local files=files.getFiles()
if #files>1 then error"Multiple-file drops are not supported at this time." end
local file=files[1]
write("Loading "..file.getName().."... ")
filedata=file.readAll()
print("success!")
end
local version, divider = string.unpack("BB",filedata)
local sounddata = filedata:sub(3)
print("Loading audio data... (this might take a while)")
local audio = aukit.dfpwm(sounddata,1,48000/divider)
print(tostring(audio))
audio=audio:resample(48000)
print("Loaded!")
aukit.play(audio:stream(48000),speaker)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment