ComputerCraft Forums

ComputerCraft => Programs => Topic started by: jupilogy on Jan 22, 2025, 09:41 PM

Title: Making music in computercraft (cbat)
Post by: jupilogy on Jan 22, 2025, 09:41 PM
I wanted to entertain and surprise my friends so I programmed the computer to play cbat using minecraft native sounds on infinite loop.

This does not require downloading any songs and is quite small. It's also quite stupid and seems to lag sometimes. The programs you have all made are fantastic and this was just my first idea of what to do when given access to the computercraft computer.

tempo = 0.2
snote = 8
ins = "didgeridoo"
speaker=peripheral.find("speaker")
round=0
while(true)
do
  speaker.playNote("snare",1,16)
  speaker.playNote(ins,1,snote+8)
  sleep(tempo) --1
  sleep(tempo) --2
  speaker.playNote(ins,1,snote+9)
  sleep(tempo) --3
  speaker.playNote(ins,1,snote+7)
  speaker.playNote("snare",1,16)
  sleep(tempo) --4
  speaker.playNote("snare",1,16)
  sleep(tempo) --5
  sleep(tempo) --6
  speaker.playNote(ins,1,snote+8)
  speaker.playNote("snare",1,16)
  sleep(tempo) --7
  sleep(tempo) --8

  -- bar 2
  speaker.playNote(ins,1,snote+6)
  sleep(tempo) --1
  speaker.playNote(ins,1,snote+6)
  speaker.playNote("snare",1,16)
  sleep(tempo) --2
  speaker.playNote(ins,1,snote+6)
  speaker.playNote("snare",1,16)
  sleep(tempo) --3
  sleep(tempo) --4
  speaker.playNote(ins,1,snote+5)
  speaker.playNote("snare",1,16)
  sleep(tempo) --5
  sleep(tempo) --6
  sleep(tempo) --7
  sleep(tempo) --8

  if round==1 then
    snote= snote+2
    round = 0
  else
    round=1
    snote= snote-2
  end
end

Enjoy it, enjoy hating it, whatever. I hope this isn't too low quality for the forum.