Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local comp = require('component')
- local snd = comp.sound
- local tap = comp.tape_drive
- local no = require('note')
- local thrd = require('thread')
- local tbl = require('table')
- local commsize = 2
- local channs = 1
- local channadsr = {{[1]=0,[2]=0,[3]=0,[4]=0,['chg']=false},
- {[1]=0,[2]=0,[3]=0,[4]=0,['chg']=false},
- {[1]=0,[2]=0,[3]=0,[4]=0,['chg']=false},
- {[1]=0,[2]=0,[3]=0,[4]=0,['chg']=false},
- {[1]=0,[2]=0,[3]=0,[4]=0,['chg']=false},
- {[1]=0,[2]=0,[3]=0,[4]=0,['chg']=false},
- {[1]=0,[2]=0,[3]=0,[4]=0,['chg']=false},
- {[1]=0,[2]=0,[3]=0,[4]=0,['chg']=false}}
- function setChanns(chn)
- channs = chn
- end
- function rnoteplay(midn, chn)
- if channadsr[chn].chg then
- channadsr[chn].chg = false
- local adsr = channadsr[chn]
- snd.setADSR(adsr[1], adsr[2], adsr[3], adsr[4])
- end
- snd.open(chn)
- snd.setFrequency(chn, note.freq(midn))
- end
- function nnoteplay(midn, chn)
- snd.setFrequency(chn, note.freq(midn))
- end
- function noterel(chn)
- snd.close(chn)
- end
- function volume(vol, chn)
- snd.setVolume(chn, (vol / 255)*0.2)
- end
- function sattack(att, chn)
- channadsr[chn][1] = att * 8
- channadsr[chn].chg = true
- end
- function sdelay(del, chn)
- channadsr[chn][2] = del * 8
- channadsr[chn].chg = true
- end
- function ssustain(sus, chn)
- channadsr[chn][3] = (sus / 255)*0.2
- channadsr[chn].chg = true
- end
- function srelease(rel, chn)
- channadsr[chn][4] = rel * 8
- channadsr[chn].chg = true
- end
- tap.seek(-(tap.getSize()))
- local tapesize = string.unpack("<I4", tap.read(4))
- function TICK()
- snd.delay(50)
- snd.process()
- os.sleep(0.05)
- end
- local currChan = 1
- local tickwait = 1
- function decComm(bytecomm, data)
- if bytecomm == 254 then
- setChanns(data)
- currChan = 1
- elseif bytecomm == 100 then
- tickwait = data
- currChan = 1
- elseif bytecomm == 130 then
- sattack(data, currChan)
- elseif bytecomm == 131 then
- sdelay(data, currChan)
- elseif bytecomm == 132 then
- ssustain(data, currChan)
- elseif bytecomm == 133 then
- srelease(data, currChan)
- elseif bytecomm == 155 then
- volume(data, currChan)
- elseif bytecomm == 2 then
- rnoteplay(data, currChan)
- elseif bytecomm == 3 then
- nnoteplay(data, currChan)
- elseif bytecomm == 4 then
- noterel(currChan)
- elseif bytecomm == 0 then
- local linesize = commsize * channs
- tap.seek(-(linesize * data))
- end
- end
- print("OK, starting")
- local tickstowait = 1
- while true do
- tickstowait = tickstowait - 1
- local tick = thrd.create(TICK)
- if tickstowait <= 0 then
- while currChan <= channs do
- local co, coval = tap.read(2)
- --local comma = string.unpack("<B", co)
- --local comval = string.unpack("<I1", coval)
- decComm(co, coval)
- currChan = currChan + 1
- end
- tickstowait = tickwait
- end
- currChan = 1
- thrd.waitForAll(tick)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement