09.12.2012 Views

The Kyma Language for Sound Design, Version 4.5

The Kyma Language for Sound Design, Version 4.5

The Kyma Language for Sound Design, Version 4.5

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Conditionals<br />

i := 0.<br />

[i 1 s)<br />

varIfTrue: [1 s]<br />

ifFalse: [0.1 * ?dur]<br />

as the value of the attack parameter.<br />

Random Numbers<br />

To obtain random numbers in Smalltalk, you create an object that will supply you with an endless stream<br />

of random numbers. To create a random number generator use<br />

Random newFor<strong>Kyma</strong>WithSeed: 3413.<br />

If you assign the random number generator to a variable, you can ask it <strong>for</strong> the next random value by<br />

sending it the message next.<br />

| r |<br />

r := Random newFor<strong>Kyma</strong>WithSeed: 1002.<br />

4 timesRepeat: [r next].<br />

generates four random numbers between zero and one. <strong>The</strong> following statements,<br />

| r |<br />

r := Random newFor<strong>Kyma</strong>WithSeed: 2530.<br />

1 to: 100 do: [ :i |<br />

a<strong>Sound</strong><br />

start: i s<br />

freq: ((r next * 100) + 500) hz].<br />

creates a sequence of 100 instances of a<strong>Sound</strong>, each with a randomly selected frequency between 500 and<br />

600 hz.<br />

Set the seed to an integer value from 0 to 65535, so the <strong>Sound</strong> will be repeatable.<br />

520

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!