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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:11:55+00:00 2026-05-23T08:11:55+00:00

I’m going to be processing a lot of audio files, I don’t need to

  • 0

I’m going to be processing a lot of audio files, I don’t need to play the files, but I want to be able to get the volume level at a regular interval (e.g. every second), so I can roughly graph the overall volume level throughout the file. I’ve used the java Sound API to read the frames of the file, but I’m not sure how to interpret them (i’m not sure how to deal with the little-endian as well splitting the frame into two channels), and I tried sending the AudioInputStream to a SourceDataLine, and calling getLevel() on the dataline every second, but it always returned 0.

  • 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-05-23T08:11:56+00:00Added an answer on May 23, 2026 at 8:11 am

    If you have signed PCM, the values decoded from the bytes will have the range of a Java short integer (-32768 to 32767). The nature of a sound wave, though, is to sweep back and forth, so at any single frame, the value could be almost anywhere and thus not particularly well correlated with the volume you hear.

    So, I suspect you will have to look at many samples and do some sort of analysis in the aggregate. Perhaps add up all the deviations from 0 as absolute values and divide by the number of frames? How many frames would be needed? Well, if we want to include, say, bass sound waves that cycle at 50 cps, and want to make sure we include an entire cycle, that’s 1/50 of a full second’s worth of frames. If you sample rate is 44100fps, that’s 8805 frames! But perhaps using this rolling average distorts the contributions of other nearby frequency values?

    Caveat, I’m mostly self-taught, so there may be a better way to do this.

    Following is the code line I use to convert a frame of a little-endian track to a float between -1 and 1 (er, 0.999…), where buffer is a byte array:

    float audioVal  = (float)( ( ( buffer[i+1] << 8 )   
        | ( buffer[i] & 0xff ) ) / 32768.0 ); 
    

    If you search, there are other posts that have similar conversions, here on Stack Overflow. The MSB is shifted and retains its sign. The LSB is &’d with an ff hexadecimal to make sure the “sign bit” is interpreted as being part of the numeric value. The MSB & LSB are |’d together and divided by the largest possible short int value to “normalize” the range. I think the four bytes of a frame for little endian 16-bit encoding are ordered as follows: b[0] = left LSB, b[1] = left MSB, b[2] = right LSB, b[3] = right MSB. I can’t recall where I saw this officially defined or posted though. It would be embarressing to have swapped the left & right!

    You would want to do an ABS before finding the moving average. Maybe the ABS could be built into the conversion to save a couple cpus.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I want to construct a data frame in an Rcpp function, but when I
I have thousands of HTML files to process using Groovy/Java and I need to
I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.