I’m a pretty new programmer, but I have a question about audio clicks.
I’m hearing some audio clicks in my plugin, and I was curious about some reasons why clicking would happen.
To my understanding, clicks can occur on edge conditions for a circular buffer. For example, let’s say you have a delay buffer 10 samples long. At this moment, the circular buffer’s pointer is at the 9th position. You write your current sample to buffer then you increment your bufferIndex (now at the 10th position, which doesn’t exist). Then you have to check in your code if your buffer if the writeIndex and the bufferSize relationship is in bounds:
if (m_nLeftWriteIndex > m_nLeftBufferSize) m_nLeftWriteIndex = m_nLeftWriteIndex - m_nLeftBufferSize; // checking if buffer sample is in bounds
When I originally wrote the code is used the “>” symbol instead of the “>=” and I heard clicks because I was writing to the buffer at the 10th which doesn’t exist.
Why does this click occur? Here are my guesses/questions I have:
- There’s a big discontinuity the between the buffer at the 9th position and buffer at the 0th position. The physical speaker can’t respond to the discontinuity change so fast that it clicks?
- When the program tries to write to the buffer at the 10th position, why doesn’t the program crash? It’s trying to access memory outside array’s location where it’s undefined; it should crash. Is the click basically a “small crash”?
Also, when do other common clicks occur? It would help me prevent some coding pitfalls.