Skip to content

关于正确获取采样位数 #9

@zhangxin1989

Description

@zhangxin1989

我看你代码里面是这么写的,但是很多时候拿到的都是0
byteNumber = (outputFormat.containsKey("bit-width") ? outputFormat.getInteger("bit-width") : 0) / 8;

搜了下,建议用下面这种方式更合理点
//此处用于获取每个采样的位数
int pcm = outputFormat.containsKey("pcm-encoding") ? outputFormat.getInteger("pcm-encoding") : AudioFormat.ENCODING_PCM_16BIT;
if (pcm == AudioFormat.ENCODING_PCM_8BIT) {
byteNumber = 1;
} else if (pcm == AudioFormat.ENCODING_PCM_16BIT) {
byteNumber = 2;
} else if (pcm == AudioFormat.ENCODING_PCM_FLOAT) {
byteNumber = 4;
} else {
byteNumber = 2;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions