Added notificaiton sound

This commit is contained in:
2025-12-12 15:52:18 -05:00
parent 4e6b83a456
commit e77752efae
5 changed files with 74 additions and 2 deletions

56
speaker-driver.lua Normal file
View File

@@ -0,0 +1,56 @@
local speaker = peripheral.find("speaker")
local dfpwm = require("cc.audio.dfpwm")
local kernel = require("kernel")
local sounds = {
{name = "notification", file = "notification.dfpwm"}
}
local function initialize()
kernel.addSound("notification")
speaker = peripheral.find("speaker")
if not speaker then
print("Warning: No speaker attached.")
return false
end
return true
end
local function play(name)
if not speaker then return false end
local filePath
for _, sound in ipairs(sounds) do
if sound.name == name then
filePath = sound.file
break
end
end
if not filePath then
print("Sound '" .. name .. "' not defined.")
return false
end
if not fs.exists(filePath) then
print("File '" .. filePath .. "' not found.")
return false
end
-- Create a new decoder for this playback to reset state
local decoder = dfpwm.make_decoder()
for chunk in io.lines(filePath, 16 * 1024) do
local buffer = decoder(chunk)
while not speaker.playAudio(buffer) do
os.pullEvent("speaker_audio_empty")
end
end
return true
end
return { initialize = initialize, play = play }