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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:40:59+00:00 2026-05-21T03:40:59+00:00

General problem in the following: I decode the audio as follows: ReSampleContext* rsc =

  • 0

General problem in the following:
I decode the audio as follows:

ReSampleContext* rsc = av_audio_resample_init(
        1, aCodecCtx->channels,
        aCodecCtx->sample_rate, aCodecCtx->sample_rate,
        av_get_sample_fmt("u8"), aCodecCtx->sample_fmt,
        16, 10, 0, 1);

while (av_read_frame(pFormatCtx, &packet)>= 0) {
    if (aCodecCtx->codec_type == AVMEDIA_TYPE_AUDIO) {
        int data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE * 2;
        int size=packet.size;
        int decoded = 0;

         while(size > 0) {
             int len = avcodec_decode_audio3(aCodecCtx, pAudioBuffer, 
                 &data_size, &packet);

             //Сonvert audio to sample 8bit
             out_size = audio_resample(rsc, outBuffer, pAudioBuffer, len);

             jbyte *bytes = (*env)->GetByteArrayElements(env, array, NULL);

             memcpy(bytes, outBuffer, out_size);
             (*env)->ReleaseByteArrayElements(env, array, bytes, 0);
             (*env)->CallStaticVoidMethod(env, cls, mid, array, out_size, number);

             size -= len;
             number++;
         }
     }
 }

Next release it AudioTrack. After that, I hear that song that was necessary, but with noise and speed of 2 times larger. In what may be the problem?

UPDATE:
This is Java code:

public static AudioTrack track;
public static byte[] bytes;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    int bufSize = 2048;
    track = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_OUT_MONO, 
                AudioFormat.ENCODING_PCM_8BIT, bufSize, AudioTrack.MODE_STREAM); 

    bytes = new byte[bufSize];
    Thread mAudioThread = new Thread(new Runnable() {
        public void run() {
            int res = main(2, "/sdcard/muzika_iz_reklami_bmw_5_series_-_bmw_5_series.mp3", bytes);
            System.out.println(res);
        } 
    });
    mAudioThread.setPriority(Thread.MAX_PRIORITY);
    mAudioThread.start(); 
}

private static void play(byte[] play, int length, int p) {
    if (p==0){
        track.play();
    }
    track.write(play, 0, length); 
}
  • 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-21T03:40:59+00:00Added an answer on May 21, 2026 at 3:40 am

    This could be a problem of sampling rate mismatch. May be you are creating audioTrack with a lesser sampler rate compared to actual rate.

    It could be also a problem with the AudioTrack channel configuration, as Matthew mentioned.

    May be you should try something like I have answered in this question.

    Because the way you are interacting with JNI from Java, I am not sure, whether that will work. I have little knowledge about JNI. But my code works with me and which is what I am currently using with my app.

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

Sidebar

Related Questions

I ran into the following problem: how to make a general container (HTML +
I have the following problem while i scroll the table view: NSCFString objectAtIndex:]: unrecognized
I've got the following problem with my PMA-GUI: While the data submitted by PHP-Scripts
Consider the following general issue before I go to the specific problem: You use
Is makefile an advanced problem or a general problem for a programmer? For a
Don't be scared of the extensive code. The problem is general. I just provided
just had a general question about how to approach a certain problem I'm facing.
The main problem I'm having is pulling data from tables, but any other general
I am looking for a general and complete solution to this common problem! I
Update: After some more reading I see that this problem is totally general, you

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.