如何将 .WAV 音频数据样本转换为双精度类型? [英] How to convert a .WAV audio data sample into an double type?

查看:62
本文介绍了如何将 .WAV 音频数据样本转换为双精度类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个处理音频数据的应用程序.我正在使用 java(我添加了 MP3SPI、Jlayer 和 Tritonus).我正在将音频数据从 .wav 文件提取到字节数组.我正在使用的音频数据样本是 16 位立体声.

I'm working on an application that processes audio data. I'm using java (I've added MP3SPI, Jlayer, and Tritonus). I'm extracting the audio data from a .wav file to a byte array. The audio data samples I'm working with are 16 bits stereo.

根据我读过的一个样本的格式是:

According to what I've read the format for one sample is:

AABBCCDD

其中 AABB 代表左声道和 CCDD 右声道(每个声道 2 个字节).我需要将此示例转换为双值类型.我正在阅读有关数据格式的信息.Java 使用大端,.wav 文件使用小端.我有点困惑.你能帮我完成转换过程吗?谢谢大家

where AABB represents left channel and CCDD rigth channel (2 bytes for each channel). I'd need to convert this sample into a double value type. I've reading about data format. Java uses Big endian, .wav files use little endian. I'm a little bit confused. Could you please help me with the conversion process? Thanks you all

推荐答案

警告:整数和字节是有符号的.也许你在打包时需要屏蔽低字节:

Warning: integers and bytes are signed. Maybe you need to mask the low bytes when packing them together:

for (int i =0; i < length; i += 4) {
    double left = (double)((bytes [i] & 0xff) | (bytes[i + 1] << 8));
    double right = (double)((bytes [i + 2] & 0xff) | (bytes[i + 3] << 8));

    ... your code here ...

}

这篇关于如何将 .WAV 音频数据样本转换为双精度类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆