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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:48:26+00:00 2026-06-14T15:48:26+00:00

High Level: I use the same encoder in two different ways. Way #1: record

  • 0

High Level:

I use the same encoder in two different ways.

Way #1: record raw audio and save to an entire file, then compress file after it is all finished. RESULT Flawless audio

Way #2: record raw audio, encode it frame by frame. RESULT Audible skipping

Why does way #2 cause skipping?

Low Level

Code for way #1 (writing to FileOutputStream fos, and compress after all writing is finished)

public void writeSample(short[] buf) throws IOException {
            byte[] byteArray = Util.toByteArray(buf,false);
            bytesWritten += byteArray.length;
            fos.write(byteArray);
        }

Code for way #2

public void writeSample(short[] buf) throws IOException {
            byte[] byteArray = Util.toByteArray(buf,false);
            bytesWritten += byteArray.length;
            encoder.encode(byteArray);
        }

ALMOST PERFECT:
The length of the short buf in way #2 is 15360. Since this is an odd sized number, I employed this technique: but there is stil a slight audible skipping:

      ByteArrayInputStream bais = new ByteArrayInputStream(byteArray);
      byte[] readme = new byte[4096];
      int count = bais.read(readme);
      while ( count != -1 ) {
        System.out.println("READING :"+count+ " bytes");
        if(bais.available() < 4096) {
          System.out.println ("LESS THAN 4096 available: "+bais.available());
          byte[] remain = new byte[bais.available()];
          bais.read(remain);
          aacEncoder.encode(remain);
          break;
        }
        aacEncoder.encode(readme);
        count = bais.read(readme);
      }
  • 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-14T15:48:28+00:00Added an answer on June 14, 2026 at 3:48 pm

    Here’s the deal: when the encoder encodes, it doesn’t always take the same amount of time. Sometimes it just stashes some data away for later, and sometimes it actually does a whole lot of number crunching. It has to wait for enough audio to encode an entire MP3 “frame” or it will just stash data.

    Every time there’s a call for new data that requires number crunching, if it takes longer than the amount of time the audio represents, there’s a risk that a dropout will occur.

    The solution is to have your record thread fill a buffer and have second thread do all the work that might slow things down, or take an unpredictable amount of time. That includes encoding and writing to the file.

    For your buffer, if you are targeting android 2.3 or later, you can use the piped I/O. This is not technically a ringbuffer because it blocks, but in my experience it works well enough. (This api is available in earlier versions of android, but you can’t set the buffer size. Grrr!)

    You might find this link helpful for understanding how the audio IO actually works conceptually: http://blog.bjornroche.com/2011/11/slides-from-fundamentals-of-audio.html

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

Sidebar

Related Questions

At a high level, how would you use the execve() function to write a
Are there any high-level, cross-platform, and abstracted (simple to use) widget toolkits for C
Are there any easy-to-use , high-level classes or libraries that let you interact with
I have to use CoreData based database to store my data. At high-level my
How to save a variable at application level(same for all users) in php which
This is a high-level project organization question. What is the proper way to organize
High Level With StructureMap, Can I define a assembly scan rule that for an
The high level problem we're having is this. We've got Apache Wave installed and
I find that many high level functions are missing in most well-known javascript libraries
Are there any high level language that don't support using C++ libraries?

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.