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

时间:2013-06-27 10:54:21

标签: java android audio audio-recording

我想在我的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)。以下是这两种方法:

第一个:

        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;                    
            }
        }
第二个:

        if(encoding == AudioFormat.ENCODING_PCM_8BIT){
            int len = data.length;
            for (int i=0, i<len; i++){
                data[i] = (byte)(data[i] >> 8);
            }
        }

1 个答案:

答案 0 :(得分:3)

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