使用AudioTrack与JLayer德codeR [英] Use AudioTrack with JLayer decoder

查看:252
本文介绍了使用AudioTrack与JLayer德codeR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的这是使用JLayer库脱code MP3文件中的Andr​​oid应用程序(我需要访问音频采样),并AudioTrack对象来播放它。我有这样的事情:

I'm working on the Android application which is using JLayer library to decode MP3 file (I need access to audio samples) and AudioTrack object to play it. I have something like this:

int timeMarker = 0;
int timeStep = 5000;

while (!isCancelled()) {
    outSignalBuffer = decode(fileToPlay.getPath(), timeMarker, timeStep, bufferSize);
    audioTrack.write(outSignalBuffer, 0, outSignalBuffer.length);
    //publishProgress(outSignalBuffer);
    timeMarker += timeStep;
}

这code被放置在作为AsyncTask的创建自定义播放器。一般来说,因为我听到的声音文件我去code和写入方法效果好。问题是,我的声音每隔5秒(时间步长= 5000毫秒)定期混蛋。当我看到audioTrack.write(...)块我的异步任务,所以在短暂的暂停,每次经过的步骤通过等待从德code方法导致引起的。

This code is placed in my custom player created as AsyncTask. In general my decode and write method works OK because I hear sound file. The problem is, that my sound regularly jerk in every 5 seconds (timeStep = 5000 ms). As I see audioTrack.write(...) blocks my async task, so the short pause after every time Steps is caused by waiting to result from decode method.

你有什么建议要正确交付outSignalBuffer写从去codeR方法来获得流畅audioTrack球员最好的办法?

Do you have any advices what is the best approach to correctly deliver outSignalBuffer to write method from decoder to get smooth audioTrack player?

推荐答案

您是否尝试过定时去code和audioTrack.write功能,看看有什么拖住你的异步任务是什么?我不认为audioTrack.write会有问题。

Have you tried timing the decode and audioTrack.write functions to see what is holding up your Async task? I wouldn't think audioTrack.write would be the problem.

我与JLayer的经验是,它可以为实时解码太慢了,特别是如果你有CD质量的音频(立体声,44.1kHz的采样率)的工作。

My experience with JLayer is that it can be too slow for real-time decoding, especially if you're working with CD-quality audio (stereo, 44.1kHz sampling rate).

如果你可以提高你的基地SDK,媒体codeC可能是一个很好的路要走:的 http://developer.android.com/reference/android/media/Media$c$cc.html

If you can raise your base SDK, Media Codec might be a good way to go: http://developer.android.com/reference/android/media/MediaCodec.html

您也可以看看使用openSL ES实现您的音频。这篇文章涉及的一些Android的音频节目的挑战和解决方案:<一href=\"http://stackoverflow.com/questions/18794965/android-audio-programming-nightmare-soundpool-audiotrack-arrghh/19103704#19103704\">Android音频节目的噩梦 - 的Soundpool,audiotrack arrghh

You can also look at implementing your audio using openSL es. This post deals with some of the challenges and solutions for Android audio programming: Android audio programming nightmare - soundpool, audiotrack arrghh?

这篇关于使用AudioTrack与JLayer德codeR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆