国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

ChucK初步(7)

2019-11-11 07:40:45
字體:
供稿:網(wǎng)友

manipulating time

time and durationOperations (arithmetic)the keyWord ‘now’advancing timePRoperties

Manipulating Time

ChucK is a strongly-timed language, meaning that time is fundamentally(根本地) embedded(嵌入) in the language. ChucK allows the programmer to explicitly(明確的) reason about time from the code. This gives extremely flexible(靈活的) and precise(精確的) control over time and (therefore) sound synthesis(綜合).

In ChucK:

time and duration are native types in the languagekeyword now holds the current logical timetime is advanced (and can only be advanced) by explicitly(顯式地) manipulating(操縱) nowyou have flexible(靈活的) and precise(精確的) control

time and duration

Time and duration are native types in ChucK.

`time` represents an absolute(絕對(duì)的) point in time (from the beginning of ChucK time). 時(shí)間點(diǎn)`dur` represents a duration (with the same logical units as time). 時(shí)間段// a duration of one second1::second => dur foo;// a point in time (duration of foo from now)now + foo => time later;

Later in this section, we outline(概述) the various arithmetic operations(各種數(shù)學(xué)運(yùn)算) to perform on time and duration.

Durations can be used to construct new durations, which then be used to inductively(歸納地) construct yet other durations. For example:

// .5 second is a quarter.5::second => dur quarter;// 4 quarters is whole4::quarter => dur whole;

By default, ChucK provides these preset(預(yù)先裝置的) duration values:

samp : duration(持續(xù)) of 1 sample(樣本 in ChucK timems : duration of 1 millisecond(毫秒)second : duration of 1 secondminute : 1 minutehour : 1 hourday : 1 dayweek : 1 week

Use these to represent any duration.

// the duration of half a sample.5::samp => dur foo;// 20 weeks20::week => dur waithere;// use in combination2::minute + 30::second => dur bar;// same value as above2.5::minute => dur bar;

operations on time and duration (arithmetic)

In ChucK, there are well-defined(定義明確的) arithmetic operations on values of type time and dur.


example 1 (time offset(偏移)):

// time + dur yields timenow + 10::second => time later;

example 2 (time subtraction):

// time - time yields durlater - now => dur D;

example 3 (addition):

// dur + dur yields dur10::second + 100::samp => dur foo;

example 4 (subtraction):

// dur - dur yields dur10::second - 100::samp => dur bar;

example 5 (division):

// dur / dur yields number10::second / 20::ms => float n;

example 6 (time mod):

// time mod dur yields dur now % 1::second => dur remainder;

example 7 (synchronize to period):

// synchronize to period of .5 second.5::second => dur T;T - (now % T) => now;

example 8 (comparison(比較) on time):

// compare time and timeif( t1 < t2 ) // do something...

example 9 (comparison on duration:

// compare dur and durif( 900::ms < 1::second ) <<< "yay!" >>>;

the keyword ‘now’

The keyword now is the key to reasoning about and controlling time in ChucK.思考控制時(shí)間的關(guān)鍵

Some properties(屬性) of now include:

now is a special variable(變量) of type time.now holds the current ChucK time (when read).modifying now has the side effects(副作用) of: advancing time (see below);suspending(暫停) the current process (called shred) until the desired time is reached - allowing other shreds and audio synthesis to compute; the value of now only changes when it is explicitly(明確地) modified(改動(dòng)).

(also see next section on advancing time).

Example:

// compute value that represents "5 seconds from now"now + 5::second => time later;// while we are not at later yet...while( now < later ){ // print out value of now <<< now >>>; // advance time by 1 second 1::second => now;}

advancing time(推進(jìn)時(shí)間)

Advancing time allows other shreds (processes進(jìn)程) to run and allows audio to be computed in a controlled manner. There are three ways of advancing time in ChucK:

chucking (=>) a duration to now: this will advance time by that duration.chucking (=>) a time to now: this will advance time to that point. (note that the desired time must be later than the current time, or at least be equal to it.)chucking (=>) an Event to now: time will advance until the event is triggered(引發(fā)). (also see event)

advancing time by duration

// advance time by 1 second1::second => now;// advance time by 100 millisecond100::ms => now;// advance time by 1 samp (every sample)1::samp => now;// advance time by less than 1 samp.024::samp => now;

advancing time by absolute(絕對(duì)的) time

// figure out whennow + 4::hour => time later;// advance time to laterlater => now;

A time chucked to now will have ChucK wait until the appointed(約定的) time. ChucK never misses an appointment (unless it crashes)! Again, the time chucked to now must be greater than or equal to now, otherwise an exception(異常) is thrown.

advancing time by event

// wait on evente => now;

The advancement(推進(jìn)) of time can occur(發(fā)生) at any point in the code.

// our patch: sine oscillator -> dacSinOsc s => dac;// infinite time loopwhile( true ){ // randomly choose frequency from 30 to 1000 Std.rand2f( 30, 1000 ) => s.freq; // advance time by 100 millisecond 100::ms => now;}

Furthermore(此外), there are no restrictions(限制) (other than underlying floating point precision除了基本的浮點(diǎn)精度) on how much time is advanced. So it is possible to advance time by a microsecond(微秒), a samp, 2 hours, or 10 years. The system will behave accordingly(相應(yīng)地) and deterministically(確切地).

This mechanism(機(jī)制) allows time to be controlled at any desired rate, according to any programmable(可編程的) pattern. With respect to(關(guān)于) sound synthesis(合成), it is possible to control any unit generator at literally(字面地) any rate, even sub-sample rate.

The power of the timing mechanism is extended(延伸) by the ability to write parallel(并行) code, which is discussed in concurrency(并發(fā)性) and shreds.

properties

(see above)


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 托克逊县| 万山特区| 宁南县| 唐河县| 刚察县| 旺苍县| 德清县| 开远市| 临沭县| 吴旗县| 昭平县| 亚东县| 崇州市| 体育| 成都市| 丹巴县| 河源市| 保靖县| 赤水市| 蕲春县| 乌兰县| 阿拉尔市| 六枝特区| 伊宁市| 普定县| 囊谦县| 扎鲁特旗| 临潭县| 屏南县| 洛扎县| 潞城市| 商洛市| 扬中市| 仙桃市| 格尔木市| 大田县| 康定县| 凌源市| 西充县| 西藏| 浙江省|