首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将PCM 16位音频转换为PCM 8位

将PCM 16位音频转换为PCM 8位
EN

Stack Overflow用户
提问于 2013-06-27 18:54:21
回答 1查看 1.3K关注 0票数 1

我想在我的android录制应用程序中实现使用PCM 16位和PCM 8位进行录制的可能性。我有一个问题converting a byte[] PCM 16 bit to 8 bit,我尝试了不同的方法,but the size of the recording remained the same (for PCM 8 bit the size should be half of the PCm 16 bit)。以下是这两种方法:

第一个:

代码语言:javascript
复制
        if(encoding == AudioFormat.ENCODING_PCM_8BIT){
            int i,j;
            int tempint;
            int len = data.length;
            for (i=1, j=0; i<len; i+=2, j++){
               tempint = ((int) data[i]) ^ 0x00000080;
               data[j] = (byte) tempint;                    
            }
        }

第二个:

代码语言:javascript
复制
        if(encoding == AudioFormat.ENCODING_PCM_8BIT){
            int len = data.length;
            for (int i=0, i<len; i++){
                data[i] = (byte)(data[i] >> 8);
            }
        }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-27 19:21:28

如果您使用相同的数组来存储转换后的数据,那么它当然具有相同的大小。您必须将其写入新数组。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17341236

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档