-
Notifications
You must be signed in to change notification settings - Fork 3
/
pan.c
60 lines (48 loc) · 1.01 KB
/
pan.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "synth.h"
/* pan.c: adjust a waveform's horizontal panning */
static void pan(float angle);
int main(int argc, char *argv[])
{
float angle = 0.0f;
int i;
/* read options */
for (i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "-angle") && i+1 < argc)
angle = atof(argv[++i]);
else if (!strcmp(argv[i], "-help"))
{
fprintf(stderr, "options: -angle arg (-180 to 180)\n");
exit(0);
}
}
/* check options */
angle = CLAMP(-180.0f, angle, 180.0f);
/* convert options */
angle = angle * M_PI / 180.0f;
SET_BINARY_MODE
pan(angle);
return 0;
}
static void pan(float angle)
{
float f;
float leftamp, rightamp;
int odd = 0;
leftamp = cos(angle) + sin(angle);
rightamp = cos(angle) - sin(angle);
while (fread(&f, sizeof f, 1, stdin) == 1)
{
odd = !odd;
if (odd) /* left speaker */
f *= leftamp;
else /* right speaker */
f *= rightamp;
if (fwrite(&f, sizeof f, 1, stdout) < 1)
return;
}
}