Skip to content

Sound card plays the modulator channel after set to modulate multiple channels #328

@Fingercomp

Description

@Fingercomp

Code to reproduce the issue:

local s = require("component").sound

s.setWave(1, s.modes.square)
s.setWave(3, s.modes.sine)

s.setFrequency(1, 440)
s.setFrequency(3, 220)

s.setVolume(1, 1)
s.setVolume(3, 1)

s.setTotalVolume(1)

s.setFM(1, 3, 220)
-- ch3 now modulates ch1

s.open(1)
s.open(3)
s.delay(1000)

s.setFM(2, 3, 220)
-- ch3 now modulates both ch1 and ch2
s.resetFM(2)
-- the modulator for ch2 is now removed
-- ch3 should only be modulating ch1

s.delay(1000)
-- expected behavior: no change is observed
-- actual behavior: the sound clearly changes

s.close(1)
s.close(3)

s.process()

As far as I understand, whether a channel is mixed into the output is controlled by the isFreqMod and isAmpMod flags. They are set when the channel is set as a modulator for another channel and reset when the modulation is removed. In the code above, channel 3 is modulating two channels. The modulation of one of the carrier channels is then removed, which resets the isFreqMod flag even though the first channel still has the channel 3 set as its modulator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions