Mic with sensor control for pitch shift

Hello, I currently have an Arduino 1 with a trimmer (soon to be conductive cord sensor) to control certain parameters from the voice. The Arduino and the serial port to SC are working ok, and I can hear some shifting in the pitch according to the trimmer, but after some seconds, all I hear is a pop sound on my headphone. I assume it has to do with timing and lagging issues but I am unsure how to solve them.
My mic is currently on a Focusrite on one port, and the Arduino on another.

(
~port= SerialPort.new(
“/dev/cu.usbmodem141401”,
9600
);
)

(
~string= String.new;
Tdef(\readValues, {
{
~ascii = ~port.read;
if (~ascii.notNil) {
~ascii = ~ascii.asAscii;

  case

  	{~ascii.isDecDigit or: { ~ascii.isPunct } }
  	{~string = ~string.add(~ascii)}

  	{~ascii.asAscii.isPunct}
  	{~intArray = ~intArray.add(~ascii.asAscii)}

  	{~ascii.asAscii.isAlpha}
  	{
  		~val = ~string.asFloat;
  		~string= String.new;
  	}

  }
  }.loop;

}).play;
)

~val;

(
~mic= {
|in=0, out=0, amp=0.3, pan=0.7, ratio=0.0, dispP = 0.0, dispT = 0.0, mix = 0.7, mul = 1|
var sig, delay, pitchshift;
sig=SoundIn.ar(in!2);
pitchshift = PitchShift.ar(sig, 0.2, ratio, dispP, dispT, mul);
sig = XFade2.ar(sig, pitchshift,mix);
Out.ar(out, Pan2.ar(sig, pan));
}.play;
)

(
Tdef(\filterSweep, {
{
~mic.set(\dispP, ~val.linexp(0.0, 1.0, -1, 0.5));
0.01.wait;
}.loop;
}).play
)

Is there any work around this? It seems to work if it wasn’t for that big issue
Thanks!

Have you tried printing the value of ~val in your Tdef to make sure that there are no circumstances in which it becomes something that is not a value between 0 and 1?

1 Like

Hey thanks for answering!
Yes, the values are normalised between 0 and 1 from Arduino, and the tops that I got (I am using the rate of change of the trimmer instead of the sensing values in themselves) is like 0.50 or so. Maybe it has something to do with that?
Like the abrupt change of information?
I tried changing the wait method in the filterSweep Tdef but it doesn’t change at all.

I’m unsure on how to check what’s going on

The “exp” part of linexp expects two nonzero real numbers of the same sign. You can’t have an exponential function ranging from -1 to 0.5. Maybe use lincurve instead?

1 Like

Hey, yes! You’re right, it’s working perfectly now! Thanks