0
votes

This is the first time I try to analyse audio stream on C#. Without any experience, it will be grateful that you share your solution. :)

Using NAudio(an opensource for C# dealing with audio), I try to compare two audio stream with the following stages:

  1. Read in a .wav file and store in float[] in 16 Bits:

    audio = new AudioFileReader("test.wav");   
    _buffer = new float[wave.length];   
    audio.Read (_buffer, 0, _buffer.Length);
    
  2. Pass the float[] to SmbPitchShifter(), and set the PitchShift=1(not change the pitch), set the osamp as the hop size, and pass the _buffer.

    sps = new SmbPitchShifter();   
    sps.PitchShift(1, _buffer.Length, 2048, 32, 44100, _buffer);
    
  3. Last, compare two STFT float[] using DTW algorithm.

Now, I am stucked at the stage 2, and have some questions:
1. I do not exactly know what is my sampleRate, but set it to 44100 as default...
2. After the above code, I got a new _buffer float[], with dater after stage2 1: https://imgur.com/a/VLmHJ as I know the data after STFT should be [-1.0, 1.0). What step did I miss, or I am completely wrong at the beginning?
3. I have no idea what window is NAudio used.NAudio.Dsp.SmbPitchShifter.CS from github These bothered me for a long time. As you can tell I am new in audio analyse, and i am really appreciate for your advice. Have a good day.

1

1 Answers

0
votes

Firstly you can find the sample rate with audio.WaveFormat.SampleRate

Second, a pitch shifter will not really help with analysis. It is simply shifting the pitch (as you stated), firstly using the short time fourier transform (STFT), doing some processing and then transforming back with an in inverse short time fourier transform (ISTFT).

If you want to use dynamic time warping to compare two signals you will need the representation of your signal whilst it is still in the frequency domain. The github link to the pitchshifter is actually a really nice place to start, I suggest you take the STFT code+logic from there and try to make it work yourself. See how they implement the STFT on line 242 and how they use this on line 125. Good luck!