Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8003125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:34:23+00:00 2026-06-04T16:34:23+00:00

I have found converting a short to byte array , and byte array to

  • 0

I have found converting a short to byte array, and byte array to short array, but not short array to byte array.

Here is the code leading up to the conversion

while(!stopped)
        { 
            Log.i("Map", "Writing new data to buffer");
            short[] buffer = buffers[ix++ % buffers.length];

            N = recorder.read(buffer,0,buffer.length);
            track.write(buffer, 0, buffer.length);

            byte[] bytes2 = new byte[N];

I have tried

              int i = 0;
              ByteBuffer byteBuf = ByteBuffer.allocate(N);
              while (buffer.length >= i) {
                  byteBuf.putShort(buffer[i]);
                  i++;
        }

bytes2 = byteBuf.array();

and

    ByteBuffer.wrap(bytes2).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().put(buffer);

However I receive this error on both (the error if not exactly the same but very similar for both):

05-29 13:41:12.021: W/AudioTrack(9758): obtainBuffer() track 0x30efa0
disabled, restarting

05-29 13:41:12.857: W/AudioWorker(9758): Error reading voice
AudioWorker

05-29 13:41:12.857: W/AudioWorker(9758):
java.nio.BufferOverflowException

05-29 13:41:12.857: W/AudioWorker(9758): at
java.nio.ShortBuffer.put(ShortBuffer.java:422)

05-29 13:41:12.857: W/AudioWorker(9758): at
java.nio.ShortToByteBufferAdapter.put(ShortToByteBufferAdapter.java:210)

05-29 13:41:12.857: W/AudioWorker(9758): at
java.nio.ShortBuffer.put(ShortBuffer.java:391)

05-29 13:41:12.857: W/AudioWorker(9758): at
com.avispl.nicu.audio.AudioWorker.run(AudioWorker.java:126)

And just to be give as much info as possible here is the code after that uses the byte array

Log.i("Map", "test");
                //convert to ulaw
                read(bytes2, 0, N);

                //send to server
                os.write(bytes2,0,bytes2.length);

                System.out.println("bytesRead "+buffer.length);
                System.out.println("data "+Arrays.toString(buffer));
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:34:25+00:00Added an answer on June 4, 2026 at 4:34 pm

    Java short is a 16-bit type, and byte is an 8-bit type. You have a loop that tries to insert N shorts into a buffer that’s N-bytes long; it needs to be 2*N bytes long to fit all your data.

    ByteBuffer byteBuf = ByteBuffer.allocate(2*N);
    while (N >= i) {
        byteBuf.putShort(buffer[i]);
        i++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While converting types, I have found myself using both VB functions and BCL Convert.To*
I am converting some Java code to C# and have found a few labelled
I have found a Tutorial here on how to implement drag and drop in
I have found the way to copy the record that I would like, but
I have found the Form.TopMost property but it puts the form on top of
I have found this project on Codeplex. http://www.codeplex.com/ProjNET I need to integrate this code
Note, I have found the solution to my problem. Please see below. I'm converting
Of. I have found plenty of resources on converting specific url strings (domain.com/?hello=world to
I'm converting an application to use Java 1.5 and have found the following method:
I have some C++ code that I found that does exactly what I need,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.