Skip to content

Commit

Permalink
Fix sound card volume level between process calls
Browse files Browse the repository at this point in the history
  • Loading branch information
zenith391 committed Dec 12, 2021
1 parent ff555cc commit 5750436
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/component/sound_card.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ local function checkChannel(n, index)
compCheckArg(n, index, "number")
index = math.floor(index)
if index < 1 or index > 8 then
error("invalid channel: " .. tostring(index))
error("invalid channel: " .. tostring(index), 2)
end
return index
end
Expand Down Expand Up @@ -107,7 +107,7 @@ function obj.setVolume(channel, volume)
cprint("sound.setVolume", channel, volume)
compCheckArg(2, volume, "number")
if volume < 0 or volume > 1 then
error("invalid volume: " .. tostring(volume))
error("invalid volume: " .. tostring(volume), 2)
end
channels[checkChannel(1, channel)].volume = volume
end
Expand Down Expand Up @@ -226,8 +226,9 @@ function obj.process()
delayQueue = {}
delayTime = 0
for _, channel in pairs(channels) do
channel.adsrStart = -delayTime
channel.adsrStartSet = false
if not channel.adsrStart then channel.adsrStart = 0 end
channel.adsrStart = channel.adsrStart - processTime
--channel.adsrStartSet = false
end
produceSound()
return true
Expand All @@ -246,7 +247,7 @@ mai.delay = {direct = true, doc = "function(duration:number); Instruction; Adds
function obj.delay(duration)
cprint("sound.delay", duration)
if duration < 0 or duration > 8000 then
error("invalid duration")
error("invalid duration: " .. tostring(duration), 2)
end
local delayEntry = {}
for k, channel in pairs(channels) do
Expand Down Expand Up @@ -281,7 +282,8 @@ function obj.setFrequency(channel, frequency)
compCheckArg(2, frequency, "number")

channels[channel].frequency = frequency
channels[channel].adsrStart = nil
channels[channel].adsrStart = delayTime
channels[channel].adsrStartSet = true
end

table.insert(machineTickHandlers, produceSound)
Expand Down

0 comments on commit 5750436

Please sign in to comment.