public class FunctionPlayer
extends java.lang.Object
public class MyWaveform implements Waveform
{
public double f(double t, double freq)
{
double amplitude = 0.8;
double omega = 2 * Math.PI * freq;
double[] overtones =
{
1.0, 1.0 / 2, 1.0 / 3, 1.0 / 4, 1.0 / 5, 1.0 / 6, 1.0 / 7, 1.0 / 8, 1.0 / 9
};
double value = 0;
for (int n = 0; n < overtones.length; n++)
value = value + overtones[n] * Math.sin(n * omega * t);
return amplitude * value;
}
}
Waveform
Constructor and Description |
---|
FunctionPlayer()
Creates a FunctionPlayer with format Audioformats.dvd_mono.
|
FunctionPlayer(javax.sound.sampled.AudioFormat audioFormat)
Creates a FunctionPlayer with given audio format.
|
Modifier and Type | Method and Description |
---|---|
void |
load(Waveform wf,
double duration,
double frequency)
Loads the audio data using the function from given Waveform.
|
boolean |
loop()
Starts playing the sound clip continously and returns immediately.
|
boolean |
save(java.io.File file)
Save the loaded sound data to the given WAV file using the current
audio format.
|
boolean |
start()
Starts playing the sound clip and returns immediately.
|
boolean |
start(boolean blocking)
Starts playing the sound clip and blocks until finished if blocking is true.
|
void |
stop()
Stops playing the sound clip and discards all remaining data.
|
public FunctionPlayer(javax.sound.sampled.AudioFormat audioFormat)
audioFormat
- the audio format to use.AudioFormats
public FunctionPlayer()
AudioFormats
public void load(Waveform wf, double duration, double frequency)
wf
- the Waveform that defines the function to playduration
- the time in seconds the clip is playedfrequency
- the frequency in Hertzpublic boolean save(java.io.File file)
file
- the WAV file to be created. If it already exists, it is overwritten.public boolean start()
public boolean start(boolean blocking)
blocking
- if true, the method blocks until the clip is finishedpublic boolean loop()
public void stop()