Search Unity

OnAudioFilterRead, how to change pitch?

Discussion in 'Audio & Video' started by Modernllama, Mar 23, 2017.

  1. Modernllama

    Modernllama

    Joined:
    Nov 30, 2012
    Posts:
    19
    Hi,

    I've been looking into changing the pitch of audio using this sequencer open source code:

    https://github.com/Nidre/Unity-Audio-Sequencer

    This sequencer is working really well, but I'd really like to be able to adjust the pitch of the track and don't really understand how to do that in OnAudioFilterRead()? I'd love for someone to detail further how that function works and how I would go about it.

    Thanks,
     
  2. CarlosBCV

    CarlosBCV

    Joined:
    Jun 21, 2013
    Posts:
    4
    Short answer, you can't.

    Long answer, seems like what it is doing on OnAudioFilterRead() is copying the clip data to the buffer, so if you want to change the pitch you should interpolate the sample rate by hand, and you will have to rewrite nearly all what is on the OnAudioFilterRead().

    I recommend you not to use that sequencer, it’s very convoluted, and I doubt of its synchrony.

    You can program a good sequencer using AudioSettings.dsptime as time reference, and scheduling the AudioSources with PlayScheduled(). That way you can use the own pitch of the AudioSource.
     
  3. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,305
    the above reply is incorrect - you certainly can adjust pitch of the sound when using OnAudioFilterRead callback - just adjust it on the corresponding AudioSource on the same game object - that's all.
    ( there are other parameters of an AudioSource which don't work when using OnAudioFilterRead, but pitch is certainly not among them )