| 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 |
#include "rplayd.h" |
| 27 |
|
| 28 |
#ifdef TEST_FLANGE |
| 29 |
|
| 30 |
typedef struct |
| 31 |
{ |
| 32 |
float rate; |
| 33 |
float sweep; |
| 34 |
float delay; |
| 35 |
float dry_mix; |
| 36 |
float wet_mix; |
| 37 |
float feedback; |
| 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 |