TAPDAPverb.c 1.7 KB
/***************************************************************
 *
 *	TAPDAPverb.c
 *		a simple single tapped all-pass chain
 *
 *	1/14/95		bfs initial version
 *
 */

#include <stdlib.h>
#include "TAPDAPverb.h"
#include "allpass.h"
#include "output.h"

struct ap_info ap[NUM_OF_AP_SECTS]; 

void
init_all_passes(void)
{
	int i;
	
	for (i=0; i<NUM_OF_AP_SECTS; i++){
		ap[i].length = TAPDAP_REVERB_PARMS[i].length;
		ap[i].coef = TAPDAP_REVERB_PARMS[i].coef;
		
		/* allocate storage for delay line */
		if(( ap[i].base = (float *)calloc(sizeof(float),ap[i].length)) == NULL ){
			fprintf(stderr,"Can't allocate delay line memory!\n");
			exit(1);
		}
		
		ap[i].out_ptr = ap[i].base + 1;
	}		
}		

int do_reverb(FILE *in_file, FILE *out_file, float *wet, float *dry, int stereo)
{
	short	inL, inR;
	int	i, count=0;
	float	trim=0.7;
	long 	temp;

	init_all_passes();
		
	while(!feof(in_file)){
	    fread(&inL, sizeof(short), 1, in_file);
	    if (stereo) fread(&inR, sizeof(short), 1, in_file);
	    
	    ap[0].in_data = (inL * trim) + (inR * trim);	/* sum left and right into first ap */
	    ap[1].in_data = all_pass_filter(&ap[0]);
	    ap[2].in_data = all_pass_filter(&ap[1]);
	    ap[3].in_data = all_pass_filter(&ap[2]);
	    ap[4].in_data = all_pass_filter(&ap[3]);
	    ap[5].in_data = all_pass_filter(&ap[4]);

	    temp = 0;
	    for (i=1; i<NUM_OF_AP_SECTS; i++)
		temp += ap[i].in_data;
	    temp += all_pass_filter(&ap[5]);
	    wrout(temp*(*wet) + inL*(*dry), out_file);

	    if (stereo) {
		wrout(temp*(*wet) + inR*(*dry), out_file);
		wrout(temp, out_file);
	    }

	    count++;
	}

	/* de-allocate storage for each all-pass delay line */
	for (i=0; i<NUM_OF_AP_SECTS; i++){
		free(ap[i].base);
	}	
	return count;	
		
}