Search Unity

Audio Will it be possible to create audio mixer groups one day?

Discussion in 'Audio & Video' started by bleu, Jun 13, 2017.

  1. bleu

    bleu

    Joined:
    Apr 6, 2013
    Posts:
    41
  2. Ari-Bouaniche

    Ari-Bouaniche

    Joined:
    Dec 17, 2013
    Posts:
    9
    It seems (from my short exploration of the doc) that this is still not possible today (i.e. more than 4 years later...) I was trying to instiate a mixer at runtime, and either I didn't find how to do it properly, or it can't be done...

    Any earthshaking / groundbreaking idea anyone?
     
  3. bleu

    bleu

    Joined:
    Apr 6, 2013
    Posts:
    41
    It would be nice. I have dynamic audio sources that I wish to normalize, and the only way to normalize an individual audio source is to do so via an individual audio mixer group. So not only is it not possible to create an audio mixer group dynamically, but I cannot try the alternative -- apply a normalization filter to an audio source without relying on an audio mixer group.

    The other alternative is to do various effects like normalization via C#. Or if I want to rely on audio mixer groups for that stuff, I would have to maintain a pool of used and free audio mixer groups but that sounds a tad complicated.
     
  4. Marald

    Marald

    Joined:
    Jan 16, 2015
    Posts:
    42
    Hi, I would also like to create channels and groups during runtime, as well as adding effects and automatically exposing variables of the effects. Another useful feature would be if you could clone / copy existing audio channels (runtime or editor), as for now you have to set up every channel by hand.

    Also the settings of all audio effects aren't copy-able from one effect to the other. Why not?
    And please Unity, give direct access to all parameters in the mixer. Currently not all parameters are exposable. I would like to have a direct link with the output level of a channel (after and before processing effects).
     
  5. tfodorsound

    tfodorsound

    Joined:
    Jun 12, 2015
    Posts:
    12
    +1 +1 +1 on this. Dynamically adding and removing mixer groups would be outstanding.
     
    Marald likes this.
  6. laggyluk

    laggyluk

    Joined:
    Oct 7, 2011
    Posts:
    32
    Looks like we need to wait another 4 years for next audio engine iteration
     
  7. realkillerx

    realkillerx

    Joined:
    Nov 9, 2013
    Posts:
    10
    Make that another 4 years
     
  8. StudioEvil

    StudioEvil

    Joined:
    Aug 28, 2013
    Posts:
    66
    And another 2 years
     
    DarkDeivel likes this.
  9. asger60

    asger60

    Joined:
    Mar 27, 2013
    Posts:
    45
    Any day now..
     
  10. FaithlessOne

    FaithlessOne

    Joined:
    Jun 19, 2017
    Posts:
    315
    While it would be great to create audio mixer groups dynamically I still needed a working solution for my project. I only need a couple of such mixer groups and only temporary, so I implemented a pooling where a pool of audio mixer group is shared via an ObjectPool. Thats the code for creating the pool:
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using System.Linq;
    3.  
    4. using My.Game.Scripts.Audio;
    5.  
    6. using UnityEngine;
    7. using UnityEngine.Audio;
    8. using UnityEngine.Serialization;
    9.  
    10. using Zenject;
    11.  
    12. using Object = UnityEngine.Object;
    13.  
    14. namespace My.Game.Scripts.Project
    15. {
    16.   public class GameObjectPools : MonoBehaviour
    17.   {
    18.     private List<AudioMixerGroup> _pitchedSoundEffectsMixerGroups;
    19.  
    20.     [Inject]
    21.     private AudioController _audioController = null!;
    22.  
    23.     private ObjectPool<AudioMixerGroup> _pitchedSoundEffectsMixerPool = null!;
    24.  
    25.     private int _pitchedSoundEffectsMixerProvidedCount;
    26.  
    27.     public ObjectPool<AudioMixerGroup> PitchedSoundEffectsMixerPool => this._pitchedSoundEffectsMixerPool;
    28.  
    29.     private void Awake()
    30.     {
    31.       this._pitchedSoundEffectsMixerPool = this.CreateSoundEffectsMixerPool();
    32.     }
    33.  
    34.     private ObjectPool<AudioMixerGroup> CreateSoundEffectsMixerPool()
    35.     {
    36.       this._pitchedSoundEffectsMixerGroups.Clear();
    37.       // The MasterMixer is the AudioMixer which is assigned from a serialized field of a different GameObject
    38.       var matchingGroups = this._audioController.MasterMixer.FindMatchingGroups("Master/SoundEffectsSend/PitchedSoundEffectsSend/");
    39.  
    40.       // Filter out parent
    41.       this._pitchedSoundEffectsMixerGroups.AddRange(matchingGroups.Where(group => group.name != "PitchedSoundEffectsSend"));
    42.  
    43.       return new ObjectPool<AudioMixerGroup>(
    44.         () =>
    45.         {
    46.           if (this._pitchedSoundEffectsMixerProvidedCount >= this._pitchedSoundEffectsMixerGroups.Count)
    47.           {
    48.             throw new GameException($"Too many audio mixer groups requested from pool. Maximum is {this._pitchedSoundEffectsMixerGroups.Count}.");
    49.           }
    50.  
    51.           return this._pitchedSoundEffectsMixerGroups[this._pitchedSoundEffectsMixerProvidedCount++];
    52.         },
    53.         (audioMixerGroup) => { },
    54.         (audioMixerGroup) => { },
    55.         audioMixerGroup => { },
    56.         defaultCapacity: this._pitchedSoundEffectsMixerGroups.Count, maxSize: this._pitchedSoundEffectsMixerGroups.Count
    57.       );
    58.     }
    59.   }
    60. }
    This is the audio mixer configuration:
    upload_2023-12-30_22-16-55.png
    Each exposed parameter has to have its own unique name so they can later be called to change the necessary mixer group settings. The code getting a mixer and chaning the exposed parameter looks like this:
    Code (CSharp):
    1. var pitchedAudioMixerGroup = this._gameObjectPools.PitchedSoundEffectsMixerPool.Get();
    2. someAudioSource.outputAudioMixerGroup = pitchedAudioMixerGroup;
    3. var pitchParameterName = $"{pitchedAudioMixerGroup.name}.Pitch";
    4.  
    5. if (!this._audioController.MasterMixer.SetFloat(pitchParameterName, 1.1f))
    6. {
    7.   throw new Exception($"Pitch parameter '{pitchParameterName}' not found");
    8. }
    9.  
    When no more needed the mixer should be returned to the pool.
     
    Last edited: Dec 31, 2023