at.ofai.music.beatroot
public class AudioPlayer extends Object implements Runnable
Field Summary | |
---|---|
protected 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 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, 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(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(boolean resetPosition) Notifies play thread to stop playing. |
void | stop() Notifies play thread to stop playing or reset position if not playing. |
void | togglePlay() Notifies the play thread to pause if playing or play if paused/stopped. |
Parameters: f The input audio file ch The FileChooser object for opening and saving files
Parameters: buffer The audio sample without the beats being marked offset Offset of the percussion sound relative to the audio sample len Length of the sound to add (in bytes) level Metrical level of the percussion sound (determines instrument)
Parameters: buffer The audio sample without beats bytes The length of the audio sample in bytes
Returns: Current playback position in bytes relative to the beginning of the file.
Returns: Length in bytes of the current or requested audio input file.
Returns: Playback time in seconds
Parameters: time New play position (in seconds)
Parameters: fileName The relative or absolate path name of the new audio input file.
Parameters: audioOnly Flag indicating whether to play audio (true) or play beats (false)
Parameters: audio Flag indicating whether audio should be played beats Flag indicating whether beats should be played
Parameters: newFile The new input file.
Parameters: positionRequested The new file position (in bytes) for audio input
Parameters: positionRequested The new file position (in bytes) for audio input update Flag to indicate whether the GUI should be updated or not
Parameters: time Offset of new play position (in seconds) relative to present play position.
Parameters: bytes Offset of new play position (in bytes) relative to present play position.
Parameters: resetPosition Flag indicating whether to reset the playback position to the beginning of the file