Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Implementing pitch shifting in real time (Read 6035 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Implementing pitch shifting in real time

Hi guys,

Im currently involved in a final year project where i must implement a pitch 'scaling' function to change the pitch of a violins real time input.  This would be a simple code in matlab / c except im having trouble because violins have tonal qualities!!!!

Is there anyone who would know how to implement this, ive tryed implementing a high pass filter to filter out every thing above 2.5khz (tonal qualities when bowing) and rejoining the signal but it doesnt sound right!

Basically im asking if there any general algorithms out there that may help? 

Any help would be great...
Cheers

Peter 

Implementing pitch shifting in real time

Reply #1
Quote
Im currently involved in a final year project where i must implement a pitch 'scaling' function to change the pitch of a violins real time input.  This would be a simple code in matlab / c except im having trouble because violins have tonal qualities!!!!
[a href="index.php?act=findpost&pid=298764"][{POST_SNAPBACK}][/a]

!!!! do they ????
(just kidding, it's just that i tend to interprete multiple exclamation marks as yelling which could easily annoy me - so be warned)

Quote
Is there anyone who would know how to implement this, ive tryed implementing a high pass filter to filter out every thing above 2.5khz (tonal qualities when bowing) and rejoining the signal but it doesnt sound right!
[a href="index.php?act=findpost&pid=298764"][{POST_SNAPBACK}][/a]

Throwing out high frequencies is what a lowpass filter does.

Quote
Basically im asking if there any general algorithms out there that may help?  

Any help would be great...
Cheers

Peter 
[a href="index.php?act=findpost&pid=298764"][{POST_SNAPBACK}][/a]


The pitch can be shifted via time compression/expansion + resampling/interpolating. Time compression/expansion is usually done via overlapped cut & paste of signal blocks. This could be done signal adaptive for better results - ie do a pitch estimantion, create or erase cycles via crossfading/overlapping. The pitch estimation thing will only be feasable for monophonic signals (one voice / note at a time only), though. For a simple formant correction you can apply whitneing and dewhitening filters via LPC (whitening before speed adjustment/interpolation, dewhitening after speed adjutment/interpolating).
Pitch estimation can be done on a lowpassed vesion of the preciction residual. (the prediction residual is the whitened version of the signal which you have to compute anyway to do the formant correction).

MatLab functuions you could use:
- hann/blackman/... (windowing signal parts for LPC analysis)
- lpc (for deriving (de-)whitening filters
- filter (for lowpass filtering the residual / applying (de-)whitening filters)

Knowledge about how speech coding is usually done could be of help in case you want to go the pitch estimation route to improve results.

Things will get quite complicated if your signal contains multiple voices / notes at a time. Pitch estimation will fail and be useless anyway. Another popular approach of deciding where to cut the signal into pieces for pitching music is usually based on how/where the signal volume changes to avoid "transient echo" (while time expansion) or "transient loss" (while time compression).

HTH,
Sebi

Implementing pitch shifting in real time

Reply #2
How have you configured MATLAB to process audio in real time? (by which I assume you mean in via sound card > MATLAB process > out via sound card all at the same time).

You're going to tell me I need to learn or download some functions introduced after MATLAB v5.1, aren't you?

btw (to state the obvious) a google for pitch shift algorithm (or similar) is a great place to start! As is this forum, of course!

Cheers,
David.

Implementing pitch shifting in real time

Reply #3
As SebastianG said, timestretching and resampling is one method to do it. But if you need pitch-shifting only, pure frequency domain methods are probably easier to implement (although they sound in most cases worse than the pure time-domain methods - depending on your input signal).

There are two general classes:
- do a pitchshift by scaling the signal in the frequency domain
- timestretch a signal and resample it to have the right length

These classes can be inverted as well:
- timestretch a signal directly
- scale a signal in the frequency domain and transform back as it were a signal with scalefactor size

And don't forget to use windows and low-pass filters when necessary  !

Just a hint: search for "phase vocoder matlab" and you're done. You can as well search for other methods like PSOLA, ... - or look at the soundstretch library.

There are really tons of information on the internet - and it's not hard to find them 

Hias

Implementing pitch shifting in real time

Reply #4
Quote
How have you configured MATLAB to process audio in real time? (by which I assume you mean in via sound card > MATLAB process > out via sound card all at the same time).


I believe MATLAB supports several DSPs, mainly from texas instruments. I really can't tell if this is a fact or not 'cause I've never worked directly with DSPs, I think I just read that somewhere.

Implementing pitch shifting in real time

Reply #5
Hey Guys,

Thanks alot for your comments,

SabastianG - yea apparently violins contain distinct high frequencies (~3k) that are present when bowing caused from the continuous drag and let go of the bow against the string. (i.e. saw tooth)  along with other resonances of the violin + the fundamental note being played.

2Bdecided - matlab does it but does has some delay, im only doing in matlab because i am 'somewhat' confident using it.

I was think of creating a while loop that only breaks if user presses a key and continously performing stft and going a lpf to work out the pitch scaling and a hpf to store the tonal qualities then outputing the sum of them both??

What do people think? 

Implementing pitch shifting in real time

Reply #6
Quote
SabastianG - yea apparently violins contain distinct high frequencies (~3k) that are present when bowing caused from the continuous drag and let go of the bow against the string. (i.e. saw tooth)  along with other resonances of the violin + the fundamental note being played.
[a href="index.php?act=findpost&pid=298932"][{POST_SNAPBACK}][/a]

What i was trying to say was: If you're only playing one note at a time you could improve the quality of the lapped cut & paste thingy if you do it pitch-adaptive.

Quote
I was think of creating a while loop that only breaks if user presses a key and continously performing stft and going a lpf to work out the pitch scaling and a hpf to store the tonal qualities then outputing the sum of them both??

What do people think? 
[a href="index.php?act=findpost&pid=298932"][{POST_SNAPBACK}][/a]

You only want to "pitch" lower frequencies and keep upper harmonics as they are ? This doesn't seem to make much sense.

Sebi

Implementing pitch shifting in real time

Reply #7
Apparently the violins bowing action (~3kHz) is present at no matter what note your playing, so yeah i was thinking of hpf the 3khz and above...
Intuition would suggest that the higher up the neck of the violin your playing the force applyed by the violinist on the bow would mean that the saw tooth wave would increase in frequency, but apparently it stays constant...


Implementing pitch shifting in real time

Reply #8
You asked for opinions. You got mine. The approach you're heading for will mess with upper harmonics (they won't be at the correct multiple of the fundamental) since there are usually plenty of harmonics above 3 kHz (for violins).

Sebi

Implementing pitch shifting in real time

Reply #9
Definitely -  I'm pretty certain violins play above 1,500Hz (if my maths is correct, that's somewhere vaguely around 2 octaves above middle C), and so even the first harmonic will exceed 3,000Hz.

Implementing pitch shifting in real time

Reply #10
Quote
Apparently the violins bowing action (~3kHz) is present at no matter what note your playing
[a href="index.php?act=findpost&pid=299047"][{POST_SNAPBACK}][/a]

I don't know exactly what you're talking about, despite being a string player!  But I'll go and have a look at what's going on in a minute. If you're talking about the physical friction between the bow and the string, then I would assume that the frequency depends on the speed of bowstroke if nothing else.

Implementing pitch shifting in real time

Reply #11
Quote
Quote
Apparently the violins bowing action (~3kHz) is present at no matter what note your playing
[a href="index.php?act=findpost&pid=299047"][{POST_SNAPBACK}][/a]

I don't know exactly what you're talking about, despite being a string player!  But I'll go and have a look at what's going on in a minute. If you're talking about the physical friction between the bow and the string, then I would assume that the frequency depends on the speed of bowstroke if nothing else.
[a href="index.php?act=findpost&pid=299309"][{POST_SNAPBACK}][/a]


tgoose - I think from what my project supervisor said is that the minimum force applyed on the string to actually make it bow produces the minimum frequency ~3khz which is a saw tooth wave.  You are correct in assuming that the speed of the bowstroke increases the frequency of that saw tooth,  if i could i would attach an attachment to show you guys a somewhat brief report my project supervisor has written? is there anyway i can post an attachment with linking it to a http? 

Implementing pitch shifting in real time

Reply #12
Not sure what you mean with "post an attachment with linking it to a http?", but yes, the forum does allow attachements/uploads for not-too-large files.

Implementing pitch shifting in real time

Reply #13
Quote
Not sure what you mean with "post an attachment with linking it to a http?", but yes, the forum does allow attachements/uploads for not-too-large files.
[a href="index.php?act=findpost&pid=299443"][{POST_SNAPBACK}][/a]


sorry my typing skills are not good and i made a booboo, what i meant about adding attachments (i.e. word docs) is how do i do it without hyperlinking it? 

Implementing pitch shifting in real time

Reply #14
When you write a post there is a "file attachements" section below the edit box. You can browse on your HD for the file you want, and then "add this attachement".

If it doesn't work in this forum section, use the "uploads" forum:
http://www.hydrogenaudio.org/forums/index.php?showforum=35