Speakermode Error

Greetings, dear Fmod developers and users!
I’ve encountered a weird behavior when trying to use Fmod bank in a custom C# application, that we’ve written in our company. The purpose of this app is to play some intro while Unity engine loads. This app is using Fmod bank, as i said and the default speaker mode that we’re using is Dolby Atmos 7.4.1.The problem is that when i try to make some events in this bank louder, the loudness doesn’t affect what is happening on the output, so the situation is: the events in the bank are extremely loud, but in the app they are very quiet. Also, it seems to me that the events go to stereo on the output of the app, instead of Dolby Atmos.The code line that describes the output of the app looks like this:

var r1 = coreSystem.setSoftwareFormat(48000, SPEAKERMODE._7POINT1POINT4, 0);

r1 = ERR_INITIALIZED

Can you please help me, what are we doing wrong?Thank you so much in advance! (edited)

Hi,

Could I please grab your FMOD version. Would it be possible to see the full initialization code of the FMOD system?

Hi, Connor! Thank you for your response!
Our Fmod version is 2.02.15
I have an update: Dolby Atmos is working correctly. The main problem now is that audio message events have uncontrolled loudness - the are very quiet in the app, but if we call em from Unity they are extremely loud.
The code of the app is here:

using System.Timers;
using FMOD;
using FMOD.Studio;
using FmodAudio.Interfaces;

namespace FmodAudio
{

public class FmodPlayAudio : IPlayAudio, IDisposable
{
    private readonly IConfig _config;
    private readonly IBankNameStorage _bankNameStorage;
    private readonly List<Bank> _loadedBanks = new List<Bank>();

    private readonly Dictionary<string, EventDescription> _eventDescriptions =
        new Dictionary<string, EventDescription>();

    private readonly Dictionary<string, EventInstance> _eventInstances = new Dictionary<string, EventInstance>();
    private FMOD.Studio.System _system;
    private System.Timers.Timer _timer;

    public FmodPlayAudio(IConfig config, IBankNameStorage bankNameStorage)
    {
        _config = config;
        _bankNameStorage = bankNameStorage;
        _bankNameStorage.OnBankAppear += OnBankAppear;
    }

    public RESULT Init()
    {
        var result = FMOD.Studio.System.create(out _system);
        if (result != RESULT.OK) return result;

        if (_config.SupportDolbyAtmos)
        {
            _system.getCoreSystem(out var coreSystem);
            var r1 = coreSystem.setSoftwareFormat(48000, SPEAKERMODE._7POINT1POINT4, 0);
            if (r1 != RESULT.OK)
            {
                Console.WriteLine($"Set _7POINT1POINT4 failed {r1}");
            }

            r1 = coreSystem.setOutput(OUTPUTTYPE.WINSONIC);
            if (r1 != RESULT.OK)
            {
                Console.WriteLine($"Set WINSONIC failed {r1}");
            }
        }
        
        result = _system.initialize(_config.NumberOfChannels, FMOD.Studio.INITFLAGS.NORMAL, FMOD.INITFLAGS.NORMAL,
            IntPtr.Zero);

        if (result != RESULT.OK)
        {
            Console.WriteLine($"Initialize failed {result}");
            return result;
        }
        
        

        foreach (var bankName in _bankNameStorage.BankNames)
        {
            result = _system.loadBankFile(bankName, LOAD_BANK_FLAGS.NORMAL, out var bank);

            if (result != RESULT.OK) return result;
            _loadedBanks.Add(bank);
        }

        _timer = new System.Timers.Timer(_config.UpdateInterval);
        _timer.Elapsed += UpdateFmodSystem;
        _timer.AutoReset = true;
        _timer.Enabled = true;
        return RESULT.OK;
    }

    private void OnBankAppear(string bankName)
    {
        var result = _system.loadBankFile(bankName, LOAD_BANK_FLAGS.NORMAL, out var bank);

        if (result != RESULT.OK)
        {
            Console.WriteLine($"Error failed to load bank {bankName} {result}");
            return;
        }

        _loadedBanks.Add(bank);
    }

    private void UpdateFmodSystem(Object source, ElapsedEventArgs e)
    {
        _system.update();
    }

    public void PlayOneShot(string eventName)
    {
        EventDescription desc;
        RESULT result;
        if (!_eventDescriptions.TryGetValue(eventName, out desc))
        {
            result = _system.getEvent(eventName, out desc);
            if (result != RESULT.OK)
            {
                Console.WriteLine($"Error {result} while getting description for {eventName}");
                return;
            }
        }

        result = desc.createInstance(out var eventInstance);
        if (result != RESULT.OK)
        {
            Console.WriteLine($"Error {result} while creating instance for {eventName}");
            return;
        }

        result = eventInstance.start();
        if (result != RESULT.OK)
        {
            Console.WriteLine($"Error {result} while staring instance for {eventName}");
            return;
        }
        Console.WriteLine($"PlayOneShot {eventName}");

        eventInstance.release();
    }

    public void Play(string eventName)
    {
        if (_eventInstances.ContainsKey(eventName))
        {
            return;
        }

        EventDescription desc;
        RESULT result;
        if (!_eventDescriptions.TryGetValue(eventName, out desc))
        {
            result = _system.getEvent(eventName, out desc);
            if (result != RESULT.OK)
            {
                Console.WriteLine($"Error {result} while getting description for {eventName}");
                return;
            }
        }

        result = desc.createInstance(out var eventInstance);
        if (result != RESULT.OK)
        {
            Console.WriteLine($"Error {result} while creating instance for {eventName}");
            return;
        }

        result = eventInstance.start();
        if (result != RESULT.OK)
        {
            Console.WriteLine($"Error {result} while staring instance for {eventName}");
            return;
        }
        Console.WriteLine($"Play {eventName}");

        _eventInstances[eventName] = eventInstance;
    }

    public void Stop(string eventName)
    {
        if (_eventInstances.TryGetValue(eventName, out var eventInstance))
        {
            eventInstance.stop(STOP_MODE.ALLOWFADEOUT);
            eventInstance.release();
            _eventInstances.Remove(eventName);
            Console.WriteLine($"Stop {eventName}");
        }
    }

    public void SetParameter(string eventName, string parameterName, float value)
    {
        if (_eventInstances.TryGetValue(eventName, out var eventInstance))
        {
            if (eventInstance.setParameterByName(parameterName, value) != RESULT.OK)
            {
                Console.WriteLine($"Failed to set parameter {parameterName} for  {eventName} with value {value}");
            }
            else
            {
                Console.WriteLine($"Set parameter {parameterName} for  {eventName} with value {value}");
            }
        }
    }

    public void Dispose()
    {
        if (_timer != null)
        {
            _timer.Stop();
        }

        foreach (var eventInstance in _eventInstances)
        {
            eventInstance.Value.stop(STOP_MODE.IMMEDIATE);
            eventInstance.Value.release();
        }

        _eventInstances.Clear();

        foreach (var bank in _loadedBanks)
        {
            bank.unload();
        }

        _loadedBanks.Clear();

        if (_system.isValid())
        {
            _system.release();
        }
    }
}

}

Thank you for the code, everything looks good there. Would it be possible to update to the latest 2.02 version (currently 2.02.31) and let me know if the issue persists?

If you initialize the app system with:

result = _system.initialize(_config.NumberOfChannels, FMOD.Studio.INITFLAGS.NORMAL | FMOD.Studio.INITFLAGS.LIVEUPDATE, FMOD.INITFLAGS.NORMAL, IntPtr.Zero);

And connect live update to the app, do you still experience the loudness differences? Are there any differences in the banks between those loaded in the app an in the Unity project?

1 Like

Hi, Connor! I think we’ve fixed the the app and everything works fine for now! Thank you for your answer!

1 Like

Good to hear it is solved. Would it be possible to share the solution?