FmodSystem Acts Strange With Certain Channel Counts
Below are a couple of snippets in my code.
internal SfxSystem()
{
_fmodSystem = Fmod.CreateSystem();
_fmodSystem.Init(MaxChannels);
}
Channel? channel = _fmodSystem.PlaySound(sfx.Sound);
if (channel is null) throw new Exception("Sound channel wasn't properly created");
if (randomPitch) channel.Pitch = _rng.Range(0.9f, 1.1f);
When I play the same sound repeatedly, what I hear is different depending on the MaxChannels value. If it's 16, I hear the sound effect playing repeatedly just fine. If it's 64, the sound will play normally at first, but it will eventually stop overlapping with itself and only play when the previous sound is done playing. When I set MaxChannels to 128, the sound plays fine for a few seconds and then cuts out completely, leaving me with total silence.
I have tested further and found that the issues at 64 and 128 channels occur after 64 iterations of the sound have played. No audio issues at 63 channels and below.
Nevermind about 63 and below being fine. My sound effects are randomly cutting out or not playing, and it seems to get worse with higher channel counts.
Here is the full wrapper class I made where I am encountering the above-described issues.
public class SfxSystem
{
private const int MaxChannels = 63;
private FmodSystem _fmodSystem;
private Rng _rng = new();
internal SfxSystem()
{
_fmodSystem = Fmod.CreateSystem();
_fmodSystem.Init(MaxChannels);
}
public void Play(Sfx sfx, bool randomPitch = false)
{
Channel? channel = _fmodSystem.PlaySound(sfx.Sound);
if (channel is null) throw new Exception("Sound channel wasn't properly created");
if (randomPitch) channel.Pitch = _rng.Range(0.9f, 1.1f);
}
public void Play(string sfxName, bool randomPitch = false) => Play(Lib.Sfx[sfxName], randomPitch);
internal Sound CreateSound(string assetName)
{
var soundPath = $"{ContentPaths.Root}/{ContentPaths.Sfx}/{assetName}";
if (!File.Exists(soundPath)) throw new Exception($"Invalid path for sound file: {soundPath}");
return _fmodSystem.CreateSound(soundPath, Mode.CreateSample | Mode.Loop_Off);
}
}
Ok, so, one thing to note about Fmod, is that how many channels it can actually play at a time depends on how many channels the underlying hardware/API allows. Anything above that is updated virtually until such time as a real/hardware channel becomes available.
Also, sorry for the really late reply.
You can query how many real channels are available via FmodSystem.SoftwareChannels. This API reports on my system to be 64 channels.
As for the other issue, where all sound cuts out entirely, that might be something you will want to report to the Fmod team directly.