📄 sine.c
字号:
#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){ int cnt = 0; int i; int sr = 44100; float freq = 300; int per = sr / freq; int frames = 256; int amp = 30000; short * buffer = (short *)malloc(frames * 4); int fc; float currs = 0.0; float currc = 1.0; float sv; float cv; float nexts; float nextc; float w; float dt; dt = 1.0f / 44100.0f; w = 2 * 3.14159 * freq; sv = sin(w*dt); cv = cos(w*dt); while(1) { for (i = 0; i < (frames*2); i+=2) { w = 2 * 3.14159 * freq; sv = sin(w*dt); cv = cos(w*dt); nexts = currs * cv + currc * sv; nextc = currc * cv - currs * sv; currs = nexts; currc = nextc; buffer[i] = amp * currs; buffer[i+1] = buffer[i]; } fc = fwrite(buffer, sizeof(short),(frames*2),stdout); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -