⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 write_wav.c

📁 4.8k/s速率FS1016标准语音压缩源码
💻 C
字号:
#include	<stdio.h>
#include	<stdlib.h>
#include    <string.h>

#define MAXSIZE 1024
#define SIGMAX 32767

void write_wav(
float output[], 
FILE *fp_out, 
int size, 
int num_samps
)

{
    int				i;
    short			int_sp[MAXSIZE]; /*  integer input array		*/
    float			temp;

	char			this_char[4];
	unsigned long	this_ulong;
	unsigned short	this_ushort;

	static int		first = 1;



    if (size > MAXSIZE) {
	printf("****ERROR: write block size too large **** \n");
	exit(1);
    }

    
    for (i = 0; i < size; i++ ) {
		temp = output[i];
		/* clamp to +- SIGMAX */
		if (temp > SIGMAX)
			temp = SIGMAX;
		if (temp < -SIGMAX)
			temp = -SIGMAX;

		/*temp = temp/SIGMAX;*/
		int_sp[i] = temp;

    }

	if (first == 1)	{
		first = 0;
		strcpy(this_char, "RIFF");
		fwrite(this_char, sizeof(char), 4, fp_out);
		this_ulong = 36 + num_samps;	/* number of bytes in file */
		fwrite(&this_ulong, sizeof(long), 1, fp_out);

		strcpy(this_char, "WAVE");
		fwrite(this_char, sizeof(char), 4, fp_out);	
		
		strcpy(this_char, "fmt ");
		fwrite(this_char, sizeof(char), 4, fp_out);
		this_ulong = 16;	/* fmt size */
		fwrite(&this_ulong, sizeof(long), 1, fp_out);

		this_ushort = 1;						/* PCM */
		fwrite(&this_ushort, sizeof( short), 1, fp_out);
		this_ushort = 1;						/* # channels */
		fwrite(&this_ushort, sizeof( short), 1, fp_out);
		this_ulong = 8000;						/* samples / sec */
		fwrite(&this_ulong, sizeof( long), 1, fp_out);
		this_ulong = 1*2*8000;					/* average transfer rate */
		fwrite(&this_ulong, sizeof( long), 1, fp_out);
		this_ushort = 1*2;						/* block alignment */
		fwrite(&this_ushort, sizeof( short), 1, fp_out);
		this_ushort = 16;						/* # bits/sec */
		fwrite(&this_ushort, sizeof( short), 1, fp_out);

		strcpy(this_char, "data");
		fwrite(this_char, sizeof(char), 4, fp_out);
		this_ulong = num_samps;					/* number of bytes in data */
		fwrite(&this_ulong, sizeof(long), 1, fp_out);

	}
	

    fwrite(int_sp,sizeof(short),size,fp_out);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -