use of vazkii.symphony.lib.javazoom.jl.decoder.Header in project Symphony by Vazkii.
the class AdvancedPlayer method skipFrame.
/**
* skips over a single frame
* @return false if there are no more frames to decode, true otherwise.
*/
protected boolean skipFrame() throws JavaLayerException {
Header h = bitstream.readFrame();
if (h == null)
return false;
bitstream.closeFrame();
return true;
}
use of vazkii.symphony.lib.javazoom.jl.decoder.Header in project Symphony by Vazkii.
the class Converter method convert.
public synchronized void convert(InputStream sourceStream, String destName, ProgressListener progressListener, Decoder.Params decoderParams) throws JavaLayerException {
if (progressListener == null)
progressListener = PrintWriterProgressListener.newStdOut(PrintWriterProgressListener.NO_DETAIL);
try {
if (!(sourceStream instanceof BufferedInputStream))
sourceStream = new BufferedInputStream(sourceStream);
int frameCount = -1;
if (sourceStream.markSupported()) {
sourceStream.mark(-1);
frameCount = countFrames(sourceStream);
sourceStream.reset();
}
progressListener.converterUpdate(ProgressListener.UPDATE_FRAME_COUNT, frameCount, 0);
Obuffer output = null;
Decoder decoder = new Decoder(decoderParams);
Bitstream stream = new Bitstream(sourceStream);
if (frameCount == -1)
frameCount = Integer.MAX_VALUE;
int frame = 0;
long startTime = System.currentTimeMillis();
try {
for (; frame < frameCount; frame++) {
try {
Header header = stream.readFrame();
if (header == null)
break;
progressListener.readFrame(frame, header);
if (output == null) {
// REVIEW: Incorrect functionality.
// the decoder should provide decoded
// frequency and channels output as it may differ from
// the source (e.g. when downmixing stereo to mono.)
int channels = (header.mode() == Header.SINGLE_CHANNEL) ? 1 : 2;
int freq = header.frequency();
output = new WaveFileObuffer(channels, freq, destName);
decoder.setOutputBuffer(output);
}
Obuffer decoderOutput = decoder.decodeFrame(header, stream);
// this exception should never happen, we test to be sure.
if (decoderOutput != output)
throw new InternalError("Output buffers are different.");
progressListener.decodedFrame(frame, header, output);
stream.closeFrame();
} catch (Exception ex) {
boolean stop = !progressListener.converterException(ex);
if (stop) {
throw new JavaLayerException(ex.getLocalizedMessage(), ex);
}
}
}
} finally {
if (output != null)
output.close();
}
int time = (int) (System.currentTimeMillis() - startTime);
progressListener.converterUpdate(ProgressListener.UPDATE_CONVERT_COMPLETE, time, frame);
} catch (IOException ex) {
throw new JavaLayerException(ex.getLocalizedMessage(), ex);
}
}
use of vazkii.symphony.lib.javazoom.jl.decoder.Header in project Symphony by Vazkii.
the class Player method decodeFrame.
/**
* Decodes a single frame.
*
* @return true if there are no more frames to decode, false otherwise.
*/
protected boolean decodeFrame() throws JavaLayerException {
try {
AudioDevice out = audio;
if (out == null)
return false;
Header h = bitstream.readFrame();
if (h == null)
return false;
// sample buffer set when decoder constructed
SampleBuffer output = (SampleBuffer) decoder.decodeFrame(h, bitstream);
synchronized (this) {
out = audio;
if (out != null) {
out.write(output.getBuffer(), 0, output.getBufferLength());
}
}
bitstream.closeFrame();
} catch (RuntimeException ex) {
throw new JavaLayerException("Exception decoding audio frame", ex);
}
/*
catch (IOException ex)
{
System.out.println("exception decoding audio frame: "+ex);
return false;
}
catch (BitstreamException bitex)
{
System.out.println("exception decoding audio frame: "+bitex);
return false;
}
catch (DecoderException decex)
{
System.out.println("exception decoding audio frame: "+decex);
return false;
}
*/
return true;
}
use of vazkii.symphony.lib.javazoom.jl.decoder.Header in project Symphony by Vazkii.
the class AdvancedPlayer method decodeFrame.
/**
* Decodes a single frame.
*
* @return true if there are no more frames to decode, false otherwise.
*/
protected boolean decodeFrame() throws JavaLayerException {
try {
AudioDevice out = audio;
if (out == null)
return false;
Header h = bitstream.readFrame();
if (h == null)
return false;
// sample buffer set when decoder constructed
SampleBuffer output = (SampleBuffer) decoder.decodeFrame(h, bitstream);
synchronized (this) {
out = audio;
if (out != null) {
out.write(output.getBuffer(), 0, output.getBufferLength());
}
}
bitstream.closeFrame();
} catch (RuntimeException ex) {
throw new JavaLayerException("Exception decoding audio frame", ex);
}
return true;
}
Aggregations