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

Dynamic music in Unity - Examples?

Discussion in 'Audio & Video' started by Olipool, Feb 12, 2015.

  1. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    316
    Hi there,

    I'm just starting off with Unity and haven't even touched audio yet but I'm very fascinated by the idea of dynamic audio e.g. a fight begins and the music turns into battle music. Or simply in a 2D sidescroller when the player progresses towards the exist, the music gets "richer", more instruments come to play etc.
    While the fight music maybe easy to implement by fading to audio sources, I was wondering how to achieve something like the second example. One could switch the audio source when the player reaches a certain point but that would be too abrupt, blending sounds like, well, blending. Is it possible to queue up audio files?
    For example: while the player is in region 1, only the first 4 beats of a song are looped, after that the music has to switch to the next 4 beats, but in a fashion that it feels like one song. It is like generating notes on the fly depending on the player behaviour... :) Is something that dynamic possible and do you have any nice examples for that on Youtube etc.?

    Thanks for the support! :)
     
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah - interested in guides on this for a future unity blog :)
     
  3. Veemix

    Veemix

    Joined:
    Dec 5, 2014
    Posts:
    25
    The Veemix plugin (currently for Unity iOS with an Android version in development) can do what you are describing in the first example, using streaming music from SoundCloud or from the device's music library. There are a couple of demo videos in its promotional thread in the Asset Store subforum: http://forum.unity3d.com/threads/veemix-a-music-plugin-for-unity-ios.284236/

    In a nutshell: Veemix allows for the creation of unlimited tagged event areas within a game scene, and these tagged areas have mood keywords associated them (set by the game developer). While streaming, the mood keywords are used to find appropriate music on SoundCloud and the music gets queued and played automatically as the player encounters one of these tagged events while playing. When using the iOS music library, the mood keywords serve to help the player make a suitable selection from their own music, although the player is free to choose whatever music they like. If the player has already picked music from their own library for a given event, then that music gets played automatically when the encounter the tagged area, just like in streaming mode.

    As for the second example, it is certainly possible to use pre-recorded segments of a complete song and play the individual parts at appropriate times, but you would still be constrained to hearing whatever was in the looped segments with no real variation. You mentioned generating notes on the fly depending on the player behaviour (generative/procedural music), which to me is a much more interesting and useful approach. While Veemix doesn't support completely generative music (yet!), we have been experimenting with generating sound effects and short musical phrases (musemes) that are harmonized with the player's music selection and serve to complement the overall auditory experience while increasing the feeling of immersion in the game. You can see some clips of the Veemix harmonizer prototype here:



    Dynamic music is definitely a fascinating aspect of game audio. I'm glad to see it being discussed on these forums!
     
    Matti-Jokipii and Olipool like this.
  4. HelloMeow

    HelloMeow

    Joined:
    May 11, 2014
    Posts:
    279
  5. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    316
    Thanks for the input fellows! :)
     
  6. TheSniperFan

    TheSniperFan

    Joined:
    Jul 18, 2013
    Posts:
    712
    Here's also the pro solution for Unity.
    It's extremely powerful and widely used, but will take some time to really get used to. It may or may not be overkill for you.
     
  7. Werkmeister

    Werkmeister

    Joined:
    Jan 7, 2015
    Posts:
    16
    Hi,
    our Interactive Music Engine psai gives you quite a range of possibilities to easily achieve highly interactive music in your game. As game composers we wanted to be able to achieve highly adaptive music in games without turning grey on audio authoring madness - so we decided to develop our own tool. We focussed on how to achieve adaptivity and simplicity at the same time. Since November psai is available for Unity.

    Just recently we have created a new demo using Unity's Angry Bots.You will find the demo and tutorial videos on how it was created (without any scripting) in this unity forum thread:
    http://forum.unity3d.com/threads/released-psai-interactive-music-engine.279963/

    You can get psai for free and check out interactive features within your game using our demo soundtrack:
    http://www.assetstore.unity3d.com/en/#!/search/psai

    Cheers,
    Jan
    Periscope Studio
     
  8. bosone

    bosone

    Joined:
    Sep 13, 2011
    Posts:
    375
    I have tried to compose some adaptive music.
    you may have a look here

    basically I composed several loops with different moods, that can be seamlessly crossfaded and adapted to game play.

    watch the youtube demo

    If you have more suggestions for a composer interested in making more assets like this just tell me! :)
     
  9. Nifflas

    Nifflas

    Joined:
    Jun 13, 2013
    Posts:
    118
    On the side of my main project, I've been developing a general purpose signal system that's very suitable for procedural music, as well as some components for it (a tracker-like step sequencer). One day I might release the thing on the asset store, but I want to use it in a bigger game of my own first. I took it for a test run in my mini game 7 Nanocycles:



    You can play the game here. It's not loop-based (though there is some semi-realtime random beat slicing on one of the drum tracks), so all notes are triggered from the game using scale modifiers and random chances for notes to trigger.

    Though it takes a lot of work, maybe my approach can be useful when have spent more time with Unity. Basically, make a whole bunch of components (a master sync device, sequencers, sound players, generators, random chance relays) and make sure they all communicate in a very generic way that allows you to hook anything up to anything, so that you can just keep creating more components as you need them.
     
    Last edited: Feb 25, 2015
  10. bernardfrancois

    bernardfrancois

    Joined:
    Oct 29, 2009
    Posts:
    373
    A while ago, I wrote a blog post on doing dynamic music - where you have multiple loops that fade in/out dynamically.

    It's not too hard to do, but the music needs to have some requirements (ideally the loops have the same length, tempo, and sample rate).

    See http://previewlabs.com/dynamic-music-in-unity3d/
     
  11. mtytel

    mtytel

    Joined:
    Feb 28, 2014
    Posts:
    84
    I just shipped some assets that allow you to run a synthesizer and sequencer in your game.
    You could change the sequence to major/minor, change the synth parameters so the sound is richer, etc. as the player progresses in the game to create dynamic and even generative music.

    https://www.assetstore.unity3d.com/#!/content/86984
     
    MlleBun and DXTRMRFY like this.