Hi Folks! I'm needing help understanding what the code for the frequency down below in bold text is doing. Context: I'm trying to build a code that will randomly pick frequencies and rhythms within a given range. As time passes my goal is to write a code that will also allow the frequencies and rhythms to change. I know I'm not ready to understand how to code this yet as I am teaching myself at my own pace. But I would like some help if maybe someone could talk me through what the frequency portion of this code is doing. I took the frame of most of my code from a ChucK example and am changing it for a composition of mine. I don't understand the relationship between the scale part and the freuency part. I don't understand the Math.pow. I do understand math.random2, int, and freq. Thank you much!! // Sitar Sitar sit => JCRev r => Echo a => dac; // gain .56 => r.gain; // reverb mix 1.12 => r.mix; // max delay for echo 1120::ms => a.max; // set delay for echo 112::ms => a.delay; // initial effect mix 0.0 => a.mix; *// scale* *[ 15 ] @=> int scale[];* *// freq* * scale[Math.random2(0,scale.cap()-1)] => int freq;* * 220.0 * Math.pow( 1.05946, (Math.random2(0,2)*12) + freq ) => sit.freq;* // loop while( true ){ //pluck Math.random2f( 0.1, 0.9 ) => sit.noteOn; //time Math.random2f( .01, 1000 )::ms => now; } -- J. Alexander Diaz www.diazsounds.com MFA Student - Music Composition jalexander@diazsounds.com [image: VCFA] http://vcfa.edu/
Hi, I think you meant to put the frequency generation inside of the loop? Also, why don't you add some more steps to your 'scale' array ? For converting pitches: Std.mtof converts midi-values (ranged 0-128, 69 being A4) to standard tempered scale frequencies, bypassing your need to use Math.pow etc... You could just do: 69 => Std.mtof => sit.freq You may want to read the ChucK manual, which covers the basics much better then I could explain in a single email ! Happy chucking, Casper // Sitar Sitar sit => JCRev r => Echo a => dac; // gain .56 => r.gain; // reverb mix 1.12 => r.mix; // max delay for echo 1120::ms => a.max; // set delay for echo 112::ms => a.delay; // initial effect mix 0.0 => a.mix; // scale [ 1,5,6,7,15 ] @=> int scale[]; // loop while( true ){ // freq scale[Math.random2(0,scale.cap()-1)] => int freq; 220.0 * Math.pow( 1.05946, (Math.random2(0,2)*12) + freq ) => sit.freq; //pluck Math.random2f( 0.1, 0.9 ) => sit.noteOn; //time Math.random2f( .01, 1000 )::ms => now; }
On 8 jun. 2015, at 06:26, J Alexander Diaz
wrote: // freq
scale[Math.random2(0,scale.cap()-1)] => int freq;
220.0 * Math.pow( 1.05946, (Math.random2(0,2)*12) + freq ) => sit.freq;
It's just the formula to calculate semitones within the equal temperatment tuning: http://en.wikipedia.org/w/index.php?title=Equal_temperament#Twelve-tone_equa... Math.pow(...) is simply the exponent .... On 08.06.2015 14:38, Casper Schipper wrote:
Hi, I think you meant to put the frequency generation inside of the loop? Also, why don't you add some more steps to your 'scale' array ?
For converting pitches: Std.mtof converts midi-values (ranged 0-128, 69 being A4) to standard tempered scale frequencies, bypassing your need to use Math.pow etc...
You could just do: 69 => Std.mtof => sit.freq
You may want to read the ChucK manual, which covers the basics much better then I could explain in a single email !
Happy chucking, Casper
// Sitar
Sitar sit => JCRev r => Echo a => dac;
// gain
.56 => r.gain;
// reverb mix
1.12 => r.mix;
// max delay for echo
1120::ms => a.max;
// set delay for echo
112::ms => a.delay;
// initial effect mix
0.0 => a.mix;
// scale
[ 1,5,6,7,15 ] @=> int scale[];
// loop
while( true ){ // freq
scale[Math.random2(0,scale.cap()-1)] => int freq;
220.0 * Math.pow( 1.05946, (Math.random2(0,2)*12) + freq ) => sit.freq;
//pluck
Math.random2f( 0.1, 0.9 ) => sit.noteOn;
//time
Math.random2f( .01, 1000 )::ms => now;
}
On 8 jun. 2015, at 06:26, J Alexander Diaz
mailto:jalexander@diazsounds.com> wrote: *// freq*
*scale[Math.random2(0,scale.cap()-1)]=>intfreq;*
* 220.0*Math.pow(1.05946,(Math.random2(0,2)*12)+freq)=>sit.freq;*
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
participants (3)
-
Casper Schipper
-
J Alexander Diaz
-
Niklas Reppel