3DOverb.c 1.62 KB
/***************************************************************
 *
 *	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;	
		
}