Search Unity

Looping "Margins"

Discussion in 'Audio & Video' started by EnsurdFrndship, Nov 28, 2015.

  1. EnsurdFrndship

    EnsurdFrndship

    Joined:
    Apr 17, 2010
    Posts:
    786
    Hello,
    I was wondering if there is a way to set a left and right 'margin' for a looping audio rather than for the audio to loop from start to finish. Using Stop() and Play() through an if statement and a loop seems to work, but it sounds more like there is chopping, distortion or it being done at a noticeable frequency. How can I get the sound to 'loop' more smoothly through a 'margin' (like it does when it goes from start to finish without a script involved)? Thank you.
     
    Last edited: Nov 28, 2015
  2. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Perhaps you need to find the zero crossings in the audio in advance, create a list of "nice places to loop", and then flick through them. Seems like a reasonably doable project. or maybe create a class that seeks the zero points at runtime.

    As you know: Simply displacing the start point effectively provides you with 50% of a big juicy square wave (if you are lucky). Commonly known as a "click". The "right" way to do it would be the "snap-to-nearest" zero crossings method.

    Another way: You could simply override the "loop" facility and loop the sample yourself (this is easy) and then at the end/start lerp/ramp the volume down/up. In a pinch I would use method 2.

    If you want something to sound "non-loopy" then much like colours on your terrain avoid sounds that have totally obvious repeats in them, favour instead noise based patterns or simpler sounds added together to make more complex scapes thus (again) blurring over the repeats.

    I have used this last method lots of times with good effect, smooshing 3 similar wind/wave sounds together via looping them at the same time. The real trick is actualy giving the ear something else to listen to.

    Here is a quick run down of ways to abuse your ears. and to hide clicks.
    (I actually glitch remixed this speech once.. with permission, but I digress. enjoy)