Android 播放来自 C++ 的原始音频边
我需要能够在 Android 系统的 C++ 端以自定义文件格式传输音频。我正在致力于移植自定义媒体播放器,并且需要能够打开自定义文件并从中传输音频。这很重要,因为我认为从性能角度来看将整个播放器移植到 JAVA 是不可行的,并且通过 JNI 接口移动音频缓冲区我认为速度太慢而无法保持良好的帧速率。我可以通过 OpenGL ES 处理 NDK 端的视频,但音频我不知道如何实现这一点。
I need to be able to stream audio from a custom file format on the C++ side of the Android system. I am working on porting a custom media player and need to be able to open a custom file and stream audio from it. This is important as I do not think porting the whole player to JAVA is feasible from a performance stand point and moving the audio buffers through the JNI interface I believe will be too slow to keep a decent frame rate. I can handle the video on the NDK side through OpenGL ES, but the Audio I have no idea how to make this happen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您通过 JNI 传递音频并查看它的实际执行情况。我发现 JNI 实际上非常高效(如果实现正确),如果它的速度足以满足您的需要,我不会感到惊讶。
只是关于实现的注释,不要让 Java 在每次要传递音频时都创建一个缓冲区,只需在 Java 中(或通过 JNI)创建一个缓冲区,然后在每次需要更新时将其 memcpy 到其中即可。
另外,您应该注意,Android 上的所有音频类当前都是用 C++ 编写并通过 JNI 运行。如果单向速度足够快(我目前正在开发一款游戏,我们可以在某些帧上将超过 0.5mb 的音频数据从 Java 提交到 AudioTrack),那么它可能不会太糟糕其他的操作基本相同,即锁定缓冲区、写入、解锁音频,以及锁定缓冲区、读取、解锁音频类。
I recommend you pass the audio through the JNI and see how it actually performs. I've found that the JNI is actually quite efficient (if implemented correctly) and wouldn't be surprised if it is more than fast enough for what you need.
Just a note on implementation, don't get Java to create a buffer each time you want to pass audio through, simply create a buffer in Java (or via the JNI) and then memcpy into it each time you need to update.
Also, you should note that ALL of the audio classes on the Android are currently written in c++ and run through the JNI. If its fast enough to go one way (I'm currently working on a game where we may submit over 0.5mb of audio data from Java to AudioTrack in on some frames without a problem), then it probably won't be too bad to go the other as its basically the same operation, i.e. lock buffer, write, unlock going to the audio, and lock buffer, read, unlock within the audio classes.
NDK 目前不支持播放音频帧。您必须使用 java AudioTrack API 来实现此目的。
The NDK does not support playing audio frames currently. You have to use the java AudioTrack API to achieve this.