Controlling Default Audio Channel

,

error when trying to control the volume of default audio channel

Sound sources not added to a custom channel are added to the global channel.

playdate.sound.channel:addSource(source)

We're able to add effects to the global channel

  sfx.addEffect(delay)

however i get an error when trying to access or control the volume using a similar method.

sfx.getVolume()
sfx.setVolume(0.5)

Advice?

Thanks!


PS - really appreciate anyone who has the time and patience to review this

unexpected behavior when trying to use custom channels.

I think that my instrument is not being removed from the global/default channel when I add it to a custom channel. Just aurally, it sound like the volume is nearly doubled and the tone is different, almost like an FM synth playing unison notes.

  local lead_track = crescent_mill_sequence:getTrackAtIndex(1)
  local lead_synth = sfx.synth.new(sfx.kWavePOVosim)
  local lead_inst = sfx.instrument.new()
  local lead_channel = sfx.channel.new()
  lead_inst:addVoice(lead_synth)
  lead_track:setInstrument(lead_inst)
  lead_channel:addSource(lead_inst)

And even stranger it sounds when I add effects to the custom channel (in addition to the default/global)

  local delay = effect_library.delay
  sfx.addEffect(delay)
  lead_channel:addEffect(delay)

  local bandpass = effect_library.bandpass
  sfx.addEffect(bandpass)
  lead_channel:addEffect(bandpass)

whole project zip

here's a zip of the current state if you'd like to hear the music -
scapia-main-2.zip (283.4 KB)

you'll find the offending line at source/audio_engine/intsruments.lua line 24
comment it in and out to reproduce what I'm describing

Thanks for including the source code; I played around with it for a minute and have some observations which I think will help you.

I think that my instrument is not being removed from the global/default channel when I add it to a custom channel. Just aurally, it sound like the volume is nearly doubled and the tone is different, almost like an FM synth playing unison notes.

This doesn't seem to be the case. If I do this:

  lead_channel:addSource(lead_inst)
  lead_channel:setVolume(0)

...then the track is no longer heard. This means that the default channel isn't playing underneath it-- I think that's just what that instrument sounds like without the bandpass/delay added.

And even stranger it sounds when I add effects to the custom channel (in addition to the default/global)

You weren't kidding! It sounds really weird when you use the code in your example. But it looks like it just comes down to the fact that you are sharing one instance of a playdate.sound.effect with more than one channel. It seems like that makes the effect try to process simultaneous channels in an invalid way. I think Playdate should probably be made to throw an error for this, like it does when trying to assign synths to multiple instruments.

If you do it like this:

  lead_track:setInstrument(lead_inst)
  lead_channel:addSource(lead_inst)

--...

  --sfx.addEffect(delay)  --Don't use 'delay' twice
  lead_channel:addEffect(delay)

--...

  --sfx.addEffect(bandpass)  --Don't use 'bandpass' twice
  lead_channel:addEffect(bandpass)

It sounds perfect. Give it a try and see if it works on your end.

Finally, to address this:

however i get an error when trying to access or control the volume using a similar method.

sfx.getVolume()
sfx.setVolume(0.5)

That's just because there is no function playdate.sound.setVolume() in the API. Using playdate.sound.[channelFunction] isn't actually a shortcut to modify the default audio channel-- playdate.sound.addSource(source) is a specific convenience function included in the API to do only that specific thing.

As you likely already know, you can change the volume of a custom channel such as lead_channel with

  lead_channel:setVolume(vol)

I'm not sure if there is a way to get a reference to the default channel to set its volume this way. I'm not really sure the default channel's volume is even intended to be modifiable... For now, I would suggest using custom channels whenever you plan to change a channel's volume.

By the way, I enjoyed the mood of the song that plays in your project. Makes me think of bedtime.

3 Likes

THANK YOU!!!

Embarrassing that I was so wrong about the two-instances of the channel; thank you for the correction and proof.

And yeah, im making more and separate effects for each channel now, based on your advice.

I may come back and say more later when I have a chance to implement this stuff, but just off the first read: I appreciate you taking the time homie. I really do! Such complete answers. And I'm really happy you liked the music, that sleep-like comment has me thinking of where it should go in the game.

1 Like