public class Guitar
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private float |
decayRate
Decay rate
|
private static float |
DEFAULT_DECAY_RATE
Default decay rate
|
private static int |
DEFAULT_SAMPLE_RATE
Default sample rate in Hz
|
private static int |
MAX_SAMPLE_RATE
Maximum sample rate in Hz
|
private java.util.List<Note> |
notes
List of notes
|
private int |
sampleRate
Sample rate in samples per second
|
Constructor and Description |
---|
Guitar()
Constructs a new Guitar object with the default sample rate
and decay rate.
|
Guitar(int sampleRate,
float decayRate)
Constructs a new Guitar object with the specified parameters.
|
Modifier and Type | Method and Description |
---|---|
void |
addNote(Note note)
Adds the specified note to this Guitar.
|
Note[] |
getNotes()
Returns an array containing all the notes in this Guitar.
|
private java.util.List<java.lang.Float> |
jaffeSmith()
Uses the Jaffe-Smith algorithm to generate the audio samples.
|
void |
play()
Generates the audio samples for the notes listed in the
current Guitar object by calling the jaffeSmith algorithm and
sends the samples to the speakers.
|
void |
removeNote(int index)
Removes the note at the specified index from this Guitar.
|
void |
write(java.io.File file)
Creates a new file and writes to that file.
|
private static final int DEFAULT_SAMPLE_RATE
private static final int MAX_SAMPLE_RATE
private static final float DEFAULT_DECAY_RATE
private java.util.List<Note> notes
private int sampleRate
private float decayRate
public Guitar()
public Guitar(int sampleRate, float decayRate)
sampleRate
- sample rate (between 8000 Hz and 48000 Hz)decayRate
- decay rate (between 0.0f and 1.0f)public void addNote(Note note)
note
- Note to be added.public void play() throws javax.sound.sampled.LineUnavailableException, java.io.IOException
javax.sound.sampled.LineUnavailableException
java.io.IOException
private java.util.List<java.lang.Float> jaffeSmith()
public void removeNote(int index)
index
- Index of the note to be removed.public Note[] getNotes()
public void write(java.io.File file) throws java.io.IOException
file
- File to write to.java.io.IOException