使⽤⾳频分析⼯具audacity分析wave⽂件下载安装
audacity也有ubuntu版本,通过命令sudo apt install audacity安装
startup.wav⽂件内容
波形
wav 格式,是微软开发的⼀种⽂件格式规范,整个⽂件分为两部分,第⼀部分是“⽂件头”,记录重要
的参数信息,对于⾳频⽽⾔,就包括:采样率、通道数、位宽等等;第⼆部分是“数据块”,即⼀帧⼀帧的⼆进制数据,对于⾳频⽽⾔,就是原始的 PCM 数据。所以wav格式 = Header(44 bytes) + data
下图的前44个字节表⽰wave⽂件头
wave⽂件头的数据类型是:
data数据区PCM数据格式:
解析代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct WaveHeader{
int riff_id;
int riff_sz;
int riff_fmt;
int fmt_id;
int fmt_sz;
short audio_fmt;
short num_chn;
int sample_rate;
int byte_rate;                                                                                                                                                                                              short block_align;
short bits_per_sample;
int data_id;
int data_sz;
} WaveHeader;
int main(void)
{
FILE *stream;
WaveHeader wh;
memset(&wh, 0x00, sizeof(wh));
printf("sizeof(WaveHeader) = %ld.\n", sizeof(WaveHeader));
fprintf格式if((stream=fopen("startup.wav","ro"))==NULL)
{
fprintf(stderr,"Can not open file.\n");
return 0;
}
printf("open success.\n");
fseek(stream, 0, SEEK_SET);
fread(&wh,1,sizeof(wh),stream);
fclose(stream);
printf("riff_id %d,\n" \
"riff_size %d\n" \
"num_chn %d.\n" \
"sample_rate %d.\n" \
"byte_rate %d.\n" \
"block_align %d.\n" \
, wh.riff_id, wh.riff_sz, wh.num_chn, wh.sample_rate, wh.byte_rate, wh.block_align);
return 0;
}
同理,将PCM⽂件转换为WAVE格式,其实就是在PCM前⾯加上了44个字节的头.
结束!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。