-
Notifications
You must be signed in to change notification settings - Fork 3
/
clip.c
45 lines (37 loc) · 782 Bytes
/
clip.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 <string.h>
#include <math.h>
#include "synth.h"
/* clip.c: clip a waveform */
static void clip(float max, float min);
int main(int argc, char *argv[])
{
float max = 1.0f;
int i;
for (i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "-amp") && i+1 < argc)
max = atof(argv[++i]);
else if (!strcmp(argv[i], "-dB") && i+1 < argc)
max = pow(10.0, atof(argv[++i]) / 20.0);
else if (!strcmp(argv[i], "-help"))
{
fprintf(stderr, "options: -amp amplitude, -dB dB\n");
exit(0);
}
}
SET_BINARY_MODE
clip(max, -max);
return 0;
}
static void clip(float max, float min)
{
float f;
while (fread(&f, sizeof f, 1, stdin) == 1)
{
f = CLAMP(min, f, max);
if (fwrite(&f, sizeof f, 1, stdout) < 1)
return;
}
}