The Finch allows you to play simple sounds.
The playTone() and buzz() methods require a frequency(f) and duration(d) for each tone you want to play.
The higher the frequency the higher the note.
The longer the duration, the longer the note will play.
This program will play a series of 3 tones: (Test it to see if your speakers are turned on)
import edu.cmu.ri.createlab.terk.robot.finch.Finch; public class SoundTest{ public static void main(String[] args){ Finch musician = new Finch(); musician.playTone(300,500); // frequency 300, duration 1/2 second musician.playTone(400,500); // frequency 400, duration 1/2 second musician.playTone(500,1000); // frequency 500, duration 1 second musician.quit(); System.exit(0); }}
Write a program to play this song:
B A G, B A G, G G G G A A A A, B A G
The whole note lasts twice as long as a half note which is twice as long as a quarter note which (of course) is twice as long as an eighth note .
|
A good timing is: |
The Finch can also play music files on the computer speaker using the playClip method.
playClip(nameOfFile)
Plays a wav file over computer speakers place the audio file in the same folder as your program