我正在尝试将MP3音频文件转换为具有相应PCM值的float []数组。这是我的代码:
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("sound.mp3"));
AudioFormat.Encoding targetEncoding = AudioFormat.Encoding.PCM_SIGNED;
AudioInputStream pcmStream = AudioSystem.getAudioInputStream(targetEncoding, AudioInputStream);
byte[] b = new byte[102400];
pcmStream.read(b, 0, b.length);
FloatBuffer l = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();
final float[] audioFloats = new float[l.capacity()];
l.get(audioFloats);
但“audioFloats”数组中返回的值包含 NaN 值的元素,这些元素会导致不良噪声影响。你能帮我找到我的错误吗?