-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
142 lines (109 loc) · 2.64 KB
/
Copy pathtest.c
File metadata and controls
142 lines (109 loc) · 2.64 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "cnatural.h"
#include "wav.h"
#include "stdio.h"
#include <stdlib.h>
#include <math.h>
void tone(
double* data,
double start,
double duration,
double freq,
double amp)
{
waveform(
data, start, duration,
constant, NULL, freq,
constant, NULL, amp,
rampwave);
}
void kick(
double* data,
double start,
double duration,
double freq,
double amp)
{
point uppity[] =
{
{0.0, 0.0},
{0.01, 1.0},
{1.0, 0.0}
};
point ramp_pts[] =
{
{0.0, 0.0},
{1.0, -80.0}
};
piecewise_desc amp_desc = {sizeof(uppity) / sizeof(point), uppity, lerp, identity};
piecewise_desc my_ramp = {sizeof(ramp_pts) / sizeof(point), ramp_pts, lerp, factor};
waveform(
data, start, duration,
piecewise, &my_ramp, freq,
piecewise, &_desc, amp,
squarewave);
}
void snare(
double* data,
double start,
double duration,
double freq,
double amp)
{
point myp[] = {
{0.0, 1.0},
{0.25, 0.2},
{1.0, 0.0}};
piecewise_desc mypieces = {sizeof(myp)/sizeof(point), myp, smoothstep, identity};
waveform(
data, start, duration,
constant, NULL, freq,
piecewise, &mypieces, amp,
noise);
}
int main()
{
point myp[] = {{0.0, 2.0}, {0.25, 4.0}, {1.0, 3.0}};
piecewise_desc myramp = {sizeof(myp)/sizeof(point), myp, lerp, identity};
int n = 44100 * 200;
int numSamples = n;
double* data = (double*)malloc(n * sizeof(double));
short* pritedData = (short*)malloc(n * sizeof(short));
int c = 1;
int e[] = {0, 2, 4, 7, 9, 12, 14, 16, 19, 21};
int index = 0;
int i = 0;
int j = 0;
int p = 0;
for( j = 0; j < 20; j++ )
{
for( i = 0; i < 4; i++ )
{
int newindex = index;
while(newindex == index)
newindex = ((rand() & 0xffff) % (sizeof(e)/sizeof(int)));
index = newindex;
double m = factor(e[index]);
tone(data, 0.25*(p++), 0.25, 220.0 * m, 0.5);
}
p += 4;
}
p = 0;
for( j = 0; j < 80; j++ )
{
if (j%2 == 1)
snare(data, p*0.25, 0.25, 220.0, 0.1);
p++;
if (j%2 == 0)
kick(data, p*0.25, 0.25, 220.0, 0.25);
p++;
}
echo(data, 0, 100, 1.0, 0.2);
FILE* f = fopen("out.wav", "w");
WavHeader wh = makeWavHeader(n, 1, 44100, 2);
fwrite(&wh, sizeof(WavHeader), 1, f);
double* tracks[] = {data};
print(pritedData, tracks, 1, numSamples);
fwrite(pritedData, n*2, 1, f);
fclose(f);
return 0;
}