Debian Codegraph @

rplayd/flange.c

raw symbols SCIP
1 /* $Id: flange.c,v 1.4 1999/03/10 07:58:03 boyns Exp $ */
2
3 /*
4 * Copyright (C) 1993-99 Mark R. Boyns <[email protected]>
5 *
6 * This file is part of rplay.
7 *
8 * rplay is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * rplay is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with rplay; see the file COPYING. If not, write to the
20 * Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24
25
26 #include "rplayd.h"
27
28 #ifdef TEST_FLANGE
29
30 typedef struct
31 {
32 float rate; /* rate of delay change (-1.0 - 1.0) */
33 float sweep; /* sweep range in milliseconds */
34 float delay; /* fixed additional delay in milliseconds */
35 float dry_mix; /* mix of unaffected signal (-1.0 - 1.0) */
36 float wet_mix; /* mix of affected signal (-1.0 - 1.0) */
37 float feedback; /* amount of recirculation (-1.0 - 1.0) */
38 float depth;
39 }
40 parameters;
41
42 parameters p =
43 {2.0, 20.0, 0.0, 0.5, 0.5, 0.0, 10};
44
45 #define SPMS 8
46 #define SPS 8000
47 #define BFSZ 1024
48
49 float Buf[BFSZ];
50
51 typedef union
52 {
53 unsigned char b[2];
54 unsigned short w;
55 }
56 bw;
57
58 typedef union
59 {
60 unsigned short w[2];
61 long l;
62 }
63 wl;
64
65 void
66 flange(char *native_buf, int nsamples, int nchannels)
67 {
68 short *sample = (short *) native_buf;
69 short *flanged = (short *) native_buf;
70 int size = nsamples * nchannels;
71 static int first = 1;
72
73 static int i, fp, ep1, ep2;
74 static int step, depth, delay, min_sweep, max_sweep;
75 static float inval, outval, ifac = 65536.0;
76 static wl sweep;
77
78 if (first)
79 {
80 first = 0;
81
82 step = (int) (p.rate * 65.536);
83 depth = (int) (p.depth * (float) SPMS);
84 delay = (int) (p.delay * (float) SPMS);
85 max_sweep = BFSZ - 2 - delay;
86 min_sweep = max_sweep - depth;
87 if (min_sweep < 0)
88 {
89 exit(1);
90 }
91
92 sweep.w[0] = (min_sweep + max_sweep) / 2;
93 sweep.w[1] = 0;
94 fp = ep1 = ep2 = 0;
95 }
96
97 #if 0
98 printf("step = %d, depth = %d, delay = %d\n", step, depth, delay);
99 printf("max_sweep = %d, min_sweep = %d\n", max_sweep, min_sweep);
100 #endif
101
102 for (i = 0; i < size; i++)
103 {
104 outval = (Buf[ep1] * sweep.w[1] + Buf[ep2] * (ifac - sweep.w[1])) / ifac;
105 Buf[fp] = (inval = (float) sample[i]) + outval * p.feedback;
106 outval = outval * p.wet_mix + inval * p.dry_mix;
107 if (outval > 32000)
108 flanged[i] = 32000;
109 else if (outval < -32000)
110 flanged[i] = -32000;
111 else
112 flanged[i] = (int) outval;
113
114 fp = (fp + 1) & (BFSZ - 1);
115 sweep.l += step;
116 ep1 = (fp + sweep.w[0]) & (BFSZ - 1);
117 ep2 = (ep1 - 1) & (BFSZ - 1);
118 if (sweep.w[0] > max_sweep)
119 step = -step;
120 else if (sweep.w[0] < min_sweep)
121 step = -step;
122 }
123 }
124
125 #endif /* TEST_FLANGE */