Midi On messages (only) to Ableton instruments causing clicks/pops


#1

I don’t think the specifics of my project are important but basically it’s a midi effect plugin (a sequencer) that periodically sends noteOn messages that can be routed to another midi instrument track.

So for example, in my processing block, inside the loops and math and stuff, we might end up with something like

midiMessages.addEvent(MidiMessage::noteOn(1, 60, (uint8) 96), 0);

Is there any obvious reason a message like that would cause consistent clicks/pops or is it perhaps something inefficient happening in my code?


#2

As a general advice, since other projects don’t show that behaviour, it’s exactly the specifics of your project, that matter :wink:

It is easiest to help, if you could provide a minimal example of code, that shows the behaviour you are describing. People might be able to guess, but guessing is not engineering.

But since you ask for guesses, I can’t see how adding an event could create clicks/pops in the audio buffer.

Can you show a little bit more of your code, e.g. the processBlock method, or the renderNextBlock of the synthesizer (if you use any)…


#3

Gotcha! Yeah I just figured I was misunderstanding something basic but no problem, he’s my processBlock so far and I tried to comment what is happening. There’s no synthesizer. My guess is that it has something to do with the fact that I’m updating a Juce Value called playPosition that has a listener in my processBlock so that I can draw one of those moving vertical play lines in the gui. But I’m not updating it every time because I know that’s inefficient.


#4

Please for future posts, copy the code into the editor, rather than posting a screenshot. If I wanted to refer to a snippet in your code, you make the people, that want to help, re-type your code.
If you surround your code with three backticks, it will be formatted correctly, like

    ```
    // your code goes here
    int foo (AudioBuffer<float>& buffer, MidiBuffer& midi)
    // ...
    ```

Since you are not creating any samples, but crackling comes from samples, I would assume the problem is somewhere else.
A possible scenario, you are sending lots of noteOn, but no noteOff, so your instrument you are feeding the midi to is constantly stealing voices… depending on the quality of the synth, this might create the crackles…


#5

“Please for future posts, copy the code into the editor…”
For sure!

“A possible scenario, you are sending lots of noteOn, but no noteOff, so your instrument you are feeding the midi to is constantly stealing voices… depending on the quality of the synth, this might create the crackles…”
Good point, I’m going to explore this and report back. Thanks.


#6

One of your comments suggests that you are adding MIDI events to midiStream from the GUI. Are you doing this in a lock-free way or is your gui directly accessing the midiStream Array?

If the gui is accessing it directly then I suspect this is where the problem lies!


#7

Yeah honestly it looks like that was just behavior for that one instrument. Every other instrument seems to work fine. My apologies for not trying other instruments first but I at least I learned a bit about Juce forum protocol :wink:


#8

I was able to fix the problem but I didn’t go out of my way to make sure it was lock free. If the processor simply detects if the Array size is greater than 0, then, if so, takes and removes an element from it, isn’t that safe? Would that be considered lock-free?


#9

Well I guess it would be lock-free, but if you’ve got two different threads accessing the underlying data then you’ll have a race condition, which is undefined behaviour and cause all kinds of problems. You can pass in a CriticalSection as a template parameter, but that would use locks so must be avoided on the audio thread. For something like this you will probably want to use some kind of FIFO. Have a look at the AbstractFIFO class for info on how to implement one.


#10

This might be a little over my head but I’m reading through it and I’ll see if I can incorporate it. As I’m getting deeper into this project, those pops and clicks are creeping in again so I may due well to understand this. I’ll also try incorporating midi off messages like Daniel suggested.