Note that there are some explanatory texts on larger screens.

plurals
  1. POThe difference between DataLine and (Output|Input)Stream?
    text
    copied!<p>I am working on sound processing with the use of Java now. Within my project, I have to deal with the stream. So I have a lot of staffs to do with <code>DataLine</code> and <code>OutputStream</code> or <code>InputStream</code>. But to me, they are too similar:(</p> <p>Is there someone who can help me with this question? Thanks in advance! Here are some code I used :</p> <pre><code> TargetDataLine line; ByteArrayOutputStream out = new ByteArrayOutputStream(); int frameSizeInBytes = format.getFrameSize(); int bufferLengthInFrames = line.getBufferSize() / 8; int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes; byte[] data = new byte[bufferLengthInBytes]; int numBytesRead; try { line = (TargetDataLine) AudioSystem.getLine(info); line.open(format, line.getBufferSize()); } catch (LineUnavailableException ex) { shutDown("Unable to open the line: " + ex); return; } catch (SecurityException ex) { shutDown(ex.toString()); return; } catch (Exception ex) { shutDown(ex.toString()); return; } line.start(); while (thread != null) { if ((numBytesRead = line.read(data, 0, bufferLengthInBytes)) == -1) { break; } out.write(data, 0, numBytesRead); } </code></pre> <p>I have read the documentation of the class <strong>TargetDataLine</strong>, it is said :"'read(byte[] b, int off, int len)' Reads audio data from the data line's input buffer." </p> <p>But where do we define it?</p> <p><em><strong>Also the line of type TargetDataLine has not been attached to any mixer, so how can we know for which mixer it is for???</em></strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload