JAMverb.c 2.21 KB
/***************************************************************
 *
 *	JAMverb.c
 *	 	Andy Moorer's suggestion from
 *		_About This Reverberation Business_
 *
 *	1/3/95		bfs initial version
 *
 */

#include <stdlib.h>
#include "JAMverb.h"
#include "allpass.h"
#include "lpcomb.h"


struct ap_info ap[NUM_OF_AP_SECTS];
struct lpc_info lpc[NUM_OF_COMB_SECTS];

void
init_proc_blocks(void)
{
	int i,j;
	
	for (j=0; j<NUM_OF_COMB_SECTS; j++){
		lpc[j].length = JAM_REVERB_PARMS[j].length;
		lpc[j].coef = JAM_REVERB_PARMS[j].coef;
		lpc[j].lpcoef = JAM_REVERB_PARMS[j].lpcoef;
		lpc[j].lpzmem = 0;
		
		/* allocate storage for delay line */
		if(( lpc[j].base = (float *)calloc(sizeof(float), lpc[j].length)) == NULL ){
			fprintf(stderr,"Can't allocate delay line memory!\n");
			exit(1);
		}
		
		lpc[j].out_ptr = lpc[j].base + 1;
		lpc[j].out_data = lpc[0].in_data = 0.0;
	}		
	for (i=0; i<NUM_OF_AP_SECTS; i++){
		ap[i].length = JAM_REVERB_PARMS[i+j].length;
		ap[i].coef = JAM_REVERB_PARMS[i+j].coef;
		
		/* allocate storage for delay line */
		if(( ap[i].base = (float *)calloc(sizeof(float),ap[i].length)) == NULL ){
			fprintf(stderr,"Can't allocate ap delay line memory!\n");
			exit(1);
		}
		ap[i].out_ptr = ap[i].base + 1;
		ap[i].out_data = ap[0].in_data = 0.0;
	}		
}		

int do_reverb(FILE *in_file, FILE *out_file, float *wet, float *dry, int stereo)
{
	short	in;
	int	i, count=0;
	float	inLeft, inRight, trim=1.0;
	long 	temp;

	init_proc_blocks();
		
	while(!feof(in_file)){
	    fread(&in, sizeof(short), 1, in_file);
	    in = (float)in;
	    lpc[0].in_data = in * trim;
	    lpc[1].in_data = in * trim;
	    lpc[2].in_data = in * trim;
	    lpc[3].in_data = in * trim;
	    lpc[4].in_data = in * trim;
	    lpc[5].in_data = in * trim;
	    ap[0].in_data = lpcomb(&lpc[0]) + lpcomb(&lpc[1]) + lpcomb(&lpc[2])
	                  + lpcomb(&lpc[3]) + lpcomb(&lpc[4]) + lpcomb(&lpc[5]);
	    temp = (all_pass_filter(&ap[0])*(*wet) + in * (*dry));
	    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);
	}	
	/* de-allocate storage for each all-pass delay line */
	for (i=0; i<NUM_OF_COMB_SECTS; i++){
		free(lpc[i].base);
	}	
	return count;	
		
}