public class ToneEmitter
extends java.lang.Object
implements java.lang.Runnable
Modifier and Type | Field and Description |
---|---|
static double |
BUFFER_DURATION |
static double |
NOTE_A |
static double |
NOTE_ASHARP |
static double |
NOTE_B |
static double |
NOTE_C |
static double |
NOTE_CSHARP |
static double |
NOTE_D |
static double |
NOTE_DSHARP |
static double |
NOTE_E |
static double |
NOTE_F |
static double |
NOTE_FSHARP |
static double |
NOTE_G |
static double |
NOTE_G_BELOW_C |
static double |
NOTE_GSHARP |
static int |
SAMPLE_SIZE |
static int |
SAMPLING_RATE |
static int |
SINE_PACKET_SIZE |
Constructor and Description |
---|
ToneEmitter()
Construct an Emitter.
|
Modifier and Type | Method and Description |
---|---|
double |
getFrequency()
Return the frequency of the sound currently being generated.
|
double |
getVolume()
Return the current volume of the sound being generated.
|
static void |
main(java.lang.String[] args)
A simple test program to illustrate how to play a tune.
|
void |
play(double note)
Play a frequency for one second.
|
void |
play(double note,
double duration)
Play a frequency for a given number of seconds
|
void |
run()
This is the thread that services the output channel.
|
void |
setFrequency(double frequency)
Set the frequency of the sound to be generated.
|
void |
setVolume(double volume)
Set the volume of the sound currently being generated.
|
void |
shutdown()
Shutdown the audio generation.
|
public static final double NOTE_G_BELOW_C
public static final double NOTE_A
public static final double NOTE_ASHARP
public static final double NOTE_B
public static final double NOTE_C
public static final double NOTE_CSHARP
public static final double NOTE_D
public static final double NOTE_DSHARP
public static final double NOTE_E
public static final double NOTE_F
public static final double NOTE_FSHARP
public static final double NOTE_G
public static final double NOTE_GSHARP
public static final int SAMPLING_RATE
public static final int SAMPLE_SIZE
public static final double BUFFER_DURATION
public static final int SINE_PACKET_SIZE
public ToneEmitter()
java.lang.RuntimeException
- if the hardware does not support an appropriate audio output
device.public void setFrequency(double frequency)
frequency
- the frequency (in hertz) of the output sound.public double getFrequency()
public void setVolume(double volume)
volume
- the volume of the sound being generated in the range (0..1). 0
is the lowest possible volume. 1 is the maximum. It is not
possible to set the output to 11.public double getVolume()
public void shutdown()
public void play(double note)
note
- the frequency to play.public void play(double note, double duration)
note
- the frequency to play.duration
- for how long to play it, in seconds.public void run()
run
in interface java.lang.Runnable
public static void main(java.lang.String[] args)
args
- command line arguments (ignored)