在android中将16位pcm音频下采样为8位
我想将 16 位 pcm 音频下采样到 8 位,然后在 android 中将相同的音频从 8 位上采样回 16 位。我正在使用这个似乎有效:
int tempint;
for (int i=1, j=0; i<tempBuffer.length; i+=2, j++)
{
tempint = ((int) tempBuffer[i]) ^ 0x00000080;
tempBuffer[j] = (byte) tempint;
Log.e("test","------------* COUNTER -> "+j+" BUFFER VALUE -> "+tempBuffer[j]+"*-----------");
}
其中 tempbuffer 是一个短 [] ,而 tempint 是一个 int 。 谁能告诉我这是否工作正常,因为我是初学者,我也使用它将字节 [] 转换回短 [],
for (int x=1, j=0; x<music.length; x+=2, j++)
{
tempint = ((int) music[x])& 0xFF;
music[j] = tempint.shortValue();
Log.e("maxsap","------------*"+ music[j]+"*-----------");
}
我不确定它是否有效。
I would like to downsample 16 bit pcm audio to 8 bit and then upsample the same from 8 bit back to 16 bit in android. I am using this which seems to work:
int tempint;
for (int i=1, j=0; i<tempBuffer.length; i+=2, j++)
{
tempint = ((int) tempBuffer[i]) ^ 0x00000080;
tempBuffer[j] = (byte) tempint;
Log.e("test","------------* COUNTER -> "+j+" BUFFER VALUE -> "+tempBuffer[j]+"*-----------");
}
where tempbuffer is a short [] and tempint is an int.
Can anyone tell me if this works fine because I am a starter, also I am using this to convert the byte [] back to a short []
for (int x=1, j=0; x<music.length; x+=2, j++)
{
tempint = ((int) music[x])& 0xFF;
music[j] = tempint.shortValue();
Log.e("maxsap","------------*"+ music[j]+"*-----------");
}
which I am not sure it is working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设 8 位和 16 位音频都是带符号的 PCM:
16 位到 8 位:
8 位到 16 位:
如果 8 位 PCM 是“偏移二进制”(具有隐式偏差的无符号格式),则转换将为:
16 位到 8 位:
8 位到 16 位:
理想情况下,您会在从 8 位转换为 16 位时添加抖动,但您可能无法承担这样做的计算成本。
另请注意,术语“上采样”和“下采样”通常指改变采样率。您在这里所做的不是重新采样,而是更改位深度或重新量化数据。
Assuming both 8 bit and 16 bit audio are signed PCM:
16 bits to 8 bits:
8 bits to 16 bits:
If the 8 bit PCM is "offset binary" however (an unsigned format with an implicit bias) then the conversions would be:
16 bits to 8 bits:
8 bits to 16 bits:
Ideally you would add dithering when converting from 8 bits up to 16 bits but you may not be able to afford the computational cost of doing this.
Note also that the terms "upsampling" and "downsampling" usually refer to changing sample rates. What you're doing here is not re-resampling, but changing the bit depth or re-quantizing the data.