More Code – trying to loop and layer in ChucK

I’m still battling with ChucK. I can now record and play back in real time, but can’t loop. Record and play back in real time:

 

adc => LiSa loopme => dac;

//alloc memory

60::second => loopme.duration;

//set number of layers

10 => loopme.maxVoices;

// print get voice

<<< loopme.getVoice >>>;

//start recording input

loopme.record(1);

<<< “recording” >>>;

2000::ms => now; loopme.play(1);

2000::ms => now; loopme.play(0);

//10 sec later, stop recording //10000::ms => now;

//loopme.record(0); 500::ms => now;

 

However, looping doesn’t work and I can’t work out why because I don’t understand all the syntax in the example file… Here’s my messy attempt.

adc => Envelope e => LiSa loopme => dac;

//alloc memory
10::second => loopme.duration;
//confirm that the length of the buffer is what you expect
<<<“buffer duration = “, loopme.duration() / 44100.>>>;
//set number of layers
10 => loopme.maxVoices;
// print get voice
<<< loopme.getVoice >>>;

//440. => loopme.freq;
//0.2 => loopme.gain;

//set times for recording fade in/out and sample loop length
100::ms => dur recfadetime;
2000::ms => dur mylooplen;
e.duration(recfadetime);

//start recording input; record 2 seconds worth
loopme.record(1);
e.keyOn(); //can also do without the Envelope and use loopme.recramp(dur) to set a recording ramp
//1000::ms => dur loopme.recramp;
now + (mylooplen – recfadetime) => time later;
while(now < later) {

//    pitchmod.value() => loopme.freq;
1000::ms => now;
//2000::ms => now;
}
e.keyOff();
recfadetime => now;
loopme.record(0);

///WHY ISN’T THIS PLAYING BACK?!?!?!?!

<<< “recording” >>>;

//disconnect input and hangout a bit
loopme =< dac;
1000::ms => now;
<<< “hanging out” >>>;

//now, manipulate the sample
//    get a voicenumber; note that this voice won’t actually be reserved until you play it
loopme.getVoice() => int voice1;

<<< “getting voice number 1” >>>;

//we’ll play voice 1 forward, and then crossfade it with voice 2 backwards
loopme.play(voice1, 1);

<<< “play voice 1” >>>;
//(mylooplen – recfadetime) => now;

//just as voice 1 is going to fade, bring in voice 2
loopme.getVoice() => int voice2;
loopme.rate(voice2, 1.);
loopme.playPos(voice2, mylooplen);
//loopme.voiceGain(voice2, 0.2);
loopme.play(voice2, 1);

//wait until voice 1 had finished fading, then turn off
recfadetime => now;
loopme.play(voice1, 0);

//wait for voice 2 to finish
2000::ms => now;

//——–

////start recording input
//loopme.loopRec;
//<<< “recording” >>>;

//2000::ms => now;

//loopme.loopEndRec;

//loopme.play(1);

//2000::ms => now;

//loopme.play(0);

//10 sec later, stop recording
//10000::ms => now;
//loopme.record(0);

500::ms => now;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s