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

  • Home
  • SEARCH
  • 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 9220347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:19:32+00:00 2026-06-18T03:19:32+00:00

im applying DSP effects to my raw audio input which is in byte[2] array

  • 0

im applying DSP effects to my raw audio input which is in byte[2] array format.To apply DSP i need to convert the byte array to float array and back.To convert byte array to float array i use the following code:

private byte[] buffer;
/*
 * 
 * Converts a byte[2] to a float, in LITTLE_ENDIAN format
 */
private float getFloat(byte argB1, byte argB2) {
    return (float) (argB1 | (argB2 << 8));
}
for (int i = 0; i < N / 2; i++) { 
    curSample[i] = getFloat(buffer[i * 2],
    buffer[i * 2 + 1]);}

I need to convert back curSample(which is a float array) to the byte[2] array.How to do that?

  • 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-18T03:19:33+00:00Added an answer on June 18, 2026 at 3:19 am

    To convert byte array to float array, what you are doing does not consider the endianness.

    int myInt = (byte[0] << 24) |
    ((byte[1] & 0xff) << 16) |
    ((byte[2] & 0xff) << 8) |
    (byte[3] & 0xff);
    

    or (for little-endian):

    int myInt = (byte[3] << 24) |
    ((byte[2] & 0xff) << 16) |
    ((byte[1] & 0xff) << 8) |
    (byte[0] & 0xff);
    

    Then you can transform to a float using this:

    float asFloat = Float.intBitsToFloat(asInt);
    

    To convert it back to byte array

      int j=0;
      byte[] byteArray=new byte[4];
      int data=Float.floatToIntBits(asFloat);
      byteArray[j++]=(byte)(data>>>24);
      byteArray[j++]=(byte)(data>>>16);
      byteArray[j++]=(byte)(data>>>8);
      byteArray[j++]=(byte)(data>>>0);
    

    I also find some similar information here

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

Sidebar

Related Questions

While applying jQuery UI autocomplete to an input field, I need to filter several
Why does applying the slice method to the javascript arguments value as follows Array.prototype.slice.call(arguments)
I'm applying some css3 effects using a function it works fine on body page
After applying join condition on two tables I want records which is maximum among
I'm very new to DSP. And have to solve the following problem: applying the
After applying Bootstrap CSS, the mobile view for map which is not in the
Hi im applying custom images to button on different states, for which i create
Applying the standard XSLT copy template, <xsl:template match=@*|node()> <xsl:copy> <xsl:apply-templates select=@*|node()/> </xsl:copy> </xsl:template> to
When applying a multi-project Gradle structure to our project, my settings.gradle looks like this:
When applying the MVP pattern to ASP.NET applications, where does using AJAX to post

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.