<< Chapter < Page | Chapter >> Page > |
Previous modules have created only monaural sound. This module also explains how to create stereo sound.
This program requires the following five classes:
I won't bore you by repeating the discussion from earlier modules. The first three classes in the above list are completely unchanged from the module titled Jbs2010-Your First Sound Program . By now, you probably have source code files and compiled class files for those three classes. If not, you can obtain the sourcecode from the earlier module titled Jbs2010-Your First Sound Program . Because they haven't changed, I won't discuss these classes further in this module.
The class named MusicComposer07 differs from the previous version only in the following respects:
Therefore, I also won't discuss this class further in this module.
A complete listing of the class named AudioGraphSinusoidal is provided in Listing 10 . I will break this class down and explain it in fragments.
The sound that you heard when you listened to the audio file named AudioGraphSinusoidal was produced by the getMelody method of the AudioGraphSinusoidal class. The AudioGraphSinusoidal class begins in Listing 1 and the getMelody method begins in Listing 2 .
The code in Listing 1 differs from the corresponding WhiteNoise code from the earlier module only with respect to the name of the class.Therefore, I won't discuss it further.
Listing 1 . Beginning of the class named AudioGraphSinusoidal. |
---|
import java.io.*;
import java.nio.*;import java.util.*;
public class AudioGraphSinusoidal extends AudioSignalGenerator02{public AudioGraphSinusoidal(AudioFormatParameters01 audioParams,String[] args,byte[] melody){super(audioParams,args,melody);
}//end constructor |
This method returns a melody array that will play an 8-second melody consisting of 32 pulses at different frequencies. The frequencies of the pulses are centered on middle-C (261.63 Hz). The frequency deviation from middle-C versus time is based on a sinusoidal function with a frequency of 0.5 Hz.
Each pulse represents one point on a graph of the sinusoid. Pulses with frequencies at or above middle-C are delivered to the left speaker. Pulses with frequencies below middle-C are delivered to the right speaker.
The audio output can be thought of as an audio representation of a graph of a sinusoid. Pulses with frequencies above middle-C represent points on the positive lobe of the sinusoid. Increasing pitch represents increasing amplitude on the graph of the sinusoid. Pulses with frequencies below middle-C can be thought of as representing points on the negative lobe of the sinusoid. In this case, decreasing pitch represents points on the sinusoid that are further from the horizontal axis in the negative direction. Pulses with a frequency of middle-C can be thought of as representing points on the horizontal axis with a value of zero.
Notification Switch
Would you like to follow the 'Accessible objected-oriented programming concepts for blind students using java' conversation and receive update notifications?