# Sound buffer having crack/pop sounds when trying to make voice chat

**URL:** <https://qa.fmod.com/t/sound-buffer-having-crack-pop-sounds-when-trying-to-make-voice-chat/19734>\
**Category:** FMOD Engine\
**Tags:** cpp\
**Created:** [January 13, 2023, 11:33am UTC](https://qa.fmod.com/t/sound-buffer-having-crack-pop-sounds-when-trying-to-make-voice-chat/19734 "2023-01-13T11:33:00Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [January 16, 2023, 10:22pm UTC](https://qa.fmod.com/t/sound-buffer-having-crack-pop-sounds-when-trying-to-make-voice-chat/19734/2 "2023-01-16T22:22:56Z")

</div>

So `AddVoiceData` is being called every time new samples become available from Steam? If this is the case, then the reason for the crackling and pops would be due to short gaps of time between `AddVoiceData` calls when the `FMOD::Sound` has finished playing and there are no more samples to play, so it outputs silence. This is could loosely be described as “buffer starvation”, and the way to avoid it is to do three things:

1. Rather than playing a new `FMOD::Sound` every time samples become available, use `AddVoiceData` to write your samples to an intermediate [ring buffer](https://soundprogramming.net/programming/creating-a-ring-buffer/), then in your `Update` loop read from the buffer and add it to your `FMOD::Sound` using `Sound::lock`/`Sound::unlock`. This will ensure samples are being given to the `FMOD::Sound` without any gaps.
2. Introduce some latency to give yourself a little more time for samples to become available. You can do this by waiting for the write position of your buffer to reach some value before starting to read from it and filling your `FMOD::Sound`.
3. Keep track of the distance between your read and write positions, and when the distance is greater than your target latency, use [`Channel::setFrequency`](https://fmod.com/docs/2.02/api/core-api-channel.html#channel_setfrequency) to speed-up the sample rate of your `FMOD::Channel` to get the `FMOD::Sound` to consume samples faster. Likewise when the distance is less than your target latency, reduce the sample rate of your `FMOD::Channel` until you get back to your target latency. This will account for any irregularities in the rate at which samples arrive from `AddVoiceData`, and will ensure you never run out of samples to play. If you speed up or slow down too quickly however you will get pitch distortions, so only make very small changes to the sample rate.

I recently wrote an [example](https://qa.fmod.com/t/is-unitys-built-in-audio-engine-fmod-studio-fmod-5/18911/10) which applies this approach to hook into a Video’s audio source in Unity and get it playing through FMOD- it is the same concept and should help demonstrate how to avoid buffer starvation.

---

_[View the full topic](https://qa.fmod.com/t/sound-buffer-having-crack-pop-sounds-when-trying-to-make-voice-chat/19734)._
