Created
April 19, 2017 20:56
-
-
Save gamax92/e460f761ab6e6c5391e45bb9058cbfd0 to your computer and use it in GitHub Desktop.
Siren noise using Computronics sound card
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local component = require("component") | |
local soundcard = require("soundcard") | |
if not component.isAvailable("sound") then | |
print("Error: Requires a Computronics Sound Card") | |
return | |
end | |
local sound = soundcard.wrap(component.sound, 100) | |
local freq={475,570} | |
local vol={0.2,0.5} | |
for i=3,4 do | |
freq[i]=freq[i-2]*2 | |
vol[i]=vol[i-2]/2 | |
end | |
local unit=10 | |
for i=1, 8 do | |
sound.setWave(i, sound.modes.triangle) | |
end | |
for i=1, 4 do | |
sound.open(i) | |
sound.open(i+4) | |
sound.setVolume(i, vol[i]) | |
sound.setVolume(i+4, vol[i]) | |
end | |
for j=0, 1, 1/3000*unit do | |
local j1=(j^0.5)*0.5+0.5 | |
for i=1, 4 do | |
sound.setFrequency(i, freq[i]*j1) | |
sound.setFrequency(i+4, math.max(freq[i]*j1-math.random(0, 50), 1)) | |
end | |
sound.delay(unit) | |
end | |
while true do | |
for i=1, 4 do | |
sound.setFrequency(i, freq[i]) | |
end | |
for j=0, 3000, unit do | |
for i=1, 4 do | |
sound.setFrequency(i+4, freq[i]+math.random(-25, 25)) | |
end | |
sound.delay(unit) | |
end | |
for j=1, 0, -1/3000*unit do | |
local j1=(j^0.75)*0.25+0.75 | |
for i=1, 4 do | |
sound.setFrequency(i, freq[i]*j1) | |
sound.setFrequency(i+4, math.min(freq[i]*j1+math.random(0, 50), freq[i])) | |
end | |
sound.delay(unit) | |
end | |
for j=0, 1, 1/2000*unit do | |
local j1=(j^0.5)*0.25+0.75 | |
for i=1, 4 do | |
sound.setFrequency(i, freq[i]*j1) | |
sound.setFrequency(i+4, math.max(freq[i]*j1-math.random(0, 50), freq[i]*0.75)) | |
end | |
sound.delay(unit) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment