小编Aar*_*ron的帖子

字节数组为短数组,并在java中再次返回

我有一些问题,将音频数据存储在一个字节数组中,将其转换为大端短数组,对其进行编码,然后将其更改回字节数组.这就是我所拥有的.原始音频数据存储在audioBytes2中.我使用相同的格式进行解码,而cos函数则使用减号.不幸的是,更改字节和短数据类型是不可协商的.

    short[] audioData = null;
    int nlengthInSamples = audioBytes2.length / 2;
    audioData = new short[nlengthInSamples];

    for (int i = 0; i < nlengthInSamples; i++) {
       short MSB = (short) audioBytes2[2*i+1];
       short LSB = (short) audioBytes2[2*i];
       audioData[i] = (short) (MSB << 8 | (255 & LSB));
    }

    int i = 0;
    while (i < audioData.length) {
        audioData[i] = (short)(audioData[i] + (short)5*Math.cos(2*Math.PI*i/(((Number)EncodeBox.getValue()).intValue())));
        i++;
    }

    short x = 0;
    i = 0;
    while (i < audioData.length) {
        x = audioData[i];
        audioBytes2[2*i+1] = (byte)(x …
Run Code Online (Sandbox Code Playgroud)

java arrays byte short type-conversion

43
推荐指数
5
解决办法
4万
查看次数

标签 统计

arrays ×1

byte ×1

java ×1

short ×1

type-conversion ×1