简体   繁体   English

从字节变短然后再变回字节时AudioRecorder的质量下降

[英]AudioRecorder quality degradation when change from byte to short and back to byte

I am writing a recording app for android using AudioRecorder Class. 我正在使用AudioRecorder类编写用于android的录音应用程序。 The code records audio raw data in a byte array then saves it to a WAV file till now all is well. 该代码将音频原始数据记录在字节数组中,然后将其保存到WAV文件中,直到一切正常。 Here is my problem: I need to change each 2 bytes to one short so i can work on audio data then change it back to bytes so I can write to output stream file. 这是我的问题:我需要将每个2字节更改为一个短字节,以便我可以处理音频数据,然后将其更改回字节,以便可以写入输出流文件。 For now there is NO work on audio data just moving from byte to short and back again but for some reason the there is a bad degradation in audio quality here is the code for moving from byte to short and back again: 现在暂时还没有关于音频数据的工作,只是从字节移动到字节,然后又返回,但是由于某种原因,音频质量下降得很厉害,这里是从字节移动到字节,然后再返回的代码:

//16 bit per sample to get correct value of sample convert to short
private short[] ByteToShort (byte[] test)
{
    short[] Sh  = new short[Alldata.size()/2];

    for(int ii=0;ii<Alldata.size()/2;ii++)
    {
        //Sh[ii] = (short) ((short)Alldata.get(2*ii)  | ((short)Alldata.get(2*ii+1))<<8);
        Sh[ii] = (short) ((short)test[2*ii]  | ((short)test[2*ii+1])<<8);

    }
    return Sh;
}
//change back to bytes for input/output streamfiles 
byte[] ShortToByte(short[] data)
{
    byte[] dataByte = new byte[(int) (data.length*2)];
    for(int ii=0;ii<data.length;ii++)
    {
        dataByte[2*ii] = (byte)(data[ii] & 0x00ff);
        dataByte[2*ii+1] = (byte)((data[ii] & 0xff00) >> 8);
    }

    return dataByte;
}

您必须考虑到该byte已签名。

Sh[ii] = (short) (test[2 * ii] & 0xFF | (test[2 * ii + 1] & 0xFF) << 8);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM