How do I change the pitch of a wave with sharpDX/Xaudio2 ?

296 views Asked by At

All I want to do is play a WAV at random pitches in my Universal App. If there is a more straight forward way to do this than needed SharpDX tell me!

 private void PlayTone(float randomPitch)
    {
        var xAudio = new XAudio2();
        var masteringVoice = new MasteringVoice(xAudio);
        var nativeFileStream = new NativeFileStream("Assets/440tone2.wav", NativeFileMode.Open, NativeFileAccess.Read, NativeFileShare.Read);
        var stream = new SoundStream(nativeFileStream);
        var waveFormat = stream.Format;

        var buffer = new AudioBuffer
        {
            Stream = stream.ToDataStream(),
            AudioBytes = (int)stream.Length,
            Flags = BufferFlags.EndOfStream
        };

        var sourceVoice = new SourceVoice(xAudio, waveFormat, true);
        sourceVoice.SubmitSourceBuffer(buffer, stream.DecodedPacketsInfo);
      //  sourceVoice.SetFrequencyRatio(200.0f);
        sourceVoice.Start();
    }
1

There are 1 answers

0
punkouter On

I had to switch these around

sourceVoice.SubmitSourceBuffer(buffer, stream.DecodedPacketsInfo);
    sourceVoice.SetFrequencyRatio(200.0f);