Channels and Sound

How can I use playdate.sound.channel?

I've added an affect and pan, and also a source but when I play the source synth I can't hear the affect or pan.

On windows:

gfx = playdate.graphics

-- synth/source
sawtooth = playdate.sound.synth.new(playdate.sound.kWaveSawtooth)
sawtooth:setADSR(0.5, 0.5, 0.5, 0.5)
sawtooth2 = playdate.sound.synth.new(playdate.sound.kWaveSawtooth)
sawtooth2:setADSR(0.5, 0.5, 0.5, 0.5)

list = {}

list[1] = { note=49, step=1, length=4, velocity=1 }
-- list[2] = { note=64, step=2, length=2, velocity=1 }
-- list[3] = { note=67, step=4, length=2, velocity=1 }

-- track
trx = playdate.sound.track.new()
--trx:addNote(1, 60, 1)
trx:setNotes(list)
trx:setInstrument(sawtooth)

-- sequence
seq = playdate.sound.sequence.new()
seq:addTrack(trx)
seq:setTempo(4)

-- effect
bitcrush = playdate.sound.bitcrusher.new()

-- channel
chan = playdate.sound.channel.new()
chan:addEffect(bitcrush)
chan:addSource(sawtooth)
chan:setPan(1)

Bdown = false
Adown = false

function playdate.update()
gfx.clear()

if Bdown then sawtooth2:playNote('Db3') 
	gfx.drawText("B Pushed", 20,20)
end
if not Bdown then sawtooth2:noteOff() end

if Adown then seq:play() 
	gfx.drawText("A Pushed", 20,50)
end
if not Adown then seq:stop() end

end

function playdate.BButtonDown()
if Bdown == true then Bdown = false
elseif Bdown == false then Bdown = true end
end

function playdate.AButtonDown()
if Adown == true then Adown = false
elseif Adown == false then Adown = true end
end

There's some unexpected stuff going on under the hood here that I need to fix. What's happening is trx:setInstrument(sawtooth) creates a playdate.sound.instrument under the hood and adds the sawtooth synth to it, and that's what's making the sound, not the synth. Since it wasn't assigned to chan it plays on the default channel and doesn't get panned or bitcrushed. If instead of trx:setInstrument(sawtooth) you do

inst = playdate.sound.instrument.new(sawtooth)
trx:setInstrument(inst)

and add inst to the channel instead of sawtooth it'll work as expected. Well, almost: The bitcrusher effect's amount parameter defaults to 0, so you'll have to crank that up a bit to hear it do anything. 1.0 is too much, it completely flattens the waveform, but 0.9 is good.

I'm not sure yet how I'll fix this, but it should work like you expected it to. Thanks for pointing this out!

1 Like

That’s a huge help. Thanks Dave!

Using playdate.sound.instrument seems like a better option anyways.