2 Replies Latest reply: Dec 28, 2010 8:43 PM by 827057 RSS

    about audio format encoding and byte[] data

    827057
      1.may i know how many types of encoding besides 5 types list in java api?

      2.how will encodings affect output sound?

      3.i get an exception when i try to to convert from PCM_UNSIGNED to ALAM. Is there any plugin to support it?
      java.lang.IllegalArgumentException: Unsupported conversion: ALAW 22050.0 Hz, 8 bit, mono, 1 bytes/frame, from PCM_UNSIGNED 22050.0 Hz, 8 bit, mono, 1 bytes/frame.
      4.how will the number of channel affect output sound?

      5.how will the data array size affect output sound? what value should we put instead of 4096?
      byte[]     data = new byte[4096];
      while ((bRead = ais.read(data, 0, data.length)) != -1) line.write(data, 0, bRead);
      thanks for your reply~
        • 1. Re: about audio format encoding and byte[] data
          captfoss
          user13556330 wrote:
          1.may i know how many types of encoding besides 5 types list in java api?
          Too many to list...
          2.how will encodings affect output sound?
          They'll generally decrease the quality of the sound, or have no effect on the sound. Depends on the encoding...
          3.i get an exception when i try to to convert from PCM_UNSIGNED to ALAM. Is there any plugin to support it?
          java.lang.IllegalArgumentException: Unsupported conversion: ALAW 22050.0 Hz, 8 bit, mono, 1 bytes/frame, from PCM_UNSIGNED 22050.0 Hz, 8 bit, mono, 1 bytes/frame.
          There's no ALAW converted built-in, no. There probably is a plugin you can find on the internet to do the conversion, but, it's up to you to find it...
          4.how will the number of channel affect output sound?
          Generally sound is designed to be rendered as one-channel per speaker... so "stereo" is 2-speakers, "surround sound" is 5 or 7 speakers, etc... you don't have to follow this rule, but, that's the "goal" of multi-channel sound.
          5.how will the data array size affect output sound? what value should we put instead of 4096?
          Assuming you're doing that code to play a file, that's essentially your "buffer" size. If you use a buffer that's too big, it'll take a long time to begin playing... if you use a buffer that's too small, it'll have too much overhead and your audio may skip.

          The standard sound format is 2-channel 16-bit PCM played at 44.1K, so a buffer size of 4096 represents about 25 milliseconds of sound... which is a good length for a buffer. I'd recommend keeping your buffer length to where it represents 20-50 milliseconds worth of data...but you can always have a longer buffer. Standard anti-skip CDs generally use a 4-second buffer, which would be 705,600 bytes...
          • 2. Re: about audio format encoding and byte[] data
            827057
            Generally sound is designed to be rendered as one-channel per speaker... so "stereo" is 2-speakers, "surround sound" is 5 or 7 speakers, etc... you don't have to follow this rule, but, that's the "goal" of multi-channel sound.
            do channels output different sound at the same time?
            as an example, combine A file and B file into C file. when playing C file, 1st speaker outputs A file and 2nd speaker outputs B file if there are only 2 speakers.
            The standard sound format is 2-channel 16-bit PCM played at 44.1K, so a buffer size of 4096 represents about 25 milliseconds of sound... which is a good length for a buffer. I'd recommend keeping your buffer length to where it represents 20-50 milliseconds worth of data...but you can always have a longer buffer. Standard anti-skip CDs generally use a 4-second buffer, which would be 705,600 bytes...
            may i know the formula to get milliseconds of sound?

            Thanks~