- Home /
How do I invert audio pitch?
I'm trying to use a script to be able to invert an audio clip's pitch, like they do when canceling out noise.
I'm using javascript.
Answer by janzdott · Feb 01, 2014 at 06:20 PM
Inverting the pitch of an audio clip isn't what you're looking for. Here's a quick explanation why.
Pitch is frequency. Inverting the frequency will give you the period of the wave. P = 1 / f
Working with audio, you should know the basic terminology and equations for waves. First you have amplitude. Amplitude is the distance of the wave from the baseline. Then you have peaks and troughs. Peaks are the high parts of the wave, troughs are the low parts. Frequency is the number of times, per second, that the wave oscillates (peak to peak or trough to trough). Period is the time between each oscillation.
What you're looking for is inverting the amplitude of the wave, which will make peaks into troughs and troughs into peaks. I have not done this before, but I believe these two methods are what you're looking for... AudioClip.GetData() and AudioClip.SetData()
They both deal with floats between -1 and 1. That's the amplitude, which is what you want to invert. Use GetData() to get all the data, then invert all the values in the array by doing data[i] = -1.0f * data[i]
Then use SetData() to set it back. I have not done this before, but it should work. Good luck!
Your answer
![](https://koobas.hobune.stream/wayback/20220613132247im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
How do I stop footstep sound from playing when I release 'w'? 1 Answer
Audio not playing on activation 1 Answer
Unity audio solution 1 Answer