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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:41:45+00:00 2026-06-04T14:41:45+00:00

I have 2 files. Once is an mp3 being decoded to pcm into a

  • 0

I have 2 files. Once is an mp3 being decoded to pcm into a stream and I have a wav being read into pcm also. The samples are being held in a short data type.

Audio stats: 44,100 samples * 16 bits per sample * 2 channels = 1,411,200 bits/sec

I have X seconds of silence that I need to apply to the beginning of the mp3 pcm data and I am doing it like this:

private short[] mp3Buffer = null;
private short[] wavBuffer = null;
private short[] mixedBuffer = null;

double silenceSamples = (audioInfo.rate * padding) * 2;
for (int i = 0; i < minBufferSize; i++){

    if (silenceSamples > 0 ){

        mp3Buffer[i] = 0; //Add 0 to the buffer as silence

        mixedBuffer[i] = (short)((mp3Buffer[i] + stereoWavBuffer[i])/2);  
        silenceSamples = silenceSamples - 0.5;
    }
    else
        mixedBuffer[i] = (short)((mp3Buffer[i] + stereoWavBuffer[i])/2);
}

The audio is always off. Sometimes its a second or two too fast, sometimes its a second or two too slow too slow. I dont think its a problem with the timing as I start the audiorecord(wav) first and then set a start timer->start mediaplayer(already prepared)->end timer and setting the difference to the “padding” variable. I am also skipping the 44kb when from the wav header.

Any help would be much appreciated.

  • 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-04T14:41:47+00:00Added an answer on June 4, 2026 at 2:41 pm

    I’m assuming you are wanting to align two sources of audio in some way by inserting padding at the start of one of the streams? There are a few things wrong here.

    mp3Buffer[i] = 0; //Add 0 to the buffer as silence
    

    This is not adding silence to the beginning, is is just setting the entry at offest [i] in the array to 0. The next line:

    mixedBuffer[i] = (short)((mp3Buffer[i] + stereoWavBuffer[i])/2);
    

    Then just overwrites this value.

    If you are wanting to align the streams in some way, the best way to go about it is not to insert silence at the beginning of either stream, but to just begin mixing in one of the streams at an offset from the other. Also it would be better to mix them into a 32 bit float and then normalise. Something like:

        int silenceSamples = (audioInfo.rate * padding) * 2;
                float[] mixedBuffer = new float[minBufferSize + silenceSamples]
        for (int i = 0; i < minBufferSize + silenceSamples; i++){
    
        if (i < silenceSamples )
        {       
            mixedBuffer[i] = (float) stereoWavBuffer[i];  
        }
        else if(i < minBufferSize)
        {
            mixedBuffer[i] = (float) (stereoWavBuffer[i] + mp3Buffer[i-silenceSamples]);
        }
        else 
        {
            mixedBuffer[i] = (float) (mp3Buffer[i-silenceSamples]);
        }
    

    To normalise the data you need to run through the mixedBuffer and find the absolute largest value Math.abs(...), and then multiple all the values in the array by 32,767/largestValue – this will give you a buffer where the largest value fits back into a short without clipping. Then iterate through your float array moving each value back into a short array.

    I’m not sure what your minBufferSize is – this will need to be large enough to get all your data mixed.

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

Sidebar

Related Questions

On a typical OS how many files can i have opened at once using
In short, I don't want to load an entire wav file into anOpenAL buffer,
Some of us programmers have to deal with graphic files every once and awhile...
I have one thousand .mp3 files in my Resources folder within an iOS 4.2
I have two files once is named as test.cpp and another as ani.cpp. test.cpp
I have some files: core.php : require_once 'logger.php'; require_once 'smth_else.php'; $Logger = new Logger();
I have an autocomplete event that fires correctly once a value is selected. I
I have an xml file populated with keys and once a particular key has
On a page i have a flash file. I click it once to start
I have an ajax call that fires multiple times but is called once. function

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.