使用 AmrInputStream 将 PCM-16 转换为 AMR
我正在使用 AmrInputStream 将 PCM-16 转换为 AMR。 AmrInputStream 的详细信息可以在这里找到 http://hi-android .info/src/android/media/AmrInputStream.java.html
我对编程很陌生,虽然它谈论使用 JNI 和其他东西,但我不知道 JNI 是什么,我也不认为它是本次讨论所需要的。上面的 AmrInputStream 显然在 SDK 和 NDK 中也找不到,但我已经能够使用它。
我一直在互联网上搜索如何使用该流,但没有找到任何示例。最后我进行了实验,发现它与任何输入流都相似。这是我测试过的代码片段
InputStream inStream;
inStream = new FileInputStream("abc.wav");
AmrInputStream aStream = new AmrInputStream(inStream);
File file = new File("xyz.amr");
file.createNewFile();
OutputStream out = new FileOutputStream(file);
byte[] x = new byte[1024];
int len;
while ((len=aStream.read(x)) > 0) {
out.write(x,0,len);
}
out.close();
,它有效(需要将 #!AMR\n 标签添加到输出文件中才能播放。)(编辑:AMR 标签必须是 #!AMR\n)。
我的问题是我只设法让它在以 8000Hz 采样的 PCM-16 文件上工作。用于原始 PCM-16 文件的任何(较高)频率都会导致(欠采样)输出。 AmrInputStream.java 文件中有一个 SAMPLES_PER_FRAME 变量,我尝试使用它,但它似乎没有影响任何内容。
欢迎任何建议或相关讨论!
I'm doing a conversion from PCM-16 to AMR using AmrInputStream. The details for the AmrInputStream can be found here http://hi-android.info/src/android/media/AmrInputStream.java.html
I'm quite new to programming to while it talks about using JNI and stuff, I have no idea what JNI is and I don't think it is required for this discussion. The AmrInputStream above is also apparently not found in the SDK nor the NDK, but I have been able to use it.
I've been searching around the internet for how to use the stream, but have not found any examples. In the end I experimented and found it to be similar to just any InputStream. Here's a code snippet
InputStream inStream;
inStream = new FileInputStream("abc.wav");
AmrInputStream aStream = new AmrInputStream(inStream);
File file = new File("xyz.amr");
file.createNewFile();
OutputStream out = new FileOutputStream(file);
byte[] x = new byte[1024];
int len;
while ((len=aStream.read(x)) > 0) {
out.write(x,0,len);
}
out.close();
I have tested this and it has worked (requiring adding the #!AMR\n tag to the output file for playing.) (Edit: The AMR tag must be #!AMR\n).
My question pertains to that I have only managed to get this to work on a PCM-16 file sampled at 8000Hz. Any (higher) frequency used for the original PCM-16 file results in an (undersampled) output. There is a SAMPLES_PER_FRAME variable in the AmrInputStream.java file which I have tried playing with but it does not seem to affect anything.
Any advise or related discussion is welcomed!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SAMPLES_PER_FRAME 是 amrencoder 一次性处理的数据块(映射到 20 毫秒的音频)。
来自 amr 编码器函数的签名(位于 http:// 的底部hi-android.info/src/android/media/AmrInputStream.java.html)
似乎没有办法将采样率传递给编码器。(gae是本机句柄)
使用此 api 将采样率至少硬编码为 8k
SAMPLES_PER_FRAME is the block of data the amrencoder acts on in one go(which is mapped to 20 msec of audio).
from the signatures of the amr encoder functions (at the bottom of http://hi-android.info/src/android/media/AmrInputStream.java.html)
There doesnt seem to be a way to pass samplerate to the encoder.(gae is native handle)
the sample rate is hardcoded to 8k atleast with this api