Search Unity

A few questions regarding audio

Discussion in 'Audio & Video' started by v3rm33r, Mar 4, 2015.

  1. v3rm33r

    v3rm33r

    Joined:
    Jan 21, 2015
    Posts:
    2
    Hi all,

    I have recently started developing content for the Gear VR using Unity as a bit of a hobby and have been enjoying learning something new. I have tried searching for answers myself, but not found anything that gives me a concrete answer or enough confidence to spend a lot of (possibly wasted) time pursuing. I have an idea I want to try and develop, but not sure if it is possible or how I would go about it and was hoping one of you guys could point me in the right direction (or stop me in my tracks and save me wasting my time!). Basically, it is a tower defence type game, where each "tower" added by the player plays an audio loop that is part of a larger composition (ie a snare drum loop, or bass loop etc so the player builds up an entire music track whilst placing the individual towers).

    I was thinking the best way to do this would be to have all the audio loops playing in sync at the start but muted, with each tower placed, unmuting the relevant loop in order to keep all the loops in time. Is this possible on Android? I understand there are audio limitations on Android regarding simultaneous sounds, which could be got around by having many loops with individual instruments enabled or disabled (but thinking this would become a logistical nightmare, increase file size significantly and not be very efficient)? Would I be best to create an audio manager and then trigger sound on/off from the individual components, or to attach the audio loop to them and code the functionality for each as separate prefabs?

    Sorry if I sound like such a noob, but unfortunately I am!!

    I would really appreciate any help or advice that you could spare the time to give.

    Many thanks
     
  2. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    hmm. sounds like fun.

    I think i would start by just making a simple list of the type using generics <>

    Then: First thing would be to actually try to get them all to sync when played at same time. That may be fun.
    You might consider a "sync" track like in the old days. I have read a few projects that used this approach with good results.

    Second thing figure out how much resource it takes to play say - 20 sounds all at once - currently unity only support a maximum of 32 sound polyphony, In the 4.x series I believe. 5.0 is probably "infinite" (in the sense of sub-mixing) - only limited by resource I would guess

    Third, worry about muting and unmuting at the right times.

    Only then even think about adding a game on top.

    If you fail miserably during any of these stages there are a couple of packages out there you could try that may facilitate this actually working. Search the store and elsewhere for these.

    I, personally, would just give it a go myself before purchasing.
    Only sticking point might be the enforced compression issue on the samples.... but since you just want to "run and loop" them this might work out okay.

    I honestly think audio drift will be the biggest issue assuming you get it all working.

    I know this is outside the scope of your original idea... but you could just do 30 tracks.
    each time you add a tower you switch to the "Next track" via a musical segue (like a filter fade out or something typical)
    This would require almost no coding just more storage. however each tower would no longer represent each "sound". (think REZ)

    Anyway. Sounds doable, if a bit of a pain.

    Good luck.
     
    Last edited: Mar 9, 2015
  3. v3rm33r

    v3rm33r

    Joined:
    Jan 21, 2015
    Posts:
    2
    Thanks twobob, I will try and set a simple scene (a cube with a switch for each loop) and see how many concurrent loops I can get playing in an exported Gear VR app first. Thinking of pooling these in Audio Toolkit to see if I can improve on drifting (not experienced this yet, but sounds like it may be a ball ache!) and synching. I have created some audio loops at a certain BPM that all play in time, so will see how I get on. I assume the audio drift is in Unity itself?

    Really appreciate you taking the time to reply and will post some progress by the end of the week (family life allowing!)

    I had already considered having various versions of the complete track with loops on or off, and then calculating which loop to play by the "towers" in play, but expecting this to be a much more time consuming approach (and big increase in file size!).
     
  4. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    The very very very very very very first thing I ever did with my xbox was make a set of virtual decks...

    (goes to find a very old hard drive).... meh, it's here somewhere.

    Anyways, long story short, same tech. same concepts, except I would argue the xbox was a pretty tough target given the state (or lack of) of the audio API back then.

    Since you actually already KNOW the bpm ahead of time there a are a couple of simple things you could do.

    The very easiest of which would be to simply trigger it at what you presume will be the next relevant "Beat start" time.

    Another, simpleish, way to ensure that the loops dont "drift" on repeat is imply don't loop them at all. Just repeat the "Play" command each time you want to trigger them.


    One final thought: Junk. or garbage, I would take a very hard look at whether or not a NEW sample is instantiated everytime you ask a sample to play. - I recall on the xbox this was the case. so check out the profiler for clues. and read the docs.
     
  5. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051