Sound

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 whole note lasts twice as long as a half note half note which is twice as long as a quarter note quarter note which (of course) is twice as long as an eighth note eighth note.

 

 Note  Frequency (Hz)
Middle C 262
D 294
E 330
F 349
G 392
A 440
B 494
C 523

A good timing is:
whole note a whole note lasts 2 seconds (2000 milliseconds),
half note a half note one second, (1000 milliseconds)
quarter note quarter notes a half of a second, etc.

Questions:

  1. Can the robot play 2 tones at the same time? How can you prove or disprove it? Create a program that demonstrates the answer.
  2. What is the lowest or highest sound you can hear the robot play? Create a program that demonstrates your answer.

Sound files:

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