ChucKå ¥é #7 - ãã«ããã ãã£ã©(shred, not thread)
ååã¯çºé³é¨ãé¢æ°ã«åãåºãã¾ãããã§ãå¼ã³åºãã¨é³ããªãã¾ãããé³ãé³´ãå§ãã¦æ¶ããã¾ã§å¼ã³åºãå ã¯ãããã¯ããã¦ãã¾ã(åæ)ã
åé³ã¯ãã¨ãããããã§ã¯è¤æ°ã®ãã¼ãã§æ¼å¥ããã¨ãä¸å¯è½ã§ããéåæã§åä½ãããããã«ããã«ãã¹ã¬ããã§ãããããmulti-shredã§ãã ChucKã§ã¯ Threadã¨ãã表ç¾ã®ãããã« Shred ã¨ããå¼ã³æ¹ãããããã§ãããã¸ã£ã¬ã§ã¯ãªãã¨æãã¾ãã
ã¾ããååã®ã½ã¼ã¹ããã®ã¾ã¾å¼ç¨ãã¾ãã
fun void buzz( float hz ) { SinOsc s => dac; hz => s.freq; SawOsc env; env => blackhole; 0.0 => env.width; 0.8 => env.freq; 1::samp => now; while (true) { env.last() => s.gain; if (env.last() <= 0) { break; } 1::ms => now; } } buzz( Std.mtof(60) ); buzz( Std.mtof(64) ); buzz( Std.mtof(67) ); buzz( Std.mtof(71) );
ããã¯åé³ãã¤é³´ãã¾ããä¸çªä¸ã®4è¡ã次ã®ããã«æ¸ãæãã¦ã¿ã¦å®è¡ãã¦ã¿ã¦ãã ããã
spork ~ buzz( Std.mtof(60) ); spork ~ buzz( Std.mtof(64) ); spork ~ buzz( Std.mtof(67) ); spork ~ buzz( Std.mtof(71) );
spork ~ é¢æ°å¼ã³åºã() ã§ããã®é¢æ°å¼ã³åºããéåæã«ãã¤ã¾ãShredãç«ã¡ä¸ãã¦å®è¡ãããã¨ããæ示ã«ãªãã¾ãã
ãããªã«ãé³´ãã¾ãããããããã®ã¯ãããããã®é¢æ°å¼ã³åºãã¯éåæã«å®æ½ããã¦ããããããã®ãã¨ã¡ã¤ã³ã®å¦çã®æµãã¯å³åº§ã«çµäºãããªã«ãé³´ããªãããã§ãã
ãªã®ã§ã以ä¸ã®è¡ã追å ãã¦ã¿ã¦ãã ãã
3::second => now;
ãã説æã¯ä¸è¦ã§ããã
åé³ããªãã¾ãããï¼ miniAudicleã®Virtual Machineã¦ã¤ã³ãã¦ãè¦ãã¨ä¸ç¬5shredç«ã¡ä¸ããã®ãè¦ãã¾ãã
ããã§åé³ãé³´ãããããã«ãªãã¾ããï¼ï¼
ä»åº¦ã¯ãã®åé³(Major7thã®åºæ¬å½¢)ã®çºé³ãããã«é¢æ°ã«ãã¦ãã¾ãã¾ãããã
fun void maj7( int root ) { spork ~ buzz( Std.mtof(root) ); // Root spork ~ buzz( Std.mtof(root+4) ); // M3 spork ~ buzz( Std.mtof(root+7) ); // P5 buzz( Std.mtof(root+11) ); // M7 }
ãã£ã¨ãæå¾ã ã shredãä½ããã«åæå®è¡ãã¦ãã¾ãããè¦ããã«ããã¯4ã¤ã®buzz()å¼ã³åºããé³ãæ¶ããã¿ã¤ãã³ã°ãåããªã®ã§ããã®é¢æ°èªä½ãæ¶é³ã®ã¿ã¤ãã³ã°ã«ãããã¦çµäºããããã«ããæ¸ãã¦ãã¾ãã
Javaãªã©ã»ãã®è¨èªãªã Thread#join() ã®ãããªãã®ã使ã£ã¦çµäºå¾ ã¡ãããã®ãæ®éãã¨æãã¾ãããChucKã ã¨join()ããããããããããªãã£ãã®ã§ãããªæ¸ãæ¹ããã¦ã¿ã¾ããã
ãã£ããå¼ã³åºãã¦ã¿ã¾ãããã
maj7( 60 ); // C maj7( 65 ); // F maj7( 58 ); // Bb maj7( 63 ); // Eb
ã¯ãï¼ãã㧠CMaj7âFMaj7âBâMaj7âEâMaj7 ã¨ãåé³ã®ã·ã¼ã±ã³ã¹ãä½ãã¾ããï¼
ã¡ãã£ã¨å¿ããªãã®ã§ãã¨ã³ããã¼ãã«ä½¿ã£ã¦ããªã·ã¬ã¼ã¿ã®freqãä¸ãã¦èª¿æ´ã¨ããã¦ã¿ã¦ãã ãããã
ããã¾ãããã¼ï¼ã¾ã次åï¼
â»ããããã®ããã«ä»æ¥ã®çµæã®å ¨ã½ã¼ã¹ã³ã¼ã
fun void buzz( float hz ) { SinOsc s => dac; hz * 2 => s.freq; SawOsc env; env => blackhole; 0.0 => env.width; 0.4 => env.freq; 1::samp => now; while (true) { env.last() => s.gain; if (env.last() <= 0) { break; } 1::ms => now; } } fun void maj7( int root ) { spork ~ buzz( Std.mtof(root) ); spork ~ buzz( Std.mtof(root+4) ); spork ~ buzz( Std.mtof(root+7) ); buzz( Std.mtof(root+11) ); } maj7( 60 ); maj7( 65 ); maj7( 58 ); maj7( 63 );