I have a few questions:
- Do you want to do it in real time?
- Should the variable
sigIn
in the following example be any other UGgen or input signal via SoundIn.ar?
(
{ var sigIn, sigOut, ampFollower;
sigIn = SinOsc.ar(2); // sigIn = SoundIn.ar(0);
ampFollower = Amplitude.ar(sigIn, 1e-4, 1e-4).abs > 0.5;
sigOut = ampFollower.if(
sigIn,
SinOsc.ar(0)
)}.plot(1)
)
I think it seems very difficult to do it in real time.
There might be several ways to do it if you do not need it in real time.
-
If you are using a particular waveform, you could use a buffer via a wavetable or signal, then read the buffer using BufRD
or PlayBuf
. To achieve your purpose, you can have BufRD
(or PlayBuf
) jump from the index (or sample frame) of c
to the index (or sample frame) of d
. I do not know if it could seamlessly work.
-
If you are using any signal, including SoundIn
, we should be concerned with time! So we should use RecordBuf
. Its argument run
makes the recording pause.
-
As far as I know, SC can pause a node with Pause
and a synth itself with PauseSelf
, but SC does not seem to be able to pause a UGen inside a running synth. So we should use Bus.audio
to separate the âsound generationâ and ârecording buffersâ if necessary.
The code below is the second way:
(
s.waitForBoot{
var duration, buffer;
duration = 1;
buffer = Buffer.alloc(s, s.sampleRate * duration);
SynthDef(\test, {
var signal, ampFollower, recorder;
signal = SinOsc.ar(2);
ampFollower = Amplitude.ar(signal, 1e-4, 1e-4).abs > 0.5;
recorder = RecordBuf.ar(signal, buffer, run: ampFollower, loop: 0, doneAction: Done.freeSelf)
}).add;
s.sync;
Synth(\test);
duration.wait;
buffer.plot
}
)
To compare input waveform and output waveform:
(
s.waitForBoot{
var duration, bufferIn, bufferOut, buffers;
duration = 1;
# bufferIn, bufferOut = { Buffer.alloc(s, s.sampleRate * duration, numChannels: 1) } ! 2;
SynthDef(\test, {
var signal, ampFollower, recorderInput, recorderOutput;
signal = SinOsc.ar(2);
ampFollower = Amplitude.ar(signal, 1e-4, 1e-4).abs > 0.5;
recorderInput = RecordBuf.ar(signal, bufferIn, loop: 0);
recorderOutput = RecordBuf.ar(signal, bufferOut, run: ampFollower, loop: 0, doneAction: Done.freeSelf)
}).add;
s.sync;
Synth(\test);
duration.wait;
buffers = [[], []];
bufferIn.loadToFloatArray(action: { |array| buffers.put(0, array) });
bufferOut.loadToFloatArray(action: { |array| buffers.put(1, array) });
buffers.plot
}
)
Sorry for not giving the draft based on other ways. I have other things to do, but this thread is very interesting, so I thought about it for a moment.