/**
* 查看音频各项参数
* @throws IOException
* @throws ReadOnlyFileException
* @throws TagException
* @throws InvalidAudioFrameException
*/
@ResponseBody
@RequestMapping("/")
public void checkAudioParam() throws IOException, ReadOnlyFileException, TagException, InvalidAudioFrameException {
File originPath = new File("E:/audio/visit/origin/少侠不用刀_(剑网3九周年翻唱丐太ver)-洛少爷-70600494.mp3");
File leftPath = new File("E:/audio/visit/left/");
File rightPath = new File("E:/audio/visit/right/");
RandomAccessFile rdfOrigin = null;
RandomAccessFile rdfLeft = null;
RandomAccessFile rdfRight = null;
// rdfOrigin = new RandomAccessFile(originPath,"r");
rdfLeft = new RandomAccessFile(leftPath,"r");
rdfRight = new RandomAccessFile(rightPath,"r");
MP3File file = new MP3File(originPath);
MP3AudioHeader header = file.getMP3AudioHeader();
("时长: " + ()); //获得时长
("比特率: " + ()); //获得比特率
("音轨长度: " + ()); //音轨长度
("格式: " + ()); //格式,例 MPEG-1
("声道: " + ()); //声道
("采样率: " + ()); //采样率
("MPEG: " + ()); //MPEG
("MP3起始字节: " + 3StartByte()); //MP3起始字节
("精确的音轨长度: " + ()); //精确的音轨长度
// ("声音尺寸: " + toInt(read(rdfOrigin, 4, 4))); // 声音尺寸
// ("音频格式 1 = PCM: " + toShort(read(rdfOrigin, 20, 2))); // 音频格式 1 = PCM
// ("声道: " + toShort(read(rdfOrigin, 22, 2))); // 1 单声道 2 双声道
// ("采样率: " + toInt(read(rdfOrigin, 24, 4))); // 采样率、音频采样级别 8000 = 8KHz
// ("每秒波形数量: " + toInt(read(rdfOrigin, 28, 4))); // 每秒波形的数据量
// ("采样帧大小: " + toShort(read(rdfOrigin, 32, 2))); // 采样帧的大小
// ("采样位数: " + toShort(read(rdfOrigin, 34, 2))); // 采样位数
("---------------------------------------------------Origin-left数据分割线-----------------------------------------------");
("声音尺寸: " + toInt(read(rdfLeft, 4, 4))); // 声音尺寸
("音频格式 1 = PCM: " + toShort(read(rdfLeft, 20, 2))); // 音频格式 1 = PCM
("声道: " + toShort(read(rdfLeft, 22, 2))); // 1 单声道 2 双声道
("采样率: " + toInt(read(rdfLeft, 24, 4))); // 采样率、音频采样级别 8000 = 8KHz
("每秒波形数量: " + toInt(read(rdfLeft, 28, 4))); // 每秒波形的数据量
("采样帧大小: " + toShort(read(rdfLeft, 32, 2))); // 采样帧的大小
("采样位数: " + toShort(read(rdfLeft, 34, 2))); // 采样位数
("---------------------------------------------------left-right数据分割线-----------------------------------------------");
("声音尺寸: " + toInt(read(rdfRight, 4, 4))); // 声音尺寸
("音频格式 1 = PCM: " + toShort(read(rdfRight, 20, 2))); // 音频格式 1 = PCM
("声道: " + toShort(read(rdfRight, 22, 2))); // 1 单声道 2 双声道
("采样率: " + toInt(read(rdfRight, 24, 4))); // 采样率、音频采样级别 8000 = 8KHz
("每秒波形数量: " + toInt(read(rdfRight, 28, 4))); // 每秒波形的数据量
("采样帧大小: " + toShort(read(rdfRight, 32, 2))); // 采样帧的大小
("采样位数: " + toShort(read(rdfRight, 34, 2))); // 采样位数
// rdfOrigin.close();
rdfLeft.close();
rdfRight.close();
}
public static int toInt(byte[] b) {
return (((b[3] & 0xff) << 24) + ((b[2] & 0xff) << 16) + ((b[1] & 0xff) << 8) + ((b[0] & 0xff) << 0));
// return ((b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0] << 0));
}
public static short toShort(byte[] b) {
return (short)(((b[1] & 0xff) << 8) + ((b[0] & 0xff) << 0));
// return (short)((b[1] << 8) + (b[0] << 0));
}
public static byte[] read(RandomAccessFile rdf, int pos, int length) throws IOException {
(pos);
byte result[] = new byte[length];
for (int i = 0; i < length; i++) {
result[i] = ();
}
return result;
}