日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WAV声音档转PCM

發布時間:2023/12/14 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WAV声音档转PCM 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include <iostream>
#include <fstream>
using namespace std;

struct wav_struct
{
??? unsigned long file_size;??????? //文件大小
??? unsigned short channel;??????????? //通道數
??? unsigned long frequency;??????? //采樣頻率
??? unsigned long Bps;??????????????? //Byte率
??? unsigned short sample_num_bit;??? //一個樣本的位數
??? unsigned long data_size;??????? //數據大小
??? unsigned char *data;??????????? //音頻數據 ,這里要定義什么就看樣本位數了,我這里只是單純的復制數據

};

int main(int argc,char **argv)
{
??? fstream fs;
??? wav_struct WAV;
??? fs.open("B:\\output.wav",ios::binary|ios::in);

//??? fs.seekg(0x04);??????????????? //從文件數據中獲取文件大小
//??? fs.read((char*)&WAV.file_size,sizeof(WAV.file_size));
//??? WAV.file_size+=8;
???
??? fs.seekg(0,ios::end);??????? //用c++常用方法獲得文件大小
??? WAV.file_size=fs.tellg();

??? fs.seekg(0x14);
??? fs.read((char*)&WAV.channel,sizeof(WAV.channel));

??? fs.seekg(0x18);
??? fs.read((char*)&WAV.frequency,sizeof(WAV.frequency));

??? fs.seekg(0x1c);
??? fs.read((char*)&WAV.Bps,sizeof(WAV.Bps));

??? fs.seekg(0x22);
??? fs.read((char*)&WAV.sample_num_bit,sizeof(WAV.sample_num_bit));

??? fs.seekg(0x28);
??? fs.read((char*)&WAV.data_size,sizeof(WAV.data_size));

??? WAV.data=new unsigned char[WAV.data_size];

??? fs.seekg(0x2c);
??? fs.read((char *)WAV.data,sizeof(char)*WAV.data_size);

??? cout<<"文件大小為? :"<<WAV.file_size<<endl;
??? cout<<"音頻通道數? :"<<WAV.channel<<endl;
??? cout<<"采樣頻率??? :"<<WAV.frequency<<endl;
??? cout<<"Byte率????? :"<<WAV.Bps<<endl;
??? cout<<"樣本位數??? :"<<WAV.sample_num_bit<<endl;
??? cout<<"音頻數據大小:"<<WAV.data_size<<endl;
??? cout<<"最后20個數據:"<<endl;

??? for (unsigned long i=WAV.data_size-20;i<WAV.data_size;i++)
??? {
??????? printf("%x? ",WAV.data[i]);
??? }
??? fs.close();

??? delete[] WAV.data;
??? system("pause");

}

總結

以上是生活随笔為你收集整理的WAV声音档转PCM的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。