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 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

Note: A detailed answer to the more general problem is in Stack Overflow question
How can the following problem be dealt with? We're using lazy loaded NHibernate properties
I have the following entity (not exact but gives a general idea): @Entity public
The following code is the simplified version of my problem: public partial class Form1
I'm considering a hypothetical problem, and looking for guidance on how to approach solving
Sorry in advance for the long question, it's long because I've been digging at
This is more of a design question that others may have had similar experience
Having considerable trouble with some pointer arithmatic. I think I get the concepts (pointer
In WPF most controls have MouseUp and MouseDown events (and the mouse-button-specific variations) but
I'm currently debugging my transposition table for a chess variant engine where pieces can

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.