-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwhite.c
54 lines (45 loc) · 981 Bytes
/
white.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "synth.h"
#define MT_IMPLEMENT
#include "lib/mt.h"
#include "rate.inc"
/* white: generate white noise */
int main(int argc, char *argv[])
{
float amp = 0.5f, range;
long len;
long n;
int i;
get_rate();
len = RATE;
/* read options */
for (i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "-amp") && i+1 < argc)
amp = atof(argv[++i]); /* amplitude from 0 to 1 */
else if (!strcmp(argv[i], "-len") && i+1 < argc)
len = atof(argv[++i]) / 1000.0f * RATE; /* len in ms */
else if (!strcmp(argv[i], "-help"))
{
fprintf(stderr, "options: -amp arg, -len arg\n");
exit(0);
}
}
/* check options */
amp = CLAMP(0.0f, amp, 1.0f);
/* convert options */
range = amp * 2;
mt_init((unsigned int)time(NULL));
SET_BINARY_MODE
for (n = 0; n < len*2; n++)
{
float f;
f = mt_frand() * range - amp;
if (fwrite(&f, sizeof f, 1, stdout) < 1)
break;
}
return 0;
}