public class AudioSignalSource extends Object implements SignalSource<AudioBuffer>, Closeable
Encapsulates an AudioInputStream
to serve as a SignalSource
for
a SignalPump
or a SignalPullProcessor
.
The provided stream/file is converted to float[]
based RealAudioBuffer
s.
This also implies a normalization to values between -1 and 1 (signed) or 0 and 1 (unsigned).
Normalization can be turned off via setNormalize(boolean)
.
If the signal contains multiple channels, these channel signals are still in their original (potentially interleaved) layout.
As of Java 6, mp3 is unfortunately not supported out of the box by Java. You might need to install the free codec JLayer. Platform dependent alternatives are CASampledSP and MFSampledSP/
AudioSystem.getAudioInputStream(java.io.File)
,
JLayer,
CASampledSP,
MFSampledSPConstructor and Description |
---|
AudioSignalSource(AudioInputStream in)
Creates a normalized (see
isNormalize() ) SignalSource from the given stream,
using a 16kb internal buffer. |
AudioSignalSource(AudioInputStream in,
int bufferSize)
Creates a normalized (see
isNormalize() ) SignalSource from the given stream. |
AudioSignalSource(File file)
Creates a normalized (see
isNormalize() ) SignalSource from the given file,
using a 16kb internal buffer. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close this signal source and its underlying
AudioInputStream . |
boolean |
equals(Object o) |
protected void |
finalize() |
int |
hashCode() |
boolean |
isNormalize()
Indicates whether all values are normalized to -1 t0 1 (signed) or 0 to 1 (unsigned).
|
AudioBuffer |
read()
Provide the next chunk of output data.
|
void |
reset()
Since this source is stream-based it cannot be properly reset.
|
void |
setNormalize(boolean normalize)
Turns normalization to values between -1 and 1 (signed) or 0 and 1 (unsigned) on or off.
|
String |
toString() |
public AudioSignalSource(AudioInputStream in, int bufferSize) throws IllegalArgumentException
isNormalize()
) SignalSource
from the given stream.in
- audio input stream with an associated AudioFormat that has at least sampleSizeInBits
, channels
, and frameSize
setbufferSize
- buffer this must be a multiple of the audio format's framesizeIllegalArgumentException
- if the audio format is not specific enoughpublic AudioSignalSource(AudioInputStream in) throws IllegalArgumentException
isNormalize()
) SignalSource
from the given stream,
using a 16kb internal buffer.in
- audio input streamIllegalArgumentException
- if the audio format is not specific enoughpublic AudioSignalSource(File file) throws UnsupportedAudioFileException, IOException, IllegalArgumentException
isNormalize()
) SignalSource
from the given file,
using a 16kb internal buffer.file
- audio fileUnsupportedAudioFileException
- if the file is not supported by AudioSystem
.IOException
- if something goes wrong while opening the audio fileIllegalArgumentException
- if the audio format extracted from the file is not specific enoughpublic boolean isNormalize()
public void setNormalize(boolean normalize)
normalize
- true or offpublic void reset()
reset
in interface SignalSource<AudioBuffer>
public AudioBuffer read() throws IOException
SignalSource
SignalSource
data, typically an SignalPullProcessor
.read
in interface SignalSource<AudioBuffer>
AudioBuffer
, null
if no more data is availableIOException
- if something goes wrongprotected void finalize() throws Throwable
public void close() throws IOException
AudioInputStream
.close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2011–2020 tagtraum industries incorporated. All rights reserved.