我是靠谱客的博主 怡然酸奶,最近开发中收集的这篇文章主要介绍wav文件头读取,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

wav文件头读取

// An highlighted block
#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 filen");
		exit(1);
	}
 
	fread(&wav, 1, sizeof(struct WAV_Format), fp);
 
	printf("ChunkID t%xn", wav.ChunkID);
	printf("ChunkSize t%dn", wav.ChunkSize);
	printf("Format tt%xn", wav.Format);
	printf("Subchunk1ID t%xn", wav.Subchunk1ID);
	printf("Subchunk1Size t%dn", wav.Subchunk1Size);
	printf("AudioFormat t%dn", wav.AudioFormat);
	printf("NumChannels t%dn", wav.NumChannels);
	printf("SampleRate t%dn", wav.SampleRate);
	printf("ByteRate t%dn", wav.ByteRate);
	printf("BlockAlign t%dn", wav.BlockAlign);
	printf("BitsPerSample t%dn", wav.BitsPerSample);
	printf("Subchunk2ID t%xn", wav.Subchunk2ID);
	printf("Subchunk2Size t%dn", wav.Subchunk2Size);
 
	fclose(fp);
 
	return 0;
}

最后

以上就是怡然酸奶为你收集整理的wav文件头读取的全部内容,希望文章能够帮你解决wav文件头读取所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(38)

评论列表共有 0 条评论

立即
投稿
返回
顶部