1 Reply Latest reply: Jul 6, 2011 7:13 AM by tschodt RSS

    Loosing AudioBytes

    825360
      Hi all.

      I am using java sound api to sample data at 50Hz, what's happening is that I am loosing audio bytes in the process.

      This is my source code:

      byteOutputStream = new ByteArrayOutputStream( );
      bufferSize = targetDataLine.getBufferSize() / 5;


      tempAudioBytes = new byte[bufferSize];

      while(!mustQuit) {
           
      numBytesRead = targetDataLine.read(tempAudioBytes, 0, tempAudioBytes.length );

      byteOutputStream.write( tempAudioBytes, 0, numBytesRead );

      // send buffer data to a queue
      audioBytesQueue.offer(byteOutputStream.toByteArray())
      byteOutputStream.reset();
      }


      I know that I am loosing audio bytes because of of the signals I am using is a perfect sinusoid at 50hz, but when I plot it using java (after converting to doubles) sometimes I get discontinuities in the ploted sinusoid.

      I've read that data will be discarded by the line if it tries to write to the internal buffer while we are reading from it. This is why I use a small buffer to access to lines internal buffer, but this doesn't seem to solve my problem...

      Any ideias how I can solve this? Or let me know if I'm doing something wrong

      Thanks in advance
        • 1. Re: Loosing AudioBytes
          tschodt
          user13514642 wrote:
          byteOutputStream = new ByteArrayOutputStream( );
          bufferSize = targetDataLine.getBufferSize() / 5;

          tempAudioBytes = new byte[bufferSize];

          while(!mustQuit) {
               
          numBytesRead = targetDataLine.read(tempAudioBytes, 0, tempAudioBytes.length );

          byteOutputStream.write( tempAudioBytes, 0, numBytesRead );

          // send buffer data to a queue
          audioBytesQueue.offer(byteOutputStream.toByteArray()); // << you should check the boolean return value from offer()
          byteOutputStream.reset();
          }
          [&#8203;/code]
          I know that I am loosing audio bytes because of of the signals I am using is a perfect sinusoid at 50hz, but when I plot it using java (after converting to doubles) sometimes I get discontinuities in the ploted sinusoid.

          I've read that data will be discarded by the line if it tries to write to the internal buffer while we are reading from it. This is why I use a small buffer to access to lines internal buffer, but this doesn't seem to solve my problem...

          Any ideas how I can solve this? Or let me know if I'm doing something wrong? You should check the boolean return value from offer()