PDSynthInstrument's playNote / playMIDINote doesn't work when passing a non-zero value for 'when'

I found another audio related bug.

The following code to play a note one second in the future using PDSynth works as expected:

AudioSample *sample = pd->sound->sample->load("audio/something.wav");
PDSynth *synth = pd->sound->synth->newSynth();
pd->sound->synth->setSample(synth, sample, 0, 0);
pd->sound->channel->addSource(pd->sound->getDefaultChannel(), (SoundSource *)synth);
pd->sound->synth->playMIDINote(synth, NOTE_C4, 0.5, 1.0, pd->sound->getCurrentTime() + 44100);

(Replace the path to the sample with whatever you want. I don't think it matters what it is.)

However attempting the same with PDSynthInstrument doesn't play anything:

AudioSample *sample = pd->sound->sample->load("audio/something.wav");
PDSynth *synth = pd->sound->synth->newSynth();
pd->sound->synth->setSample(synth, sample, 0, 0);
PDSynthInstrument *inst = pd->sound->instrument->newInstrument();
pd->sound->instrument->addVoice(inst, synth, 0, 128, 0);
pd->sound->channel->addSource(pd->sound->getDefaultChannel(), (SoundSource *)inst);
pd->sound->instrument->playMIDINote(inst, NOTE_C4, 0.5, 1.0, pd->sound->getCurrentTime() + 44100);

It does play something if you pass 0 as the final parameter to playMIDINote , though.

Thanks for catching this! The bug is that the instrument sees the voice isn't active and thinks that it's stopped playing, so it marks it as done even though it never started. I've got a (one-line) fix in the queue, scheduled it for the next update. :slight_smile:

1 Like