1

Some video games music seems to play faster as the action on screen increases.

How are they achieving this effect, Do they have the same loop but simply speed it up, do they have the loop cut up into different sections and play them closer together?

I guess the closed analogy I have is the "Jaws" movie theme tune, where it gets quicker.

I'm looking for any input on this, I don't know what the correct wording for this is.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Chris
  • 2,739
  • 4
  • 29
  • 57

1 Answers1

2

The simplest method is to increase the pitch. In Unity this can easily be done by modifying AudioSource.pitch. When this is increased, audio is faster, when decreased, the sound is slower and sounds like Mario under water.

Assuming you are slowing the game down or making it run faster with Time.timeScale, the sound will slow down or play faster too with the code snippet below:

AudioSource movingAudio;
movingAudio.pitch = Time.timeScale;

The bad side to this method is that the pitch will change, so as the tempo. You will need to build a plugin in order to make the sound play faster without increasing tempo and pitch.Re-sampling the audio-clip in real-time is the actual solution but that is a complicated topic. OnAudioFilterRead is used to do stuff like this if you decide to make a plugin.

Programmer
  • 121,791
  • 22
  • 236
  • 328
  • This isn't strictly true - this increases the pitch and speed at the same time (simply increasing the sampling rate achieves this effect - pitch being the frequency of the sound, higher pitch = higher notes). Some games have very complex audio systems and may be resampling in realtime if they want to increase the audio speed without affecting pitch. If you aren't bothered about the pitch increasing then this is the way to go (and possibly the only supported way in Unity?) – Charleh Aug 15 '16 at 22:01
  • You can have mutliple audio sources for different pace of game play, which vary depending on game state, but you need to manage how one segues into the other though. – ManoDestra Aug 15 '16 at 22:02
  • @Charleh That depends on what he's doing. If the OP is making a [piano](http://stackoverflow.com/q/36793628/3785314) then he will really need to make some plugin in C++. Unity does not have a built in way to do this. You have to make a plugin and do some processing which is CPU intensive. If you don't care about the pitch increasing then simply changing the `pitch` should be fine. – Programmer Aug 15 '16 at 22:17
  • @ManoDestra That's a clever way. It's just that it will be likely for a player to tell when the audio switches and that will be annoying... – Programmer Aug 15 '16 at 22:31
  • Not really, if you fade one into the other. The music needs to be designed in such a way as to cater for this kind of seguing effect. Play some professional games like Fable, for instance, and you'll see what I mean. It can be done by amateur devs too, but it takes quite a bit of sound design and patience to achieve it. I agree though, this is a simple solution and works fine for the requirements if they can live with the pitching effect :) – ManoDestra Aug 16 '16 at 03:19