-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
45 lines (38 loc) · 1.43 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "waver.h"
void sin_gen(long freq, long duration, int data[duration],int samplerate){
float frate= (freq*2*M_PI)/samplerate; // Frame rate -
float frame=0; // which frame you're looking at
float amplitude = 82000; // Amplitude
for (int i=0; i<duration; i++){
frame += frate; // change the frame
data[i] = amplitude * sin(frame); // data now contains the amplitude * sin of the frame.
}
}
int main(int argc, char *argv[]){
if (argc == 2){
char *flag;
flag = "--help";
int strcompare_res = strcmp(flag, argv[1]);
if (strcompare_res == 0){
system("open README.html");
}
}else{
char *file_name = "wave.wav"; // file name
unsigned int samplerate = SRATE; // Sample rate
unsigned int channels = 1; // mono
unsigned long nosamples = samplerate * 2; // two seconds of sound
unsigned int bits_per_sample = 24; // 24 bit resolution
int data[nosamples]; // data
long freq = 440.0; // frequency
wave_head_data wavedat = {file_name, samplerate, channels, nosamples, bits_per_sample}; // Wave data
printf("If you want to learn more, execute ./%s --help\n",argv[0]);
sin_gen(freq,nosamples,data,samplerate); // sin generation
waver(wavedat,data); // call waver
system("afplay wave.wav"); // run it, yo
}
return 0; // exit
}