Example usage for javax.sound.sampled LineUnavailableException LineUnavailableException

List of usage examples for javax.sound.sampled LineUnavailableException LineUnavailableException

Introduction

In this page you can find the example usage for javax.sound.sampled LineUnavailableException LineUnavailableException.

Prototype

public LineUnavailableException(final String message) 

Source Link

Document

Constructs a LineUnavailableException that has the specified detail message.

Usage

From source file:com.arkatay.yada.codec.AudioEncoder.java

public void startModule(TargetDataLine inputLine, int audioFormatIndex) throws LineUnavailableException {
    capturedFrameSizeInNanos = 20L * millisToNanos;

    if (state != STATE_OFF)
        throw new IllegalStateException("Trying to re-start the encoder");

    // Check bounds
    AudioFormat[] audioFormats = getSupportedAudioFormats();
    if (audioFormatIndex < 0 || audioFormatIndex >= audioFormats.length)
        throw new LineUnavailableException("Audio format array out of bounds");

    // Get format
    AudioFormat audioFormat = audioFormats[audioFormatIndex];

    // Create line if created internally
    if (inputLine == null) {
        inputLine = createLine(audioFormat);
    }/*from   w  w w .j av a  2s . c o  m*/

    // Validate the audio format if external
    else if (!audioFormat.matches(inputLine.getFormat())) {
        throw new LineUnavailableException("Audio format not supported");
    }

    this.inputLine = inputLine;
    this.audioFormatIndex = audioFormatIndex;

    // Call init on the sub-class implementation
    init();

    // Calculate stuff
    capturedFrameSizeInBytes = (int) (audioFormat.getFrameRate() * audioFormat.getFrameSize()
            * capturedFrameSizeInNanos / (1000 * millisToNanos));
    diffTimeNanosLimit = diffTimeMillisLimit * millisToNanos;

    // Open the input line, the wanted buffer size is N times as big as the frame size
    inputLine.open(audioFormat, 4 * capturedFrameSizeInBytes);
    inputLineBufferSize = inputLine.getBufferSize();
    log.debug("Input line is open with buffer size " + inputLineBufferSize);

    // Create a buffer for the captured frame
    captureBuffer = new byte[capturedFrameSizeInBytes];

    // Go to state idle
    state = STATE_IDLE;

    // Start the capturing thread, it will block until startProcessing is called
    thread.start();
}