当前位置:网站首页>wav文件(波形文件)格式分析与详解
wav文件(波形文件)格式分析与详解
2022-06-25 07:36:00 【u013250861】
WAV文件是在PC机平台上很常见的、最经典的多媒体音频文件,最早于1991年8月出现在Windows 3.1操作系统上,文件扩展名为WAV,是WaveFom的简写,也称为波形文件,可直接存储声音波形,还原的波形曲线十分逼真。
WAV文件格式简称WAV格式是一种存储声音波形的数字音频格式,是由微软公司和IBM联合设计的,经过了多次修订,可用于Windows,Macintosh,Linix等多种操作系统,详述如下。
一、波形文件的基础知识
1、波形文件的存储过程
声源发出的声波通过话筒被转换成连续变化的电信号,经过放大、抗混叠滤波后,按固定的频率进行采样,每个样本是在一个采样周期内检测到的电信号幅度值;接下来将其由模拟电信号量化为由二进制数表示的积分值;最后编码并存储为音频流数据。
有的应用为了节省存储空间,存储前,还要对采样数据先进行压缩。
2、WAV文件的编码
编码包括了两方面内容,一是按一定格式存储数据,二是采用一定的算法压缩数据。
WAV格式对音频流的编码没有硬性规定,支持非压缩的PCM(Puls Code Modulation)脉冲编码调制格式,还支持压缩型的微软自适应分脉冲编码调制Microsoft ADPCM(Adaptive Differential Puls Code Modulation)、国际电报联盟(International Telegraph Union)制定的语音压缩标准ITUG.711 a-law、ITU G.711-law、IMA ADPCM、ITU G.723 ADPCM (Yamaha)、GSM 6.10、ITU G.721 ADPCM编码和其它压缩算法。MP3编码同样也可以运用在WAV中,只要安装相应的Decode,就可以播放WAV中的MP3音乐。
解析代码如下:
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
struct WAV_Format {
uint32_t ChunkID; /* "RIFF" */
uint32_t ChunkSize; /* 36 + Subchunk2Size */
uint32_t Format; /* "WAVE" */
/* sub-chunk "fmt" */
uint32_t Subchunk1ID; /* "fmt " */
uint32_t Subchunk1Size; /* 16 for PCM */
uint16_t AudioFormat; /* PCM = 1*/
uint16_t NumChannels; /* Mono = 1, Stereo = 2, etc. */
uint32_t SampleRate; /* 8000, 44100, etc. */
uint32_t ByteRate; /* = SampleRate * NumChannels * BitsPerSample/8 */
uint16_t BlockAlign; /* = NumChannels * BitsPerSample/8 */
uint16_t BitsPerSample; /* 8bits, 16bits, etc. */
/* sub-chunk "data" */
uint32_t Subchunk2ID; /* "data" */
uint32_t Subchunk2Size; /* data size */
};
int main(void)
{
FILE *fp = NULL;
struct WAV_Format wav;
fp = fopen("test.wav", "rb");
if (!fp) {
printf("can't open audio file\n");
exit(1);
}
fread(&wav, 1, sizeof(struct WAV_Format), fp);
printf("ChunkID \t%x\n", wav.ChunkID);
printf("ChunkSize \t%d\n", wav.ChunkSize);
printf("Format \t\t%x\n", wav.Format);
printf("Subchunk1ID \t%x\n", wav.Subchunk1ID);
printf("Subchunk1Size \t%d\n", wav.Subchunk1Size);
printf("AudioFormat \t%d\n", wav.AudioFormat);
printf("NumChannels \t%d\n", wav.NumChannels);
printf("SampleRate \t%d\n", wav.SampleRate);
printf("ByteRate \t%d\n", wav.ByteRate);
printf("BlockAlign \t%d\n", wav.BlockAlign);
printf("BitsPerSample \t%d\n", wav.BitsPerSample);
printf("Subchunk2ID \t%x\n", wav.Subchunk2ID);
printf("Subchunk2Size \t%d\n", wav.Subchunk2Size);
fclose(fp);
return 0;
}
ByteRate计算方法是SampleRate * NumChannels * BitsPerSample/8,那么这个公式计算出来的是1秒钟音频数据大小,单位为Byte,以44100、16bit、2通道为例,那么计算出来值为176400,根据总音频数据大小,可以得出播放时间的计算公式为Subchunk2Size / ByteRate。
表 1
| 块标识(4Bytes) |
|---|
| 块长度(4Bytes) |
| 数据 |
边栏推荐
- 在二叉树(搜索树)中找到两个节点的最近公共祖先(剑指offer)
- How to analyze the coupling coordination index?
- Similarity calculation method
- Sharepoint:sharepoint server 2013 and adrms Integration Guide
- 钱堂教育商学院给的证券账户安全吗?能开户吗?
- 软件确认测试有什么作用?确认测试报告的价格是多少?
- Meaning of Jieba participle part of speech tagging
- Data preprocessing: discrete feature coding method
- Check whether the point is within the polygon
- linux中的mysql有10061错误怎么解决
猜你喜欢

Stack awareness - stack overflow instance (ret2libc)

以科技赋能设计之美,vivo携手知名美院打造“产学研”计划

How to calculate the information entropy and utility value of entropy method?

In Section 5 of bramble pie project practice, Nokia 5110 LCD is used to display Hello World

Bluecmsv1.6-代码审计
![[operation tutorial] how does the tsingsee Qingxi video platform import the old database into the new database?](/img/21/08194ac26dec50c222b88f1f64f894.png)
[operation tutorial] how does the tsingsee Qingxi video platform import the old database into the new database?

Home server portal easy gate

C language "Recursion Series": recursively realizing the n-th power of X

leetcode. 13 --- Roman numeral to integer

How to increase the monthly salary of software testing from 10K to 30K? Only automated testing can do it
随机推荐
Is it safe to open a stock account online now?
InfluxDB时序数据库
EasyPlayer流媒体播放器播放HLS视频,起播速度慢的技术优化
[summary] 1361- package JSON and package lock JSON relationship
Wechat applet_ 7. Project practice, local life
openid是什么意思?token是什么意思?
Various synchronous learning notes
QSS 不同风格的按钮
微信小程序_7,项目练习,本地生活
Swiperefreshlayout+recyclerview failed to pull down troubleshooting
Want to open an account, is it safe to open an online stock account?
Measure the current temperature
Sampling strategy and decoding strategy based on seq2seq text generation
Bluecmsv1.6- code audit
故障:Outlook 收发邮件时的 0x800CCC1A 错误
Unity Addressable批量管理
Meaning of Jieba participle part of speech tagging
How to interpret the information weight index?
Data preprocessing: discrete feature coding method
tp6自动执行的文件是哪个?tp6核心类库有什么作用呢?