Java 从32位样本大小WAV创建样本数组

Java 从32位样本大小WAV创建样本数组,java,audio,wav,sampling,waveform,Java,Audio,Wav,Sampling,Waveform,我得到了一个WAV(32位样本大小,每帧8字节,44100赫兹,PCM_浮点),它需要创建一个样本数组。这是我用于Wav的代码,具有16位样本大小,每帧4字节,44100 Hz,PCM_签名 private float[] getSampleArray(byte[] eightBitByteArray) { int newArrayLength = eightBitByteArray.length / (2 * calculateNumberOfChannels

我得到了一个WAV(32位样本大小,每帧8字节,44100赫兹,PCM_浮点),它需要创建一个样本数组。这是我用于Wav的代码,具有16位样本大小,每帧4字节,44100 Hz,PCM_签名

private float[] getSampleArray(byte[] eightBitByteArray) {

    int newArrayLength = eightBitByteArray.length
            / (2 * calculateNumberOfChannels()) + 1;

    float[] toReturn = new float[newArrayLength];
    int index = 0;

    for (int t = 0; t + 4 < eightBitByteArray.length; t += 2) // t+2 -> skip
                                                              //2nd channel
      {
        int low=((int) eightBitByteArray[t++]) & 0x00ff;
        int high=((int) eightBitByteArray[t++]) << 8;
        double value = Math.pow(low+high, 2);

        double dB = 0;
        if (value != 0) {
            dB = 20.0 * Math.log10(value); // calculate decibel
        }

        toReturn[index] = getFloatValue(dB); //minorly important conversion 
                                             //to normalized values

        index++;

    }

    return toReturn;
}
private float[]getSampleArray(字节[]eightBitByteArray){
int newArrayLength=eightBitByteArray.length
/(2*CalculateEnumberOfChannel())+1;
float[]toReturn=新的float[newArrayLength];
int指数=0;
对于(int t=0;t+4skip
//第二频道
{
int low=((int)eightBitByteArray[t++])&0x00ff;

int-high=((int)eightBitByteArray[t++])像这样的东西应该可以解决这个问题

for (int t = 0; t + 4 < eightBitByteArray.length; t += 4) // t+4 -> skip
                                                          //2nd channel
{
    float value = ByteBuffer.wrap(eightBitByteArray, t, 4).order(ByteOrder.LITTLE_ENDIAN).getFloat();
    double dB = 0;
    if (value != 0) {
        dB = 20.0 * Math.log10(value); // calculate decibel
    }

    toReturn[index] = getFloatValue(dB); //minorly important conversion 
                                         //to normalized values

    index++;
}
for(int t=0;t+4skip
//第二频道
{
float value=ByteBuffer.wrap(eightBitByteArray,t,4).order(ByteOrder.LITTLE_ENDIAN).getFloat();
双分贝=0;
如果(值!=0){
dB=20.0*Math.log10(值);//计算分贝
}
toReturn[index]=getFloatValue(dB);//最小重要的转换
//到标准化值
索引++;
}

另一方面-将瞬时采样转换为dB是毫无意义的。

是的,是的。很抱歉没有提及非常感谢!不幸的是,他们改变了upvote系统,因此我无法给出你的答案