WAV声音档转PCM
生活随笔
收集整理的這篇文章主要介紹了
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");
}
#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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 代码版本管理软件Git的优势和用法
- 下一篇: excel计算机一级知识点,计算机一级考