SNESverb.c 1.6 KB
/***************************************************************
 *
 *	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;	
		
}