int bytesToRead = ais.available(); data = new byte[bytesToRead]; int bytesRead = ais.read(data); if (bytesToRead != bytesRead) throw new IllegalStateException("read only " + bytesRead + " of " + bytesToRead + " bytes"); int bytesToRead = ais.available(); data = new byte[bytesToRead]; int bytesRead = ais.read(data); if (bytesToRead != bytesRead) throw new IllegalStateException("read only " + bytesRead + " of " + bytesToRead + " bytes");
public int read() throws IOException { AudioInputStream stream = getCurrentStream(); int nByte = stream.read(); if (nByte == -1) { /* * The end of the current stream has been signaled. We try to advance to the next stream. */ boolean bAnotherStreamAvailable = advanceStream(); if (bAnotherStreamAvailable) { /* * There is another stream. We recurse into this method to read from it. */ return read(); } else { /* * No more data. We signal EOF. */ return -1; } } else { /* * The most common case: We return the byte. */ return nByte; } }
public int read(byte[] abData, int nOffset, int nLength) throws IOException { AudioInputStream stream = getCurrentStream(); int nBytesRead = stream.read(abData, nOffset, nLength); if (nBytesRead == -1) { /* * The end of the current stream has been signaled. We try to advance to the next stream. */ boolean bAnotherStreamAvailable = advanceStream(); if (bAnotherStreamAvailable) { /* * There is another stream. We recurse into this method to read from it. */ return read(abData, nOffset, nLength); } else { /* * No more data. We signal EOF. */ return -1; } } else { /* * The most common case: We return the length. */ return nBytesRead; } }
public int read() throws IOException { AudioInputStream stream = getCurrentStream(); int nByte = stream.read(); if (nByte == -1) { /* * The end of the current stream has been signaled. We try to advance to the next stream. */ boolean bAnotherStreamAvailable = advanceStream(); if (bAnotherStreamAvailable) { /* * There is another stream. We recurse into this method to read from it. */ return read(); } else { /* * No more data. We signal EOF. */ return -1; } } else { /* * The most common case: We return the byte. */ return nByte; } }
public int read(byte[] abData, int nOffset, int nLength) throws IOException { AudioInputStream stream = getCurrentStream(); int nBytesRead = stream.read(abData, nOffset, nLength); if (nBytesRead == -1) { /* * The end of the current stream has been signaled. We try to advance to the next stream. */ boolean bAnotherStreamAvailable = advanceStream(); if (bAnotherStreamAvailable) { /* * There is another stream. We recurse into this method to read from it. */ return read(abData, nOffset, nLength); } else { /* * No more data. We signal EOF. */ return -1; } } else { /* * The most common case: We return the length. */ return nBytesRead; } }
public int read() throws IOException { AudioInputStream stream = getCurrentStream(); int nByte = stream.read(); if (nByte == -1) { /* * The end of the current stream has been signaled. We try to advance to the next stream. */ boolean bAnotherStreamAvailable = advanceStream(); if (bAnotherStreamAvailable) { /* * There is another stream. We recurse into this method to read from it. */ return read(); } else { /* * No more data. We signal EOF. */ return -1; } } else { /* * The most common case: We return the byte. */ return nByte; } }
public int read(byte[] abData, int nOffset, int nLength) throws IOException { AudioInputStream stream = getCurrentStream(); int nBytesRead = stream.read(abData, nOffset, nLength); if (nBytesRead == -1) { /* * The end of the current stream has been signaled. We try to advance to the next stream. */ boolean bAnotherStreamAvailable = advanceStream(); if (bAnotherStreamAvailable) { /* * There is another stream. We recurse into this method to read from it. */ return read(abData, nOffset, nLength); } else { /* * No more data. We signal EOF. */ return -1; } } else { /* * The most common case: We return the length. */ return nBytesRead; } }
public int read() throws IOException { AudioInputStream stream = getCurrentStream(); int nByte = stream.read(); if (nByte == -1) { /* * The end of the current stream has been signaled. We try to advance to the next stream. */ boolean bAnotherStreamAvailable = advanceStream(); if (bAnotherStreamAvailable) { /* * There is another stream. We recurse into this method to read from it. */ return read(); } else { /* * No more data. We signal EOF. */ return -1; } } else { /* * The most common case: We return the byte. */ return nByte; } }
public int read(byte[] abData, int nOffset, int nLength) throws IOException { AudioInputStream stream = getCurrentStream(); int nBytesRead = stream.read(abData, nOffset, nLength); if (nBytesRead == -1) { /* * The end of the current stream has been signaled. We try to advance to the next stream. */ boolean bAnotherStreamAvailable = advanceStream(); if (bAnotherStreamAvailable) { /* * There is another stream. We recurse into this method to read from it. */ return read(abData, nOffset, nLength); } else { /* * No more data. We signal EOF. */ return -1; } } else { /* * The most common case: We return the length. */ return nBytesRead; } }
while (nBytesRead != -1) { try { nBytesRead = audioStream.read(abData, 0, abData.length); } catch (IOException e) { e.printStackTrace();
/** * Turns the AudioInputStream into a 16bit, SIGNED_PCM, little endian audio stream that preserves the original sample * rate of the AudioInputStream. NOTE: this assumes the frame size can be only 1 or 2 bytes. The AudioInputStream * is left in a state of having all of its data being read. * @param ais stream to convert * @return result array * @throws IOException if error occurred */ static public short[] toSignedPCM(AudioInputStream ais) throws IOException { AudioFormat aisFormat = ais.getFormat(); short[] shorts = new short[ais.available() / aisFormat.getFrameSize()]; byte[] frame = new byte[aisFormat.getFrameSize()]; int pos = 0; while (ais.read(frame) != -1) { shorts[pos++] = bytesToShort(aisFormat, frame); } return shorts; }
long firstSampleNumber = totalSamplesRead / channels; int numBytesRead = audioStream.read(data, 0, data.length);
byte[] samples = new byte[BUFFER_SIZE]; int count = 0; while ((count = ais.read(samples, 0, BUFFER_SIZE)) != -1) { line.write(samples, 0, count);
boolean bigEndian = ais.getFormat().isBigEndian(); byte[] byteBuf = new byte[nBytes]; int nBytesRead = ais.read(byteBuf, 0, nBytes); // Reading all Bytes at a time int currentPos = 0; int noOfSamples = nBytes / 3;
boolean bigEndian = ais.getFormat().isBigEndian(); byte[] byteBuf = new byte[nBytes]; int nBytesRead = ais.read(byteBuf, 0, nBytes); // Reading all Bytes at a time int noOfBytesPerSample = noOfbitsPerSample / 8;
boolean bigEndian = ais.getFormat().isBigEndian(); byte[] byteBuf = new byte[nBytes]; int nBytesRead = ais.read(byteBuf, 0, nBytes); // Reading all Bytes at a time int noOfBytesPerSample = noOfbitsPerSample / 8;
@Test public void canReadTenFrames() throws Exception { int numDoubles = 10; TestProducer producer = new TestProducer(numDoubles); producer.start(); AudioInputStream ais = new DDSAudioInputStream(producer, getTestAudioFormat()); assertEquals(numDoubles, ais.getFrameLength()); int bytesRead = ais.read(new byte[16000]); assertEquals(2 * numDoubles, bytesRead); }
@Test public void canRead4000Frames() throws Exception { int numDoubles = 4000; TestProducer producer = new TestProducer(numDoubles); producer.start(); AudioInputStream ais = new DDSAudioInputStream(producer, getTestAudioFormat()); assertEquals(numDoubles, ais.getFrameLength()); int bytesRead = ais.read(new byte[16000]); assertEquals(2 * numDoubles, bytesRead); }
while (nRead != -1 && !exitRequested) { try { nRead = ais.read(abData, 0, abData.length); } catch (IOException e) { e.printStackTrace();
while (nRead != -1 && !exitRequested) { try { nRead = ais.read(abData, 0, abData.length); } catch (IOException e) { e.printStackTrace();