ar1st0crat / NWaves

.NET DSP library with a lot of audio processing functions
MIT License
453 stars 71 forks source link

Pitch shifter produces garbled noise #85

Closed BlueCyro closed 9 months ago

BlueCyro commented 9 months ago

For the life of me I cannot get the pitch shifter to work correctly.

I have instantiated a shifter with the correct sample rate for my device (48khz), a shift of 1 (which to my knowledge should be no shifting), and the default fft size of 1024 and hops of 64.

I have a sample source (mono) that provides me a span of float samples that represent amplitude (both positive and negative)

I call Process() for each sample in the span and store the returned float in another span I've created (same size as input)

I pass that buffer along to the audio system, and the samples become garbled. What am I actually doing wrong here?

PitchShiftVocoderEffect myPitchShifter = new(48000, 1, 1024, 64);
void Source(Span<float> samples)
{
  var buf = stackalloc float[samples.Length];
  for (int i = 0; i < samples.Length; i++)
  {
    buf[i] = myPitchShifter.Process(samples[i]);
  }
  // ...Stuff that sends the buf to the audio system, audio is corrupted
}
BlueCyro commented 9 months ago

Welp, that was quick. Found out what was calling my "Source" was actually inserting a call to it twice in the code I was tweaking. Woopsie daisies. The effect works fine :3