- Home /
How does AudioSource.pitch changes pitch?
I looked for this on Google and here and I can't seem to find an answer. There was an idea bouncing around about a music-based portion to our game (possibly in a form of a musical grid). I thought it would be more efficient to just have one audio file and simply change the pitch of it according to which grid cell is pressed/triggered.
I looked it up in the Script Reference and it doesn't say how it changes the pitch. There are many ways I can see it changing:
- Frequency
- Cent
- Semitones
- Percentage
Does anyone know how this is handled? Would it be accurate enough to do it this way or I should just save myself the trouble and create multiple sound files for each pitch. I'm guessing octaves can be done through changing this variable, but I would still need to know how Unity changes it.
Thanks!
Answer by Jessy · Mar 29, 2011 at 12:37 PM
Pitch is just a linear playback speed multiplier. Here's a project that uses that principle, to make an equal temperament musical instrument, using only one audio clip, at one pitch.
(If you don't know what equal temperament is, the basic idea is that there are 12 notes to an octave, and an octave is a doubling of frequency, so the frequency ratio of any note to the note below it is the 12th root of 2. There are many other forms of temperament, of course, but this one is probably easiest to implement.)
Also, because of what "pitch" is, You can play sounds in reverse by using negative numbers.
Keep in mind, though, that changing pitch also changes formants. That means that if you're dealing with voices, you'll get the Alvin & the Chipmunks effect if you pitch things up, and The Knife effect if you pitch things down. Non-human voice sounds won't sound noticeably as messed up, but this is not a modern way of using a sampler. Most samplers today use several samples for every note, for various velocity levels. There are a lot of tricks these days, to change pitch without changing formants, but none of them sound as real as getting a good recording.
Your answer
![](https://koobas.hobune.stream/wayback/20220613115436im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Generating an Exact Muscial Note 1 Answer
Read the pitch frequency of a audio clip 2 Answers
Getting beats from a song using frequency range 1 Answer
getting pitch 1 Answer
Forming chords & playing multiple sounds simultaneously 1 Answer