2
\$\begingroup\$

Using Unity's own default AudioSource, there is a pitch slider. However, that pitch slider affects both the speed and the pitch.

Short of doing the speed up/slow down in an external program and importing multiple versions of the same audio track or using third-party middlewares, is there another way to achieve this in the stock engine?

I'm happy for any guidance towards any APIs to do this programatically (ie. access to the raw soundwave as it's being played*) or concoction of internal components.

*You can access the raw waveform (samples) of an AudioClip, but I prefer to do this real-time.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Changing pitch without changing playback speed, and vice-versa, is actually a very difficult problem in audio engineering. Such effects are often computationally expensive and still come out sounding artificial - for example, recent AAA game Hogwarts Legacy has a pitch control for the player's voice, and putting the slider to either extreme causes very noticeable digital distortion in the voice. I haven't used it, but you might look at the FMOD plugin for Unity: fmod.com/docs/2.02/api/effects-reference.html#pitch-shifter \$\endgroup\$
    – Kevin
    Commented Mar 7, 2023 at 2:08
  • 1
    \$\begingroup\$ Have you looked into OnAudioFilterRead? \$\endgroup\$
    – DMGregory
    Commented Mar 7, 2023 at 2:20
  • \$\begingroup\$ The general rule of thumb I use is that if I'm changing the pitch by 10% or less, I can do it with the pitch property in Unity and the user won't notice the difference in the length of the clip. Any more than that, and the clip generally needs to be recreated/re-recorded at the desired pitch. You can try to write a custom filter using OnAudioFilterRead(), but if you aren't already deeply familiar with audio engineering, you'll probably be overwhelmed. \$\endgroup\$
    – Kevin
    Commented Mar 7, 2023 at 2:23
  • \$\begingroup\$ @DMGregory That sounds like what I might be looking for; thanks! Only issue is you can't mark a comment as an answer, lol. \$\endgroup\$
    – aytimothy
    Commented Mar 7, 2023 at 2:57
  • \$\begingroup\$ Remember you can answer your own questions. So if you're able to get a working speed adjustment or pitch shift filter using this callback, post your implementation as an answer and you can mark it as Accepted so other folks struggling with the same issue know it successfully solved the problem. \$\endgroup\$
    – DMGregory
    Commented Mar 7, 2023 at 2:59

0

You must log in to answer this question.

Browse other questions tagged .