|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object at.ofai.music.beatroot.AudioPlayer
public class AudioPlayer
Field Summary | |
---|---|
protected javax.sound.sampled.SourceDataLine |
audioOut
The object to which audio output is written |
protected int |
beatIndex
The index in beats[] of the next beat (relative to the current playback position |
protected long[] |
beats
The positions in samples of beats for playback of audio with click marking beat times |
protected int[][] |
click
An array of percussion sounds |
protected AudioFile |
currentFile
The file currently loaded by this AudioPlayer |
protected long |
currentPosition
The position (in bytes) of playback, relative to the beginning of the file |
protected boolean |
debug
Flag for debugging output |
protected static int |
defaultOutputBufferSize
The default buffer size for audio output |
protected long |
endPosition
The byte position in the current file to stop playing |
protected GUI |
gui
BeatRoot's graphical user interface |
protected javax.swing.JFileChooser |
jfc
The file chooser dialog window for opening and saving files |
protected int[] |
level
The metrical level of each beat (see beats[]) |
protected int |
outputBufferSize
The buffer size used by audioOut |
protected boolean |
playAudio
Flag indicating the current mode of playing, whether audio should be played |
protected boolean |
playBeats
Flag indicating the current mode of playing, whether the beats should be played |
protected boolean |
playing
A flag set by the play thread indicating whether audio playback is active |
protected byte[] |
readBuffer
Audio input buffer for the current input file |
protected byte[] |
readBuffer2
A second audio input buffer used when crossfading between two audio files |
protected static int |
readBufferSize
The size of the buffer for reading audio input |
protected AudioFile |
requestedFile
A new file that has been loaded to play next |
protected long |
requestedPosition
The requested playback position, in bytes, relative to the beginning of the file |
protected long |
startNanoTime
The time that the audio playback last started, in nanoseconds |
protected double |
startTime
The time in the playback file where the audio playback last started |
protected boolean |
stopRequested
A flag indicating to the play thread that playing should stop |
protected static double |
volume
The relative volume of percussion (for the click track) relative to the input audio |
Constructor Summary | |
---|---|
AudioPlayer(AudioFile f,
javax.swing.JFileChooser ch)
Constructor |
Method Summary | |
---|---|
protected void |
addBeat(byte[] buffer,
int offset,
int len,
int level)
Adds a percussion sound to an audio sample at a specified time. |
protected void |
addBeats(byte[] buffer,
int bytes)
Adds a sequence of percussive sounds marking the beats at various metrical levels to an audio sample. |
long |
correctedPosition()
Returns current playback position, corrected for audio buffered in the soundcard. |
long |
getCurrentFileLength()
Returns the length of the current or requested file. |
double |
getCurrentTime()
Returns the current playback time in seconds from when play was started. |
void |
ifSetPosition(double time)
Conditionally changes the position and possibly the file for input data, if the play thread is idle. |
protected void |
initBeats()
Initialise the beat list ready for audio playback with beats. |
protected void |
initClicks()
Initialise the percussion sounds for audio playback with beats. |
void |
load()
Open a new audio input file, with the path being chosen by a file chooser dialog. |
void |
load(java.lang.String fileName)
Open a new audio input file with the given path. |
void |
pause()
Notifies play thread to pause playing |
void |
play()
Notify play thread to play audio with beats |
void |
play(boolean audioOnly)
Notify play thread to play either audio or beats. |
void |
play(boolean audio,
boolean beats)
Notify play thread to play audio, beats or both. |
void |
run()
Implements the Runnable interface for the audio playback thread. |
void |
save()
Saves audio with beats as a WAV file, with name determined by a file chooser dialog. |
void |
setCurrentFile(AudioFile newFile)
Change the input file for audio playback (in a thread-safe way). |
protected void |
setPosition(long positionRequested)
Changes the position and possibly the file for input data, and updates the GUI accordingly. |
protected void |
setPosition(long positionRequested,
boolean update)
Changes the position and possibly the file for input data. |
void |
skip(double time)
Changes the playback position relative to the current playback position. |
void |
skip(long bytes)
Changes the playback position relative to the current playback position. |
void |
stop()
Notifies play thread to stop playing or reset position if not playing. |
void |
stop(boolean resetPosition)
Notifies play thread to stop playing. |
void |
togglePlay()
Notifies the play thread to pause if playing or play if paused/stopped. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected javax.swing.JFileChooser jfc
protected GUI gui
protected AudioFile currentFile
protected AudioFile requestedFile
protected long currentPosition
protected long requestedPosition
protected long endPosition
protected long startNanoTime
protected double startTime
protected boolean stopRequested
protected boolean playing
protected javax.sound.sampled.SourceDataLine audioOut
protected int outputBufferSize
protected byte[] readBuffer
protected byte[] readBuffer2
protected long[] beats
protected int[] level
protected int beatIndex
protected int[][] click
protected static final int readBufferSize
protected static final int defaultOutputBufferSize
protected static double volume
protected boolean debug
protected boolean playAudio
protected boolean playBeats
Constructor Detail |
---|
public AudioPlayer(AudioFile f, javax.swing.JFileChooser ch)
f
- The input audio filech
- The FileChooser object for opening and saving filesMethod Detail |
---|
public void play()
public void play(boolean audioOnly)
audioOnly
- Flag indicating whether to play audio (true) or play beats (false)public void play(boolean audio, boolean beats)
audio
- Flag indicating whether audio should be playedbeats
- Flag indicating whether beats should be playedpublic void pause()
public void stop(boolean resetPosition)
resetPosition
- Flag indicating whether to reset the playback position to the beginning of the filepublic void stop()
public void togglePlay()
protected void setPosition(long positionRequested)
positionRequested
- The new file position (in bytes) for audio inputprotected void setPosition(long positionRequested, boolean update)
positionRequested
- The new file position (in bytes) for audio inputupdate
- Flag to indicate whether the GUI should be updated or notpublic void ifSetPosition(double time)
time
- New play position (in seconds)public void skip(double time)
time
- Offset of new play position (in seconds) relative to present play position.public void skip(long bytes)
bytes
- Offset of new play position (in bytes) relative to present play position.public double getCurrentTime()
public long correctedPosition()
public long getCurrentFileLength()
public void save()
public void load()
public void load(java.lang.String fileName)
fileName
- The relative or absolate path name of the new audio input file.public void setCurrentFile(AudioFile newFile)
newFile
- The new input file.public void run()
run
in interface java.lang.Runnable
protected void initClicks()
protected void initBeats()
protected void addBeats(byte[] buffer, int bytes)
buffer
- The audio sample without beatsbytes
- The length of the audio sample in bytesprotected void addBeat(byte[] buffer, int offset, int len, int level)
buffer
- The audio sample without the beats being markedoffset
- Offset of the percussion sound relative to the audio samplelen
- Length of the sound to add (in bytes)level
- Metrical level of the percussion sound (determines instrument)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |