3DOverb.c
1.62 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/***************************************************************
*
* 3DOverb.c
* a test of the 3DO spatialization
* "reverb" for comparison
*
* 1/2/95 bfs initial version
*
*/
#include <stdlib.h>
#include "3DOverb.h"
#include "delay.h"
#include "lowpass.h"
#include "output.h"
struct dl_info dl[NUM_OF_SECTS];
void
init_proc_blocks(void)
{
int i;
for (i=0; i<NUM_OF_SECTS; i++){
dl[i].length = _3DO_REVERB_PARMS[i].length;
dl[i].coef = _3DO_REVERB_PARMS[i].coef;
/* allocate storage for delay line */
if(( dl[i].base = (float *)calloc(sizeof(float), dl[i].length)) == NULL ){
fprintf(stderr,"Can't allocate delay line memory!\n");
exit(1);
}
dl[i].out_ptr = dl[i].base + 1;
}
}
int do_reverb(FILE *in_file, FILE *out_file, float *wet, float *dry, int stereo)
{
short inL, inR = 0, stemp;
int i, count=0;
long temp;
init_proc_blocks();
if (stereo) {
while(!feof(in_file)) {
fread(&inL, sizeof(short), 1, in_file);
fread(&inR, sizeof(short), 1, in_file);
dl[0].in_data = ((1.0-(*wet)) * inL) + *wet * delay(&dl[1]);
dl[1].in_data = ((1.0-(*wet)) * .95 * inR) + *wet * delay(&dl[0]);
wrout((int)dl[0].in_data, out_file);
wrout((int)dl[1].in_data, out_file);
}
}
else {
while(!feof(in_file)) {
fread(&inL, sizeof(short), 1, in_file);
dl[0].in_data = ((1.0-(*wet)) * inL) + *wet * delay(&dl[1]);
dl[1].in_data = ((1.0-(*wet)) * .95 * inR) + *wet * delay(&dl[0]);
wrout((int)dl[0].in_data, out_file);
}
count++;
}
/* de-allocate storage for each all-pass delay line */
for (i=0; i<NUM_OF_SECTS; i++){
free(dl[i].base);
}
return count;
}