www.pudn.com > wave_generator_VC.rar > wav_generator.cpp


// wav_generator.cpp : Defines the entry point for the console application. 
// 
 
#include "stdafx.h" 
#include "stdio.h" 
#include "math.h" 
 
#define total_len (1*60*44100) 
short buf[total_len]; 
const double pi = 3.1415926535897932384626433832795; 
 
 
int main(int argc, char* argv[]) 
{ 
	int i, n; 
	double j; 
	FILE *file; 
 
	j = 0; 
	for(i=0; i<(total_len); i++) { 
		int tmp; 
		double f; 
 
		f = sin(j)*12000.0; 
		buf[i] = (short)f; 
 
		f = i; 
		f /= (total_len/10.0); 
		f = pow(2.0, f); 
		f *= 20.0;  // f is now current frequence 
		f *= pi * 2; 
		f /= (44100.0); 
		j += f; 
		if ( j>(pi*2) ) 
			j -= (pi*2); 
	} 
 
	file = fopen("c:\\test.wav", "wb"); 
	fwrite(buf, 2, total_len, file); 
	fclose(file); 
 
	return 0; 
}