noteOff() does nothing

I have some simple C code that is supposed to play a synth when A is pushed, then stop playing it when A is released.

//First, in eventHandler()
	synth = pd->sound->synth->newSynth();
	pd->sound->synth->setWaveform(synth, kWaveformSquare);

//Later, in update()
	if (pressed & kButtonA) {
		playingSound = 1;
		pd->sound->synth->playNote(synth, noteFreq, 1.0, -1.0, 0);
	} else if (released & kButtonA) {
		playingSound = 0;
		pd->sound->synth->noteOff(synth, 0);
		if (pd->sound->synth->isPlaying(synth)) {
			pd->system->logToConsole("Yep, still playing.");

The problem is that noteOff() does not stop the sound. The message "Yep, still playing." always appears when taking the button released code path. The issue is reproducible both in the simulator and on real hardware.

isPlaying() will continue to return 1 while the release section of the synth's envelope plays out, and we have a minimum 5 ms release to avoid popping. Aside from the isPlaying() check, do you hear it stop playing?

The audio continues to play indefinitely, in other words the noteOff() call does nothing. The isPlaying() check was just me trying to get more visibility

Got it, thanks! Looks like the problem is it's not respecting "when=0 means now" as described in the docs. I have a fix in the queue; until then, here's a workaround:

pd->sound->synth->noteOff(synth, pd->sound->getCurrentTime());

Thanks for catching this! I'm really surprised that's been hiding in there for so long.

No problem. Thanks for the prompt response.

1 Like