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 9072013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:03:58+00:00 2026-06-16T18:03:58+00:00

Before I ask for help, let me tell you what I did: Assuming I

  • 0

enter image description here


Before I ask for help, let me tell you what I did:
Assuming I have a sampling rate of 8000Hz and sample size of 16 bits (2 bytes), at the end of the second I need 16000 byte or 8000 short.
Now I have a 10fps recording speed then for each fps I need 16000/10 = 1600 byte.
So, here is how the story proceeds:

Variables Declared:

byte[] eachPass = new byte[1600]; //used to store data from TargetDataLine for each pass
byte[] backingArray = new byte[16000]; //the complete data for one second
ByteBuffer buffer = ByteBuffer.wrap(backingArray); //buffer which stores the complete data
short[] audioSample = new short[16000/2]; //audio samples to be encoded
int passCounter = 0; /* After 10th pass, convert the byte[] to short[]
                      * using ByteBuffer */
int seconds = 0; // used to store the position of the packet

Looping and subsequent conversion of byte[] to short[]

while(keepCapturing == true){
    -- set up the java.awt.Robot and TargetDataLine before entering the loop --
    -- use java.awt.Robot to record the screen --
    -- do some other stuff, if needed --
    fromMic.read(eachPass,0,eachPass.length); // read data from microphone
    buffer.put(eachPass); //put it in  a bigger buffer

    if(passCounter!=0 && passCounter%10==0){ // is it 10th frame?
        passCounter = 0; //reset counter
        seconds++;
        buffer.asShortBuffer.get(audioSamples); //get short[] in BigEndian format
        -- encode the audio at position (seconds-1) --
        buffer.clear();
    }else{
        passCounter++;
    }  

Issues

  • Even though buffer.position() returns 16000 in the if statement, I get a BufferUnderflowException when I do buffer.asShortBuffer.get(audioSamples);
  • I used java.util.Arrays.toString() to see what my eachPassand audioSamples contains, I got some numbers like -107, 0, 32, etc in eachPass and all zeroes in audioSamples. Why?
  • veterans, will you please help me nail this code? I have no clue what’s going on.

    • 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-16T18:04:00+00:00Added an answer on June 16, 2026 at 6:04 pm

      You are forgetting to flip the buffer before reading the data, this is why nothing in being written into audioSamples.

      buffer.flip();
      buffer.asShortBuffer.get(audioSamples);
      
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report

    Sidebar

    Related Questions

    Before I ask the question let me state that I have attempted to google
    I don't know if this question has been ask before. But I have a
    before I ask my question I wanted to let everybody know that I appreciate
    I never use jQuery before so I ask a friend to help me with
    before you ask I have looked around for a solution to my problem and
    Before I ask my question, let me just say that I know very little
    Before I ask the question let me just clarify that the objective of this
    I feel embarrassed that I have to come and ask for help with this,
    I have difficulty to solve this and would ask your help ! I'm trying
    Before I ask my question, I want to mention that I am only today

    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.