Mapping in SuperCollider

496 views Asked by At

I am trying to map amplitude to a synth using a bus in order to smooth out the sine wave (remove high frequencies) based off of semi-random inputs from an outside source, but when I run this code, there is no sound.

s.boot;
(
SynthDef( \cello, {|rate = 440, amp = 0.2|
    var signal;
    signal = SinOsc.ar(rate, 0, amp);
    Out.ar([0,1], signal)}
).add;)

h = Synth( \cello, [ \rate, 440, \amp, 0 ] );

c = Bus.control(s, 2);

c.scope;



Task({
 var counter, pyAmp, newAmp, oldAmp = 0;

 counter = 0;

 {counter < 1}.while ({

  pyAmp = 3.0.rand;
  (pyAmp).postln;

  d = { XLine.ar(oldAmp, pyAmp, 0.1) }.play(outbus: c);
        ("and").postln;
        (oldAmp).postln;
  oldAmp = pyAmp;

  h.map(\amp, d);
  0.1.wait;

 })
}).play;


)
1

There are 1 answers

0
Dan Stowell On

You have at least a couple of problems.

  1. Your first XLine synth tries to do an XLine starting from 0. Absolute zero is a problem in exponential-land, it's impossible. Start from a tiny but positive value instead.
  2. You are creating little XLine synths to try and set the amp, but you're never releasing these synths. Lots of them are building up. Who knows what value that amp is adding up to in the end? You should use doneActions to make the synths free themselves.

Thirdly (but not harmful) there's no point running those XLine synths at audio rate, you may as well use XLine.kr not XLine.ar