Crash: synths may only be in one instrument or channel at a time

Crash happens on both Simulator and Device

I'm doing this

local track= {}
local synth= {}
local wave = {}
local waveString = {}
local instrument= {}
local pitch={}
local volume={}
local attack= {}
local decay= {}
local sustain={}
local release={}

function setSynth(s,w)  
  if w==1 then s:setWaveform(playdate.sound.kWaveSine)  end
  if w==2 then s:setWaveform(playdate.sound.kWaveSquare) end
  if w==3 then s:setWaveform(playdate.sound.kWaveSawtooth) end
  if w==4 then s:setWaveform(playdate.sound.kWaveTriangle) end
  if w==5 then s:setWaveform(playdate.sound.kWaveNoise) end 
end

function waveText(w)
  if w==1 then  ws="SINE" end
  if w==2 then  ws="SQUARE" end
  if w==3 then  ws="SAW" end
  if w==4 then  ws="TRI" end
  if w==5 then  ws="NOISE" end 
  return ws
end

for i=1,4 do
  track[i]=snd.track.new()
  sequence:addTrack(track[i])
  synth[i]=snd.synth.new()
  wave[i]=i
  waveString[i]= waveText(wave[i])
  setSynth(synth[i],wave[i])  
  instrument[i]=snd.instrument.new(synth[i])
  track[i]:setInstrument(instrument[i]) -- THIS ONE GETS THE ERROR
  synth[i]:setADSR(0, 0.1, 0.1, 0.2)
  pitch[i]=700
  volume[i]=0.25
  attack[i]= 0.05
  decay[i]= 0.12
  sustain[i]=0.1
  release[i]=0.14
end  

This one is where it crashes and it worked before for sure

track[i]:setInstrument(instrument[i])

There was no issue on 1.13.0, not sure about 1.13.1

Didn't see anything in changelog

The problem is a bug (introduced in 1.13.0, I think) is causing snd.instrument.new(synth) to return the synth, not the instrument. You can work around this by doing the old style

instrument[i]=snd.instrument.new()
instrument[i]:addVoice(synth[i])

Thanks for catching this! It's filed and I'll get a fix in the queue as soon as we can get the current backlog flushed out.

1 Like