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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:50:23+00:00 2026-05-27T14:50:23+00:00

I am facing a problem regarding audio decoding. I have the SPIMP3 library for

  • 0

I am facing a problem regarding audio decoding. I have the SPIMP3 library for mp3 decoding and I am trying to decode mp3’s and storing them to an array of bytes.

Here is the thing, when I try to decode a 2 minute mp3 song it gives me, for example, the following bytes:

[ -1, 0, 42, -115, -45, 0, 14 … etc].

But when I cut that mp3 in half and try to decode the first half I get the following bytes:

[ 1, 0, 0, 65, -97, 135, -64, 32 …etc]

The weird thing is that they don’t match. The only thing that differs here is the audio length, but I am decoding the first part of both of the mp3 samples which is the same.

Here is my code:

public void testPlay(String mp3) {
    try {
        File file = new File(mp3);
        AudioInputStream in = AudioSystem.getAudioInputStream(file);
        AudioInputStream din = null;
        AudioFormat baseFormat = in.getFormat();
        AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                baseFormat.getSampleRate(),
                16,
                baseFormat.getChannels(),
                baseFormat.getChannels() * 2,
                baseFormat.getSampleRate(),
                false);
        din = AudioSystem.getAudioInputStream(decodedFormat, in);

        play(decodedFormat, din);
        spi(decodedFormat, in);
        in.close();
    } catch (Exception e) {
        System.out.println("MP3");
    }

}

private void play(AudioFormat targetFormat, AudioInputStream din) throws IOException, LineUnavailableException {

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte[] data = new byte[4096];
    SourceDataLine line = getLine(targetFormat);

        int nBytesRead = 0, nBytesWritten = 0;
        while (nBytesRead != -1) {
            nBytesRead = din.read(data, 0, data.length);
            if (nBytesRead != -1) {
                nBytesWritten = line.write(data, 0, nBytesRead);
                out.write(data, 0, 4096);
            }

        }

       byte[] audio = out.toByteArray();

}

Is this something to be expected or is there a problem on my code???

How can I change my code to get the same bytes for the matching part of my mp3?

Thank you.

  • 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-27T14:50:24+00:00Added an answer on May 27, 2026 at 2:50 pm

    this line should be:

    out.write(data, 0, nBytesRead);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing a strange problem regarding Hooking. I have a procedure which acts
I'm facing a problem that seems to have no straighforward solution. I'm using java.util.Map
i am facing a problem regarding the thread. I am having a class which
I am facing some problem in iPhone application development for Reading PDF. I have
I'm currently facing in problem using Core Data. I have two entities A and
I'm facing a problem with the android broadcast receiver. I have a login page
im facing a problem regarding my .htaccess file here is the code within the
I facing a problem regarding the import of an excel file into mysql through
I'm facing problem in setting my record value. I have nested record inside store
I'm using the AVAudioRecorder to grab audio from the microphone. The problem i'm facing

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.