public class MultiFile8BitAudioPlayer extends Object implements AudioPlayer
Modifier and Type | Field and Description |
---|---|
private String |
baseName |
private int |
curIndex |
private AudioFormat |
currentFormat |
private int |
fileCount |
private byte[] |
outputData |
private AudioFileFormat.Type |
outputType |
Constructor and Description |
---|
MultiFile8BitAudioPlayer()
Creates a default audio player for an AudioFileFormat of type
WAVE.
|
MultiFile8BitAudioPlayer(String baseName,
AudioFileFormat.Type type)
Constructs a MultiFile8BitAudioPlayer
|
Modifier and Type | Method and Description |
---|---|
void |
begin(int size)
Starts the output of a set of data.
|
void |
cancel()
Cancels currently playing audio
|
void |
close()
Closes this audio player
|
private static byte[] |
convert16To8Bits(byte[] samples16Bit)
Converts an array of signed 16-bit audio data to unsigned 8-bit
audio data.
|
boolean |
drain()
Waits for all queued audio to be played
|
boolean |
end()
Signals the end of a set of data.
|
AudioFormat |
getAudioFormat()
Gets the audio format for this player
|
long |
getTime()
Gets the amount of played since the last mark
|
float |
getVolume()
Returns the current volume.
|
void |
pause()
Pauses audio output
|
void |
reset()
Prepares for another batch of output.
|
void |
resetTime()
Resets the audio clock
|
void |
resume()
Resumes audio output
|
void |
setAudioFormat(AudioFormat format)
Sets the audio format for this player
|
void |
setVolume(float volume)
Sets the current volume.
|
void |
showMetrics()
Shows metrics for this audio player
|
void |
startFirstSampleTimer()
Starts the first sample timer
|
String |
toString()
Returns the name of this audioplayer
|
boolean |
write(byte[] audioData)
Writes the given bytes to the audio stream
|
boolean |
write(byte[] bytes,
int offset,
int size)
Writes the given bytes to the audio stream
|
private AudioFormat currentFormat
private int fileCount
private byte[] outputData
private int curIndex
private AudioFileFormat.Type outputType
public MultiFile8BitAudioPlayer()
public MultiFile8BitAudioPlayer(String baseName, AudioFileFormat.Type type)
baseName
- the base name of the audio filetype
- the type of audio outputpublic void setAudioFormat(AudioFormat format)
setAudioFormat
in interface AudioPlayer
format
- the audio formatUnsupportedOperationException
- if the line cannot be opened with
the given formatpublic AudioFormat getAudioFormat()
getAudioFormat
in interface AudioPlayer
public void pause()
pause
in interface AudioPlayer
public void resume()
resume
in interface AudioPlayer
public void startFirstSampleTimer()
startFirstSampleTimer
in interface AudioPlayer
public void cancel()
cancel
in interface AudioPlayer
public void reset()
reset
in interface AudioPlayer
public void close()
close
in interface AudioPlayer
public float getVolume()
getVolume
in interface AudioPlayer
public void setVolume(float volume)
setVolume
in interface AudioPlayer
volume
- the current volume (between 0 and 1)public void begin(int size)
begin
in interface AudioPlayer
size
- the size of data between now and the endpublic boolean end() throws IOException
begin/end
pairs.end
in interface AudioPlayer
true
if the audio was output properly,
false
if the output was canceled
or interrupted.IOException
- if an error occurs while closing the outputpublic boolean drain()
drain
in interface AudioPlayer
public long getTime()
getTime
in interface AudioPlayer
public void resetTime()
resetTime
in interface AudioPlayer
public boolean write(byte[] audioData)
write
in interface AudioPlayer
audioData
- audio data to write to the devicetrue
of the write completed successfully,
false
if the write was cancelled.public boolean write(byte[] bytes, int offset, int size)
write
in interface AudioPlayer
bytes
- audio data to write to the deviceoffset
- the offset into the buffersize
- the size into the buffertrue
of the write completed successfully,
false
if the write was cancelled.private static byte[] convert16To8Bits(byte[] samples16Bit)
samples16Bit
- the signed 16-bit audio data to convertpublic void showMetrics()
showMetrics
in interface AudioPlayer
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses