想要读取wav文件必须要知道wav头文件的信息,前人已有太多解析,此处不做详解。可以参考链接:https://blog.csdn.net/vacu_um/article/details/70195761。头文件中重点要关心的信息是文件大小,单通道还是双通道,以及数据长度。
//wav头格式
struct WavHead{
char RIFF[4]; //头部分那个RIFF
long int filesize;//存的是后面所有文件大小
char WAVE[4];
char FMT[4];
long int size1;//存的是fmt保存的大小,包含这之后,data前面几个,共16个
short int fmttag;//1
short int channel;//1
long int samplespersec;//每秒采样数
long int bytepersec;
short int blockalign;
short int bitpersamples;
char DATA[4];
long int datasize;//剩下文件大小
};
文件读取的内容是和matlab读取出来的数组是一致的:
#include <iostream>
#include <fstream>
#include <string.h>
#include<math.h>
#include<cmath>
#include<stdlib.h>
#include <bitset>
#include <iomanip>
using namespace std;
struct WavHead{
char RIFF[4]; //头部分那个RIFF