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

View File

@@ -4,11 +4,14 @@ local monitor = kernel.addDriver("monitor-driver")
local data = kernel.addDriver("disk-driver")
local chat = kernel.addProgram("chat")
local gps = kernel.addProgram("gps")
local speaker = kernel.addProgram("speaker-driver")
local function run()
monitor.initialize()
data.initialize()
speaker.initialize()
monitor.writeLine("Starting system...")
monitor.writeLine("System started successfully!")
computerName = data.getRead("computer-name")

View File

@@ -30,6 +30,17 @@ local function addProgram(fileName)
return require(fileName)
end
local function addSound(fileName)
local extension = ".dfpwm"
local fullFile = fileName .. extension
shell.execute("rm", fullFile)
local baseRoute = "https://git.astrocore.space/root/nova-corp/raw/branch/main/"
shell.execute("wget", baseRoute .. "sounds" .. "/" .. fullFile)
sleep(2)
return require(fileName)
end
addDriver("task-manager")
return { addDriver = addDriver, addFolderDriver = addFolderDriver, addProgram = addProgram }
return { addDriver = addDriver, addFolderDriver = addFolderDriver, addProgram = addProgram, addSound = addSound }

View File

@@ -1,5 +1,6 @@
local modem = peripheral.find("modem")
local PORT = 1
local speaker = require("speaker")
local function start()
if modem then
@@ -30,6 +31,7 @@ local function receiveLoop()
term.setCursorPos(1, y)
term.clearLine()
print("Received: " .. tostring(message))
speaker.play("notification")
write("> ")
end
end

BIN
sounds/notification.dfpwm Normal file

Binary file not shown.

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 }