Search in sources :

Example 1 with JavaLayerException

use of vazkii.symphony.lib.javazoom.jl.decoder.JavaLayerException in project Symphony by Vazkii.

the class Converter method convert.

public void convert(String sourceName, String destName, ProgressListener progressListener, Decoder.Params decoderParams) throws JavaLayerException {
    if (destName.length() == 0)
        destName = null;
    try {
        InputStream in = openInput(sourceName);
        convert(in, destName, progressListener, decoderParams);
        in.close();
    } catch (IOException ioe) {
        throw new JavaLayerException(ioe.getLocalizedMessage(), ioe);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) JavaLayerException(vazkii.symphony.lib.javazoom.jl.decoder.JavaLayerException)

Example 2 with JavaLayerException

use of vazkii.symphony.lib.javazoom.jl.decoder.JavaLayerException in project Symphony by Vazkii.

the class JavaSoundAudioDevice method test.

/**
 * Runs a short test by playing a short silent sound.
 */
public void test() throws JavaLayerException {
    try {
        open(new AudioFormat(22050, 16, 1, true, false));
        short[] data = new short[22050 / 10];
        write(data, 0, data.length);
        flush();
        close();
    } catch (RuntimeException ex) {
        throw new JavaLayerException("Device test failed: " + ex);
    }
}
Also used : AudioFormat(javax.sound.sampled.AudioFormat) JavaLayerException(vazkii.symphony.lib.javazoom.jl.decoder.JavaLayerException)

Example 3 with JavaLayerException

use of vazkii.symphony.lib.javazoom.jl.decoder.JavaLayerException in project Symphony by Vazkii.

the class JavaSoundAudioDeviceFactory method createAudioDevice.

public synchronized AudioDevice createAudioDevice() throws JavaLayerException {
    if (!tested) {
        testAudioDevice();
        tested = true;
    }
    try {
        return createAudioDeviceImpl();
    } catch (Exception ex) {
        throw new JavaLayerException("unable to create JavaSound device: " + ex);
    } catch (LinkageError ex) {
        throw new JavaLayerException("unable to create JavaSound device: " + ex);
    }
}
Also used : JavaLayerException(vazkii.symphony.lib.javazoom.jl.decoder.JavaLayerException) JavaLayerException(vazkii.symphony.lib.javazoom.jl.decoder.JavaLayerException)

Example 4 with JavaLayerException

use of vazkii.symphony.lib.javazoom.jl.decoder.JavaLayerException 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);
    }
}
Also used : Header(vazkii.symphony.lib.javazoom.jl.decoder.Header) BufferedInputStream(java.io.BufferedInputStream) Bitstream(vazkii.symphony.lib.javazoom.jl.decoder.Bitstream) Obuffer(vazkii.symphony.lib.javazoom.jl.decoder.Obuffer) IOException(java.io.IOException) Decoder(vazkii.symphony.lib.javazoom.jl.decoder.Decoder) JavaLayerException(vazkii.symphony.lib.javazoom.jl.decoder.JavaLayerException) JavaLayerException(vazkii.symphony.lib.javazoom.jl.decoder.JavaLayerException) IOException(java.io.IOException)

Example 5 with JavaLayerException

use of vazkii.symphony.lib.javazoom.jl.decoder.JavaLayerException in project Symphony by Vazkii.

the class FactoryRegistry method createAudioDevice.

public AudioDevice createAudioDevice() throws JavaLayerException {
    AudioDevice device = null;
    AudioDeviceFactory[] factories = getFactoriesPriority();
    if (factories == null)
        throw new JavaLayerException(this + ": no factories registered");
    JavaLayerException lastEx = null;
    for (int i = 0; (device == null) && (i < factories.length); i++) {
        try {
            device = factories[i].createAudioDevice();
        } catch (JavaLayerException ex) {
            lastEx = ex;
        }
    }
    if (device == null && lastEx != null) {
        throw new JavaLayerException("Cannot create AudioDevice", lastEx);
    }
    return device;
}
Also used : JavaLayerException(vazkii.symphony.lib.javazoom.jl.decoder.JavaLayerException)

Aggregations

JavaLayerException (vazkii.symphony.lib.javazoom.jl.decoder.JavaLayerException)11 BufferedInputStream (java.io.BufferedInputStream)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Header (vazkii.symphony.lib.javazoom.jl.decoder.Header)3 FileInputStream (java.io.FileInputStream)2 SampleBuffer (vazkii.symphony.lib.javazoom.jl.decoder.SampleBuffer)2 PrintWriter (java.io.PrintWriter)1 AudioFormat (javax.sound.sampled.AudioFormat)1 DataLine (javax.sound.sampled.DataLine)1 Line (javax.sound.sampled.Line)1 LineUnavailableException (javax.sound.sampled.LineUnavailableException)1 SourceDataLine (javax.sound.sampled.SourceDataLine)1 Bitstream (vazkii.symphony.lib.javazoom.jl.decoder.Bitstream)1 Decoder (vazkii.symphony.lib.javazoom.jl.decoder.Decoder)1 Obuffer (vazkii.symphony.lib.javazoom.jl.decoder.Obuffer)1 AudioDevice (vazkii.symphony.lib.javazoom.jl.player.AudioDevice)1