09.04.2016 Views

www.ebook777.com

Make_Getting_Started_with_Processing_Second_Edition

Make_Getting_Started_with_Processing_Second_Edition

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.

186 Getting Started with Processing<br />

<strong>www</strong>.<strong>ebook777.com</strong><br />

value of the x variable is at the edges of the screen. If the sound<br />

were played each time through draw(), the sound would restart<br />

60 times each second and wouldn’t have time to finish playing.<br />

The result is a rapid clipping sound. To play a longer sample<br />

while a program runs, call the play() or loop() method for that<br />

sound inside setup() so the sound is triggered only a single<br />

time.<br />

The SoundFile class has many methods to control<br />

how a sound is played. The most essential are<br />

play() to play the sample a single time, loop() to<br />

play it from beginning to end over and over, stop() to<br />

halt the playback, and jump() to move to a specific<br />

moment within the file.<br />

Example 13-2: Listen to a Microphone<br />

In addition to playing a sound, Processing can listen. If your<br />

computer has a microphone, the Sound library can read live<br />

audio through it. Sounds from the mic can be analyzed, modified,<br />

and played:<br />

import processing.sound.*;<br />

AudioIn mic;<br />

Amplitude amp;<br />

void setup() {

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

Saved successfully!

Ooh no, something went wrong!