-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicroScale.c
executable file
·65 lines (51 loc) · 1.73 KB
/
MicroScale.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* ------------------------------------------------MicroScale.c-------------------------------------------- */
/*Created by Vishal Menon (Laziemo) in association with Richard Dobson (The Audio Programming Book)
* Version 1.0: September 20, 2017
*
* A command-line tool to calculate micro-tone harmonics of a specified frequency.
* Designed for those kids that are bored of the chromatic scale.
*
*Input:
* - Root frequency (r_freq)
* - Octave Division (harmonics per octave)
*Output:
* - all N harmonics associated with the root frequency f_root.
*/
/* UPGRADES:
*Add functionality to hear each harmonic
*/
/* ------------------------------------------------MicroScale.c-------------------------------------------- */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(int argc, char** argv) {
double r_freq;
double ratio;
short interval;
short i;
double* harmonics;
//Check for errors in arguments
if(argc!=3) {
printf("Bad Arguments: MicroScale takes 3 arguments. \n MicroScale.c <root_frequency> <scale_interval> \n");
return 1;
}
//Store command-line arguments into local variables
r_freq = atof(argv[1]);
interval = atoi(argv [2]);
//Calculate interval ratio
ratio = pow(2.0 , 1.0/interval);
//Create space to hold harmonics data
harmonics = (double*) malloc (interval * sizeof(double));
printf("Root Frequency = %lf Hz", r_freq);
printf(" The harmonics of %lf Hz for a %i tone octave are : \n" ,r_freq, interval);
//Populate and print harmonics vector
for (i=0;i<=interval;i++) {
*(harmonics+i) = r_freq;
r_freq *= ratio;
printf("H-%i : %lf \n",i, *(harmonics+i));
}
//Clean up memory
harmonics=NULL;
free(harmonics);
return 0;
}