Initial commit
This commit is contained in:
25
gen.c
Normal file
25
gen.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define SAMPLE_RATE 44100
|
||||
#define DURATION 5
|
||||
#define FREQUENCY 440
|
||||
#define VOLUME 0.3f
|
||||
|
||||
int main() {
|
||||
for (size_t i = 0; i < DURATION * SAMPLE_RATE; ++i) {
|
||||
float t = (float)i / SAMPLE_RATE;
|
||||
float volume = (float)INT16_MAX * VOLUME;
|
||||
int16_t sample = 0;
|
||||
|
||||
sample = (int16_t)
|
||||
(
|
||||
(sinf(2*M_PI * FREQUENCY * t) * volume) +
|
||||
(sinf(2*M_PI * 2*FREQUENCY * t) * volume)
|
||||
);
|
||||
fwrite(&sample, sizeof(sample), 1, stdout);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user