| Author |
Message |
mrcold

Joined: Jun 18, 2009 Posts: 157 Location: USA
Audio files: 24
|
Posted: Fri Jun 19, 2009 11:08 am Post subject:
Why does this use so much CPU? |
 |
|
Why does this use so much cpu?
All was fine until I added the 'ch' function at the end.. when I did that the thing ate all of my cpu within about 10 seconds?
Have I done something wrong, or is this just not optimised correctly?
| Code: | // bandlimited ugens (Blit, BlitSaw, BlitSquare)
Blit s => Pan2 p;
p.left => JCRev r1 => dac.left;
p.right => JCRev r2 => dac.right;
// initial settings
.5 => s.gain;
.1 => r1.mix;
.1 => r2.mix;
// an array
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ] @=> int hi[];
[ 0, 2, 4, 7, 9 ] @=> int hi2[];
// set the harmonic
5 => s.harmonics;
// spork the pan control
spork ~ dopan();
//sporkchords
spork ~ chords();
//spork ch
spork ~ ch();
// infinite time loop
while( true )
{
32 => int i;
Std.rand2( 0, 2 ) => int rand;
if( rand == 1 )
{
//<<<"chrom">>>;
while( i > 0 )
{
Std.mtof( 33 + Std.rand2(1,3) * 12 +
hi[Std.rand2(0,hi.cap()-1)] ) => s.freq;
//mess with the rhythm
Std.rand2(0,3) => int rh;
if( rh == 0 )
{
240::ms => now;
i - 4 => i;
}
else
{
120::ms => now;
i - 2 => i;
}
}
}
else
{
//<<<"penta">>>;
while( i > 0 )
{
Std.mtof( 33 + Std.rand2(0,3) * 12 +
hi2[Std.rand2(0,hi2.cap()-1)] ) => s.freq;
120::ms => now;
i - 1 => i;
}
}
}
// pan control
fun void dopan()
{
float t;
while( true )
{
.7 * Math.sin(t) => p.pan;
.005 +=> t;
10::ms => now;
}
}
//chords
fun void chords()
{
TriOsc t1 => Gain g => Envelope e => dac;
TriOsc t2 => g => e => dac;
TriOsc t3 => g => e => dac;
.5 => g.gain;
[ 0, 2, 4, 7, 9 ] @=> int hi2[];
2000::ms => e.duration;
while( true )
{
Std.mtof( 33 + Std.rand2(1,3) * 12 +
hi2[Std.rand2(0,hi2.cap()-1)] ) => t1.freq;
Std.mtof( 33 + Std.rand2(1,3) * 12 +
hi2[Std.rand2(0,hi2.cap()-1)] ) => t2.freq;
Std.mtof( 33 + Std.rand2(1,3) * 12 +
hi2[Std.rand2(0,hi2.cap()-1)] ) => t3.freq;
Std.rand2(0,3) => int chrand;
if( chrand != 3 )
{
.5 => g.gain;
1920::ms => e.duration;
//envelopstart
e.keyOn();
//wait
1920::ms => now;
//envelopstop
e.keyOff();
1920::ms => now;
}
else
{
1920::ms => e.duration;
//envelopstart
e.keyOn();
//wait
1920::ms => now;
//envelopstop
e.keyOff();
now => now;
.3 => g.gain;
}
}
}
fun void ch()
{
while( true )
{
Noise n => ADSR adsr => dac;
.4 => n.gain;
adsr.set(1::ms, 22::ms, .01, 23::ms);
adsr.keyOn();
80::ms => now;
adsr.keyOff();
400::ms => now;
}
}
|
keep in mind that I have only been learning chuck for 2 days... this is just a mutilated version of one of the basic examples (I added some chords, a different scale array that plays randomly every now and then, and the beat)
THANKS
edit... I would also like any helpful comments about how I have put stuff together here... |
|
|
Back to top
|
|
 |
mrcold

Joined: Jun 18, 2009 Posts: 157 Location: USA
Audio files: 24
|
Posted: Fri Jun 19, 2009 11:23 am Post subject:
|
 |
|
... well I figured it out.
the problem is fixed my moving the Noise=>dac, and the adsr.set out of the while loop.
but thanks anyway!
 |
|
|
Back to top
|
|
 |
kijjaz

Joined: Sep 20, 2004 Posts: 760 Location: bangkok, thailand
Audio files: 4
|
Posted: Sat Jun 20, 2009 12:53 am Post subject:
|
 |
|
| wow.. your patch is cute. i hope i can listen to more of your ChucK sound soon. keep posting heheh. |
|
|
Back to top
|
|
 |
mrcold

Joined: Jun 18, 2009 Posts: 157 Location: USA
Audio files: 24
|
Posted: Sat Jun 20, 2009 7:29 am Post subject:
|
 |
|
Thanks
I'm sure I'll need more help eventually |
|
|
Back to top
|
|
 |
mrcold

Joined: Jun 18, 2009 Posts: 157 Location: USA
Audio files: 24
|
|
|
Back to top
|
|
 |
Inventor

Joined: Oct 13, 2007 Posts: 5457 Location: San Antonio, Tx, USA
Audio files: 236
|
Posted: Mon Jun 22, 2009 5:58 pm Post subject:
|
 |
|
I really like this song, I will try to play it on the next ChucK Show.
Les _________________ No matter how much society beats it out of me, I STILL want to make the world a better place. I am sick of the abuse yet I am powerless to stop it. |
|
|
Back to top
|
|
 |
mrcold

Joined: Jun 18, 2009 Posts: 157 Location: USA
Audio files: 24
|
Posted: Mon Jun 22, 2009 6:00 pm Post subject:
|
 |
|
word!
I am working on another one which is pretty much the same thing but with a breakbeat in it.. If I get it done I'll share it  |
|
|
Back to top
|
|
 |
|