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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:42:03+00:00 2026-05-22T21:42:03+00:00

I need to stream PCM data generated at runtime. So I have a thread

  • 0

I need to stream PCM data generated at runtime. So I have a thread with a loop

public void run() {
  while(...) {
    mAudioTrack.write(getPCM(), ...);
  }
}

Unfortunately this doesn’t work. It seems it doesn’t depend on AudioTrack buffer size. I want it to be very small to simulate sort of low latency behaviour (150 ms) so the user can dinamically change the PCM picked by getPCM()

int bufferSize = 0.150 * sampleRate * channels * bitsPerSample / 8;

However, I tried to increase the buffer size up to 100k with no result

  • 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-22T21:42:04+00:00Added an answer on May 22, 2026 at 9:42 pm

    Here is short example that works for me:

    public class Internal extends Activity
    {   
        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);              
        }
    
        public void onPlayClicked(View v)
        {
            start();    
        }
    
        public void onStopClicked(View v)
        {
            stop();
        }
    
        boolean m_stop = false;
        AudioTrack m_audioTrack;
        Thread m_noiseThread;
    
        Runnable m_noiseGenerator = new Runnable()
        {       
            public void run()
            {
                Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
    
                /* 8000 bytes per second, 1000 bytes = 125 ms */
                byte [] noiseData = new byte[1000];
                Random rnd = new Random();
    
                while(!m_stop)
                {           
                    rnd.nextBytes(noiseData);   
                    m_audioTrack.write(noiseData, 0, noiseData.length);                 
                }
            }
        };
    
        void start()
        {
            m_stop = false;
    
            /* 8000 bytes per second*/
            m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO,
                                            AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */,
                                            AudioTrack.MODE_STREAM);            
    
            m_audioTrack.play();        
    
    
            m_noiseThread = new Thread(m_noiseGenerator);
            m_noiseThread.start();
        }
    
        void stop()
        {
            m_stop = true;          
            m_audioTrack.stop();
        }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stream of u-Law compressed PCM data I am extracting from a
I have a byte stream I need parsed into a struct, and I also
I need a program that I can pipe a raw PCM stream into, and
I have a stream of PCM audio captured from a cell phone, and I
I need to split a PCM audio stream with up to 16 channels into
I need to stream a file to the Response for saving on the end
I need to know how I get the stream of the headers and footers
I need to capture the input stream from a microphone in my application, which
I need to call a method that accepts a stream argument. The method loads
I need to read and write octet streams to send over various networks to

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.