Being able to play sound files with the speakers.
Kolterdyx opened this issue ยท 4 comments
Since this mod has effectively a real file system, any real file can be accessed from the cc computer if it is in its directory. We can read binary data, and we can use the speaker peripheral to use the minecraft sound system to reproduce any audio file from any mod.
Wouldn't it be a nice addition if we could also play audio files from the computer's filesystem? The files can be downloaded from somewhere via wget
, for example, and they could be played with the speaker peripheral's function playSound
, or even with a new playFile
function.
As to audio formats, it should at least support MP3 (the most common format) and OGG (the format used by minecraft by default)
I think using dfpwm (or similar) would be better, because Computronics used it for tape drives, and it takes up less space, at the cost of very high compression, but this is Minecraft after all. You don't want a one minute song taking up an entire computer's worth of space.
You don't want a one minute song taking up an entire computer's worth of space.
Maybe not, but a four minute song definitely does. Last song I converted ('Yes Sir, I Can Boogie') which clocks in at 4:31 takes 1.1Mb once converted - just over the limit. Still better than the the 4MB mp3 though.
That said, dfpwm is definitely preferable here. However, I do think you'd need a way to stream audio to the speaker, so you can play audio from multiple disks or the internet.
As a more concrete API proposal, I guess I'm thinking something like speaker.playAudio(data: str)
. This accepts a blob of DFPWM data, which is streamed to the client. Once the buffer is cleared, we fire a need_audio
event and the computer should call playAudio
again.
As an example, you'd do something like this:
local speaker = peripheral.find("speaker")
local file = fs.open("my_file.dfpwm", "rb")
while true do
local bytes = file.read(16384)
if not bytes then return end
speaker.playAudio(bytes)
-- Alternatively, make playAudio block until its buffer is empty, meaning
-- we can drop this line.
repeat local _, name = os.pullEvent("need_audio") until name == peripheral.getName(speaker)
end
I don't know. I like it because it's powerful (would make for very easy streaming of audio over websockets), but maybe a little too complicated for CC? Maybe we should just go full computronics sound card :D:.