A script that used to work using PitchShiftPA doesn't work anymore

Hi there!
I’m very new to supercollider and I hope somebody here can help me.
A few years back I wrote a script that worked very well. A few weeks ago I wanted to revisit the script but I couldn’t get it to work. I tried some things I googled but to no avail. In other words: I’m stuck.
This is the script:

s.boot;
MIDIClient.init;
MIDIIn.connect(0,4);
(
~noten = Array.newClear(128);

MIDIdef.noteOn("TestOn", { | vel, noteNum |
	~noten[noteNum] = Synth.new("Stimme", ["midiNote", noteNum])
 });

MIDIdef.noteOff("TestOff", { | vel, noteNum |
	~noten[noteNum].release;
});

SynthDef.new("Stimme", { | midiNote |
	var in, out, freq, env;
	in = SoundIn.ar(0);
	freq = Pitch.kr(in)[0];
	env = EnvGate.new(0, nil, 0.1);
	out = Mix.new(PitchShiftPA.ar(in, freq,(midiNote.midicps/freq), 1) * env );
	Out.ar([0,1], out)
}).add;
)

It should pitch shift the incoming signal from the microphone to the midi notes I’m pressing on my keyboard which it used to do but it doesn’t do it anymore. Instead I’m hearing short notes that are not pitch shifted once I press a key. What am I doing wrong?
cheers, nils

I am not sure where the class PitchShiftPA is coming from, it is not part of SC Vanilla (PitchShift is). Do you have PitchShiftPA installed? (Check if the name turns blue in the editor)

Yes, it is installed. I do get sound out of the script, but not the sound I had before. As I wrote earlier I only get short sounds that are not pitched.

I’m not entirely sure why but some of the numbers received in the pitchRatio argument of PitchShiftPA seems to be causing it to misbehave. If we constrain them to “safe” values for pitch shifting with a clip method it seems to be able to run alright. I’ve not tested it thoroughly though.

out = PitchShiftPA.ar(in, freq,(midiNote.midicps/freq).clip(0.01, 10), 1) * env;

(also you don’t need the Mix.new since it’s only one channel, although it didn’t make any real difference)

1 Like

Thanks a lot!
I couldn’t have come up with that solution myself. You made my day, Thanks again :slight_smile:
cheers, nils

Hello @Thor_Madsen,

Here it is: GitHub - dyfer/PitchShiftPA: Phase-Aligned Pitch and Formant Shifter

1 Like