LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Real-time audio pitch shifting in Labview?

Hi everyone,

 

I'm relatively new to using Labview so am after some help. I am wanting to be able to use Labview to pitch shift inputted audio (from a microphone or from a file) by a specific amount. For example either up or down one musical octave (this would mean doubling or halving the frequency respectively) and then having it output to a speaker in real time (or at least with as little delay as possible). I've worked out how to bring the audio into Labview but am now unsure what would be the best way to do it (or if it even would be possible inside Labview). I have also done a FFT to produce a frequency spectrum of the audio but not sure if this is actually useful.

 

If anyone has any suggestions for the best course of action to take that would be great.

0 Kudos
Message 1 of 8
(4,538 Views)

I am not sure what your problem is since you do not provide code of what you are trying to achieve.

If your problem is how to double or half the frequency, you can achieve this by simply halving or doubling (respectively) the time step of the sound waveforms. Below is an example of doubling the sound frequency by halving the time step:

Doubled sound input_BD.png

If the provided code does not help, I would suggest that you show us the code (or a simple version of it) that you have written so far to try to solve your problem.

 

Good luck

 

Marc Dubois
0 Kudos
Message 2 of 8
(4,497 Views)

The question is asking about pitch-shifting in real time, but doubling the sampling frequency will halve the playback time, so it won't be real time anymore. Presumably this has to be done in the frequency domain. I'd start by capturing a short period of audio (the shorter, the more "real" the time will be), running it through an FFT to convert it from time to frequency domain, doubling all the frequency content, then converting back to time domain and playing back the audio. Do this continuously in a loop, if your CPU is capable of keeping up with it.

 

Edit: I realize these are pretty vague instructions, now that I'm fiddling around with actually trying to implement this. Anyone here have more experience working with frequency-domain signals?

0 Kudos
Message 3 of 8
(4,493 Views)

my naive guess is, you have to FT short time periods (https://en.wikipedia.org/wiki/Short-time_Fourier_transform),

and then move the coefficients 😉

since every bin represents a frequency, which you want changed.


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 4 of 8
(4,487 Views)

@arteitle wrote:

The question is asking about pitch-shifting in real time, but doubling the sampling frequency will halve the playback time, so it won't be real time anymore. Presumably this has to be done in the frequency domain. I'd start by capturing a short period of audio (the shorter, the more "real" the time will be), running it through an FFT to convert it from time to frequency domain, doubling all the frequency content, then converting back to time domain and playing back the audio. Do this continuously in a loop, if your CPU is capable of keeping up with it.

 

Edit: I realize these are pretty vague instructions, now that I'm fiddling around with actually trying to implement this. Anyone here have more experience working with frequency-domain signals?


Yes, this was more or less the theory I was going with. Analysing the input audio in increments of say 1 second (as you say smaller increments would produce better results but would be dependant on processing power). Converting to frequency domain. Altering the detected frequencies and converting back. 

 

I had got as far as getting labview to read the audio from a file that contains a single musical note and doing a FFT to display that frequency. However I am not sure how best to go about altering the frequency content.

0 Kudos
Message 5 of 8
(4,459 Views)

You have an interesting and complex problem, and already "know" (but may not realize that you know) the solution to it.  Let's "play mathematician" and decompose the problem step-by-step.

 

Consider a "static" sound, one that "sounds the same" (say, a chord played on a pipe organ or electronic keyboard) for a (long) period of time.  You want to play this at another pitch, say one octave higher = double the frequency.  Because the sound is "static", you can determine its frequency components, double them, do "something" with the phase components, convert this back to a waveform, and play back the (static) waveform.  Alternatively, you could sample the sound at one frequency (say 20KHz) and play it back at twice the frequency (e.g. 40KHz).  Since we are assuming the sounds are "static", not changing with time, we just play back twice as many points to get a sound that lasts the same amount of time.

 

But what if the sound is not static, what if it is time-varying?  Well, you can divide up the sound into (overlapping?) intervals and treat it as though it were static over that interval.  Mathematicians refer to this as "reducing the problem to a previously-solved case".  Well, almost.  You now have the problem of combining (in an aurally-pleasing way) these time intervals with their frequency-shifted samples in such a way as to "eliminate the edges" where the interval abut each other.  Having the intervals overlap may allow you to do some fancy time-frequency "averaging".

 

Note that there is something called "Time-Frequency Analysis" that deals with essentially this question, and is also important in developing (and understanding) Sound Spectrograms, a 2D plot of sound frequency as a function of time (often used in speech, bird song, and similar studies).

 

Bob Schor

0 Kudos
Message 6 of 8
(4,453 Views)

@MarcDub wrote:

I am not sure what your problem is since you do not provide code of what you are trying to achieve.

If your problem is how to double or half the frequency, you can achieve this by simply halving or doubling (respectively) the time step of the sound waveforms. Below is an example of doubling the sound frequency by halving the time step:

Doubled sound input_BD.png

If the provided code does not help, I would suggest that you show us the code (or a simple version of it) that you have written so far to try to solve your problem.

 

Good luck

 


I appreciate the time you put in to make this. I tested it out and it does come out with the result I was after. I increased the sampling rate up to 88200 which is the highest my sound card can go and that made it quite a bit smoother. 

 

I don't fully understand what this is doing though, I get that it's reading the input audio with the parameters on the left but after that I'm lost. Would you be able to explain what the program is doing after that.

 

Again thanks for the effort you put in.

0 Kudos
Message 7 of 8
(4,449 Views)

https://forums.ni.com/t5/myDAQ-Student-Projects/Pitch-Shifting-using-the-LabVIEW-Advanced-Signal-Pro...

 

http://www.ni.com/example/31219/en/

 

Google search: pitch shift labview

 

This is the same starting point I used when I wanted to play around with a myDAQ auto-tuner in my college DSP classes.

Message 8 of 8
(4,443 Views)