[linux-audio-dev] How hard is it to write a pitch shifter?

Earle earle at ezi123.com
Wed Apr 7 04:29:25 UTC 2004

Im new to audio dev and to linux and am using SoundTracker as my Fruiyloops
replacement. I have done  a _little_ bit of dsp programming, but really want
to learn more - hence this question!

I love trackers, and use them to nut out ideas. I record loops in to
soundtracker from my record player, and if it works in the song then I
record them agin with Rezound to do necessary processing from there.

But ST doesnt support plugins, and I need to be able to do a "quick and
dirty" pitchshift on the samples to see if it's gunna fit musically in the

I tracked down a bit of code in ST that does a simple fade of the currently
selected data. I want to change this to do a basic pitchshift.

    p = current_sample->sample.data;
    p += ss;
    for(i = 0; i < se - ss; i++) {	//ss = selection start, se= selection
	double q = *p;


	*p++ = CLAMP((int)q, -32768, +32767);

I found and implemented this bit of code for resampling, which changes the
pitch, but also the time

for(i=0; i <= MaxSamples; i++) {
	processed_buf[i]= unprocessed_buf[(int) j];
    	j = j + pitch;
    	if (j > MaxSamples) break;

But I cant find out how to deal with the missing data that is removed - to
keep the original length. Is there a (n easy) way to do this? I really dont
care too much about artifacts as it is just to get an idea of the loop at
that pitch. or should I skip pitchshifters until I learn the basics?!

More information about the Linux-audio-dev mailing list