wav_generator.cpp
来自「正弦波形生成器」· C++ 代码 · 共 45 行
CPP
45 行
// 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;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?