第一次写这种音频文件转化为图像显示,遇到了好多困难,百度了一些方法都不正确,终于自己搞定了。
源码地址:
http://download.csdn.net/download/qq_40006363/10131910
部分主要代码:
class WAVReader //wav 文件读取类
{private string Id; //文件标识
private double Size; //文件大小
private string Type; //文件类型
private string formatId;
private double formatSize; //数值为16或18,18则最后又附加信息
private int formatTag;
private int num_Channels; //声道数目
private int SamplesPerSec; //采样率
private int AvgBytesPerSec; //每秒所需字节数
private int BlockAlign; //数据块对齐单位(每个采样需要的字节数)
private int BitsPerSample; //每个采样需要的bit数
private string additionalInfo; //附加信息
private string dataId;
private int dataSize;
public List<double> wavdata = new List<double>();
public void ReadWAVFile(string filePath) //读取波形文件并显示
{
if (filePath == "") return;
byte[] id = new byte[4];
byte[] size = new byte[4];
byte[] type = new byte[4];
byte[] formatid = new byte[4];
byte[] formatsize = new byte[4];
byte[] formattag = new byte[2];
byte[] numchannels = new byte[2];
byte[] samplespersec &