SNESverb.c
1.6 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
/***************************************************************
*
* SNESverb.c
* a test of the SNES "reverb" for comparison
*
* 1/2/95 bfs initial version
*
*/
#include <stdlib.h>
#include "SNESverb.h"
#include "delay.h"
#include "lowpass.h"
#include "output.h"
struct dl_info dl[NUM_OF_DELAY_SECTS];
struct lp_info lp[NUM_OF_LP_SECTS];
void
init_proc_blocks(void)
{
int i;
for (i=0; i<NUM_OF_DELAY_SECTS; i++){
dl[i].length = SNES_REVERB_PARMS[i].length;
dl[i].coef = SNES_REVERB_PARMS[i].coef;
lp[i].coef = SNES_REVERB_PARMS[i].lpcoef;
/* 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, stemp;
int i, count=0;
long temp;
init_proc_blocks();
while(!feof(in_file)){
fread(&inL, sizeof(short), 1, in_file);
if (stereo) fread(&inR, sizeof(short), 1, in_file);
dl[0].in_data = inL + (low_pass_filter(&lp[0]) * dl[0].coef);
lp[0].in_data = delay(&dl[0]);
temp = (*wet * lp[0].in_data) + (*dry * inL);
wrout(temp, out_file);
if (stereo) {
dl[1].in_data = inR + (low_pass_filter(&lp[1]) * dl[1].coef);
lp[1].in_data = delay(&dl[1]);
temp = (*wet * lp[1].in_data) + (*dry * inR);
wrout(temp, out_file);
}
count++;
}
/* de-allocate storage for each all-pass delay line */
for (i=0; i<NUM_OF_DELAY_SECTS; i++){
free(dl[i].base);
}
return count;
}