Search Unity

Official Audio system

Discussion in 'Open Projects' started by cirocontinisio, Oct 13, 2020.

  1. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Sorry to have missed this! I think the latest PR from island12 fixes this. Returning a handle was always the plan, I believe I left a comment in the code as a TODO some time ago.
     
  2. cfinger

    cfinger

    Joined:
    Feb 29, 2020
    Posts:
    3
    @cirocontinisio Forgive me if I missed this, but is there a way to play an Audio Cue that follows an object as it moves?

    I see how to raise an event that sets the position of the audio, but what about a moving object that is playing looping audio (for ex, a car).

    Edit: I created a new AudioManager on the moving object, with a new Sound Emitter Pool, and a new Event Channel. I'm using this channel for the sounds associated with the moving object, and the standard scene independent one for all other sounds. Seems to work for now :)
     
    Last edited: Feb 17, 2021
  3. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    I'm not 100% sure we need it, since we don't have moving objects with looping sounds (for now). But I would like to add it.

    This is a bit of a hack :) The reason it works is that the AudioManager instantiates the pool of AudioSources under itself, so in this case they move the character, but... you should only have 1 AudioManager in the game, so it's hardly a good solution.

    We need to implement the feature. (the audio needs some love, tuning and testing, actually)
     
  4. cfinger

    cfinger

    Joined:
    Feb 29, 2020
    Posts:
    3
    That's what I figured. Although I wonder if it will become noticeable for sounds the character generates while moving, even for non-looping sounds. Either way, I'll watch for any updates on the audio !

    Most definitely a hack. And yes, it pools them as children of itself. I did think a bit about how to set the pool objects as children to other transforms but that seemed more hacky. Perhaps I'll have to forgo the scene independent AudioManager for now, and move it on scene transitions.

    Anyway, I'm hoping you do end up needing this feature in the future ;) PS- This project has been great to watch. Thank you.
     
    cirocontinisio likes this.
  5. L4ZZA

    L4ZZA

    Joined:
    Dec 20, 2019
    Posts:
    5
    Hi guys, I have recently come back to this project after a long time away from it and I was wondering if there is a specific reason why we use two lists to store AudioCueKeys and SoundEmitter arrays

    upload_2021-9-20_17-19-38.png

    instead of a Dictionary.
    upload_2021-9-20_17-20-34.png

    I am mainly asking since the latter structure makes more sense to me when coupled with the "key -> data" concept as well as being more performant (if I'm not wrong) when it comes to retrieving data.

    I was about to create a Github issue, but I thought this channels was better suited for this kind of discussion. Is this forum your preferred platform over the two @cirocontinisio?
     
  6. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    Maybe because of performance reasons. dict is not very good performance providing data structure, right? So we are using two Lists, (which is not also a performant data structure, but better than dict).

    This forum, for me... As this question is not really an issue. It is just a question that came into your mind that why this and why not this. Hence forum is a better place for this, and you also picked the right thread (Audio System).

    That's it from me.
     
  7. L4ZZA

    L4ZZA

    Joined:
    Dec 20, 2019
    Posts:
    5
    From my classes at uni as well from my professional experience, accessing elements of a dictionary is a lot faster O(1) than enumerating the whole list O(n). I would be interested to see your view on why the List might be faster, so I have an opportunity to learn from it too ;)

    Here's a few resources to back up my argument:
    1. https://www.bigocheatsheet.com/ - where the Dictionary would be the Hash Table (or very similar to it) and the List
    2. https://stackoverflow.com/a/16977769/6120464 - a nice thread about this argument, the only thing I am not totally sure it's how the CSharp implementation handles the hash algorithm. Looking into it now (see here).

    Aside from the performance argument, I feel like the Dictionary fits more accurately with the purpose of the implementation, which would also help with readability and maintenance in the long term.

    Let me know, what your guys think about it :)



    I think you're right on this ;)


    ---- EDIT ----
    A few more resources here to not stand by the first article I found:
    - https://social.msdn.microsoft.com/F...r-dictionary-for-efficiency-of-code-execution
    - https://softwareengineering.stackexchange.com/questions/264766/efficiency-of-c-dictionaries
    - http://net-informations.com/faq/general/dictionary-list.htm
     
    Last edited: Sep 21, 2021
  8. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Honestly, I don't mind either way as long as it works :)
    It's not a system that gets called frequently, so I don't think performance is a big concern. It only gets called when a sound has to start or stop, so probably never more often than once each few seconds.
    If you want to do a restructuring and you make sure it works and it doesn't affect other systems, then feel free.
     
    L4ZZA likes this.