Pitchshifting a live microphone

Is it possible to Pitchshift a live microphone using the Pitchshift UGen and SoundIn? I’m attempting to route the signal to Logic Pro X using an audio interface - Focusrite Scarlett 2i2. I’ll copy + paste the code I have below. When I use s.meter, my input is being picked up by my microphone and when I activate the synth using Synth.new(\mic), I can see the output levels moving too. And when I change the pitchRatio I can sometimes hear it and sometimes can’t. When I do hear it, it sounds like a granular synth, just repeating the words I’m saying in to the microphone and it’s super quiet and only in the left channel. I’d appreciate any help.

ServerOptions.devices;

(
s.options.device = "Scarlett 2i2 USB";
s.options.numOutputBusChannels = 2;
s.options.numInputBusChannels = 2;
s.boot;
)


(
SynthDef.new(\mic, {
	arg in=0, out=0, amp=1, windowSize, pitchRatio, pitchDispersion, timeDispersion;
	var sig;
	sig = SoundIn.ar(in) * amp;
	sig = PitchShift.ar(sig, 2, 3, 0.0, 0.0);
	Out.ar(out, sig);
}).add;
)

Synth.new(\mic);

s.meter;

Server.killAll;

Hi,

So you have declared a lot of arguments for your SynthDef but apart from amp you haven’t put them anywhere.

sig = PitchShift.ar(sig, 2, 3, 0.0, 0.0);

should be

sig = PitchShift.ar(sig, windowSize, pitchRatio, pitchDispersion, timeDispersion);

…if you want to use all the arguments that you declared.

The granular sound you heard is likely because you had windowSize set to 2 while the default value is 0.2.

You should also give some default values to the arguments, like for ex:

arg in=0, out=0, amp=1, windowSize= 0.2, pitchRatio= 1.0, pitchDispersion= 0.0, timeDispersion= 0.0;

Out.ar is only one channel unless you tell it to be more. You can do this by duplicating the channel into an array like Out.ar(out, [sig, sig]); or a very common shortcut that does the same Out.ar(out, sig!2);

This should work:


(
SynthDef(\mic, {
	arg in=0, out=0, amp=1, windowSize= 0.2, pitchRatio= 1.0, pitchDispersion= 0.0, timeDispersion= 0.0;
	var sig;
	sig = SoundIn.ar(in) * amp;
	sig = PitchShift.ar(sig, windowSize, pitchRatio, pitchDispersion, timeDispersion);
	Out.ar(out, sig!2);
}).add;
)

x= Synth(\mic);

x.set(\pitchRatio, 1.5);
x.set(\pitchRatio, 0.6);
x.set(\amp, 1.5);
//etc...

s.meter;
1 Like

Also - I highly recommend a small value for time dispersion - it really helps get rid of the comby artifacts

/*
Josh Parmenter
www.realizedsound.net/josh
*/