playAudio() and playNote() do not play well together
-
I encountered this, when using
playAudio()
andplayNote()
on the same channel:
a) If you useplayAudio()
first, the first call toplayNote()
afterwards does not play anything, but the second call works again.
b) If you useplayNote()
first, theplayAudio()
call is played, using the ADSR setting (I assume) from theplayNote()
command: in my example below, it fades in and out very quickly before the sample could be played to the end. The workaround is usingsetADSR()
manually to adjust the channel again. But because there is no "reset" parameter forsetADSR()
, you would have to use parameters that fit your sample speed. So, better not useplayAudio()
on the same channel after aplayNote()
.Examples:
This just plays the sample one time by fading it in and out quickly and cutting it before it plays to the end:
This shows how the sample is not played properly after theplayNote()
commandf = 390 v = 0.5 p = 0.5 ch = 0 w = 0 l = 2 s = 1 sample = loadAudio("David Silvera/jingle_level_complete_03") print("Start playing...") print() playNote(ch, w, f, v, l, p) // does not matter how much time passes here playAudio(ch, sample, v, p, s, 2) // should play the sample 3 times but plays it only once, with a quick fade in and out sleep(10)
This plays nothing:
playAudio(ch, sample, v, p, s, 2) // does not matter how much time passes here playNote(ch, w, f, v, l, p) sleep(10)
Workaround to make playNote() work again after playAudio() (on the same channel):
playAudio(ch, sample, v, p, s, 2) sleep(5) // plays the sample twice and the 3rd time it is aborted, what is ok playNote(ch, w, f, v, l, p) // but this tone is never heard sleep(10) // in praxis you can apply a very small value, like 0.01 instead of 10, but maybe this depends on the note length playNote(ch, w, f, v, l, p) // this tone is fine again
So, no worries, if you don't switch on the same channel between playing music and playing samples.
Hope this was useful.
-
I have noticed this too, but forgot to report it. It would be great to have this fixed.
-
I'm not quite sure I understand the workaround? Are the sleeps necessary, or is it just that you need to insert an extra playNote after playAudio before playNote starts to work again?
-
You don't need that long sleeps, most important is the extra
playNote()
, but you have to wait at least a little bit of time, I think I triedsleep(0.01)
and it worked already. -
Thank you for the report and for the examples! I've logged the issue.