My audio sources are unaffected by the pitch setting [FIXED]

Hi,

when I change the pitch of my audio clips they sound no different at all. I’ve tried many different audio clips with pitches from 0.1 to 10 and there’s no difference at all.

I’m trying to create a slow motion effect and I want the music in my game to slow down when my games slows down.

I’m not really sure what pitch is, but I would think a pitch value of 0.5 means the audio clip takes twice as long to play?

Also, I can only change the pitch between 0.5 and 2 in the editor, but I can change it between 0.1 and 10 through scripting. Is this a bug?

Am I mistaken? Am I just dumb? :slight_smile:

Edit: I’m using Unity 2.1 Indie on a Macbook Pro with Leopard.

FIXED: I had the doppler effect set to 0.5. Setting it to 0 enabled me to affect the pitch of my audio clips.

Pitch change has no effect unless the sound is uncompressed. Either use uncompressed sounds or use decompress on load.

That’s tempo. Pitch is how high/low the note is. However, changing pitch without changing tempo is more processor-intensive, so Unity takes the more common approach and slows the sound down to get a lower pitch. (And speeds it up to get a higher pitch.)

–Eric

I see.

However, I tried it now with all kinds of different file types, in mono and stereo, with both uncompressed and compressed files and decompress on load on or off.

Setting the pitch to 0.1, 0.5, 5 or 10 still doesn’t make the audio clips sound different.

I have an empty game object with an Audio Source component with my audio clip selected, and a script attached which toggles the pitch with the push of a button.

I’m unable to make this work. :slight_smile:

Are there other or better ways of slowing down sounds available to me?

You could use multiple audio samples, but that seems kind of wasteful when audio.pitch has always worked fine here. Post your script?

–Eric

It’s the same toggle I use for the slow motion itself which modifies timescale to simulate slow motion. I have changed the key required for the audio pitch in case the timescale was screwing things up, but it had no effect.

if (Input.GetKeyDown("f")) { 
  if (audio.pitch == 1.0) {
    audio.pitch = 0.1;
  } else {
    audio.pitch = 1;
  }
}

I don’t see how the script will help as I can see the pitch setting change in the edtior when I hit the toggle, and I can change it manually in the editor if I want, but it still doesn’t affect the audio clip.

Edit: Something possibly worth noting is that I’ve only playtested my game in the editor. Not sure whether that matters or not.

Edit2: Nope, it didn’t matter. :slight_smile: I thought it was time consuming to build run the game, but it wasn’t. I tested it now and the pitch still doesn’t affect anything.

In Project Settings->Audio, are you using a doppler factor? That and manual pitch changes are mutually exclusive.

Hah, awesome.

I went to bed shortly after writing my last post and just sat down with unity again. The doppler factor did it.

It was set to 0.5 by default. Setting it to 0 and I’m getting awesome results from changing the pitch. :slight_smile:

Thanks alot, both of you. :smile:

All true from Eric, but what Twiik asked here is also correct.

It is more taxing on the CPU to do pitch-shifting without changing tempo, but it also has a high chance of introducing sonic artifacts. So the way Unity does it is the safest way to keep things from sounding glitchy, and the least CPU-hungry. It’s also tricky, because different algorithms lend themselves better to different types of sounds! Logic Pro 8, for example, includes no less than nine different algorithms for this. Here is an excerpt from the Logic manual that describes the problem:

Basically, there are three important factors when dealing with this stuff: tempo, transposition, and formants. Formants are the resonances of a sound that give it its characteristic “tone”. A great example of formant shifting can be seen in the Alvin and the Chipmunks stuff, at least pre-1990, when everyone was still using tape. The voice actors had to speak or sing everything very slowly. When the tape was played back at a faster rate, the tempo of the recording was corrected. However, along with this, the pitch of the voices was transposed up, and the upward shifting of the formants gave the impression that the voices were coming from teeny-tiny bodies.

How does formant shifting relate to Unity pitch-shifting? Well, if you deviate too far from pitch = 1, you’re going to give the impression that whatever making the sound has changed in size (given two otherwise identical objects, the bigger thing will make lower-pitched sounds). If you need something to wildly vary in pitch, it is probably best to create multiple samples outside of Unity, and use a mix of the Unity pitch control, and crossfading between them.

The better sample libraries for musical instruments use one sample for each note. That is, twelve different pitches per octave, played on an acoustic instrument, will be recorded, and each one will be mapped to the appropriate key of a MIDI keyboard. Half-step deviations are equivalent to pitch values of 1.05946 and 0.94387. If you can get within about 1/4 that close (0.79370 - 1.25991), you should be doing very well for most sounds. If you’re not generating the clips with a synthesizer, then using a pitch-shifting plug-in with formant control is your best option. I just checked in Audacity, but it doesn’t come with that built-in, anyway. Maybe somebody else knows of a good free tool for this? In the past, I have used Peak and Digital Performer to do it, and now I use Logic, but those all cost a lot.