Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Procedural audio, understanding function

Discussion in 'Scripting' started by RyanPaterson, Sep 11, 2014.

  1. RyanPaterson

    RyanPaterson

    Joined:
    Dec 14, 2013
    Posts:
    77
    Hi,

    I'm looking into procedural audio, and I found a unity related article, however I'm unable to find a tutorial that explains why the functions are what they are, such as the line below. I'd like to know what this is actually calculating, and why. If anyone knows a good direction to point me in, or the answer itself i'd really appreciate it.
    This is the article: http://www.develop-online.net/tools-and-tech/procedural-audio-with-unity/0117433

    increment = frequency * 2 * Math.PI / sampling_frequency;


    Thanks
     
  2. Kogar

    Kogar

    Joined:
    Jun 27, 2013
    Posts:
    80
    This seems like a good starting point for understanding what sound is
    http://www.explainthatstuff.com/sound.html
    and here is a more programmatic approach
    http://channel9.msdn.com/coding4fun/articles/Generating-Sound-Waves-with-C-Wave-Oscillators

    A sound is just a compilation of a complex mixture of multiple soundwaves. The most simple is a sinus/cosinus sound which just need one sound wave. The line you have written down is one part of such a sound wave which is defined by its frequency and sampling speed and amplitude
     
  3. RyanPaterson

    RyanPaterson

    Joined:
    Dec 14, 2013
    Posts:
    77
    Hey,

    Thanks for the links, I checked them out, unfortunately they're kind of adhering to the learning curve problem i'm having. The first one starts out a bit too simple, and the the second jumps from simple definitions to some pretty advanced code examples. There doesn't seem to be any kind of middle ground for learning this kind of stuff.

    Cheers for the reply I really appreciate it!
     
  4. DarkArts-Studios

    DarkArts-Studios

    Joined:
    May 2, 2013
    Posts:
    389
    Sorry for the semi-spam message if it's unwanted.

    However you're welcome to have a look at my asset which covers the basics of procedural audio within Unity and has an open api allowing you to extend it where (and if) required with your own algorithmic filters etc.

     
  5. willemsenzo

    willemsenzo

    Joined:
    Nov 15, 2012
    Posts:
    585
    This isn't semi-spam this IS spam.
     
  6. DarkArts-Studios

    DarkArts-Studios

    Joined:
    May 2, 2013
    Posts:
    389
    ... he was asking about procedural audio in unity. Since he's wanting to learn, my asset provides the core with an open API to extend with. It's very much "on topic" otherwise I'd not have mentioned it. I think whether it's spam or not is subjective rather than objective. if the OP thinks it's not helpful, I will delete my post.
     
  7. Kogar

    Kogar

    Joined:
    Jun 27, 2013
    Posts:
    80
    Since procedural audio generation from nothing is really hardcore I'd recommend a FMOD Studio usage.
    There you provide audio files which can then be modified in realtime to your needs.

    http://squaretangle.com/FMODUnity.html
    Here are a few example videos

    www.youtube.com/watch?v=tW08YWvb3vU&list=PL_kQ46ERmOiJLnrTqchzC_offmfFtjO_W


    If you need procedural generated audio you should understand what component even a simple sound has.
    http://obiwannabe.co.uk/tutorials/html/tutorials_main.html
    If you only need simple generated sound effects (like old school 16bit games) you can take a look at
    https://github.com/zeh/usfxr
     
  8. willemsenzo

    willemsenzo

    Joined:
    Nov 15, 2012
    Posts:
    585
    I'm sure your asset is helpful but but offering paid help isn't really nice under the given circumstances.
     
  9. RyanPaterson

    RyanPaterson

    Joined:
    Dec 14, 2013
    Posts:
    77
    Hey guys, a couple comments came in quick so i'll answer them individually

    Darkarts - Thanks for the recommendation, but i'm in my final year of an audio production degree which goes either bsc, or ba, I thought as I like to program and develop little things as a hobby, that I could go the science rout, in doing so I'd need to start from scratch and use 100% my own material that I understand i'm afraid, thanks for letting me know though.

    Kogar - Thanks as well for the reply, I'l check out those videos asap and let you know, however audio files need to be completely excluded from the project i've got in mind. Ideally I want to create a small 2d side scrolling type project where sounds are generated procedurally, to be part of the science portion of the degree if I was to do it.

    Cheers again for the replies guys!
     
  10. DarkArts-Studios

    DarkArts-Studios

    Joined:
    May 2, 2013
    Posts:
    389
    Hi Ryan,

    Since there are those that complained and since you're a student. Send me an email at support@darkarts.co.za and I'll send you the full source code for my original proof of concept which is very simple to understand (only 2 short source code files) and does quite a large amount of procedural audio "out of the box". I'm sure it'll be a great example for you to learn from and/or experiment with.
     
    mikaisomaa and Chambers like this.
  11. willemsenzo

    willemsenzo

    Joined:
    Nov 15, 2012
    Posts:
    585
    I can't argue that's a nice gesture :)
     
  12. RyanPaterson

    RyanPaterson

    Joined:
    Dec 14, 2013
    Posts:
    77
    Hey thank you I really appreciate it!

    I've sent you an email
     
  13. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,300
    If you were going to use FMOD you would want to use the plugin that FMOD have recently released specifically for unity.
     
  14. DarkArts-Studios

    DarkArts-Studios

    Joined:
    May 2, 2013
    Posts:
    389
    Sorry it took so long @RyanPaterson , I thought I had it on-hand but had to dig the source out of my archives. I've sent it off to you.
     
  15. willemsenzo

    willemsenzo

    Joined:
    Nov 15, 2012
    Posts:
    585
    To answer your question:

    increment is a constant value, which is added to 'phase' every timestep. The phase changes every timestep, and every timestep the sine of the phase is calculated. If the phase is bigger than 2 * PI then the cycle of the wave is complete and the phase wraps up at 0.

    Here is some nice explanation about phase, I think this guy explains it excellent and I encourage you to watch his other videos as well because they are all useful even though he looks like he's on crack lol.

     
  16. RyanPaterson

    RyanPaterson

    Joined:
    Dec 14, 2013
    Posts:
    77
    Cheers for the video man I'll give it a watch now. And just again to everyone, thanks for all the help!