previous next Up Title Contents

Hard Programming: AudPer86.c

/*******
 *
 * AudPer86.c
 *
 * This is a simple test program, running an auditory periphery model.
 * It has been written using hard programming.
 *
 * Unless otherwise stated all code was written by L. P. O'Mard.
 *
 *	E-mail: L.P.OMard@uk.ac.lut
 *
 * COPYRIGHT (c)
 *
 *	Speech and Hearing Laboratory,
 *	Department of Human Sciences,
 *	Loughborough University of Technology,
 *	Loughborough,
 *	Leicestershire LE11 3TU.
 *	United Kingdom.
 *
 *	1st March 1994.
 *
 *	DISCLAIMER OF WARRANTY
 *
 * Although every effort has been made to ensure the integrity of this
code,
 * the author, Loughborough University and its Laboratories disclaim
all
 * liability for direct or consequential damages resulting from its
use.
 *
 ********/

#include <stdlib.h> 
#include <stdio.h>
#include <math.h>
#include <time.h>

#include "CRLHeaders.h"

/******************************************************************************/

/****************************** Constant definitions
**************************/ 
/******************************************************************************/


#define	PARAMETERS_FILE		"AudPer86.par"	/* Name of paramters file.*/
#define	NUM_CHANNELS		1			/* No. of channels for the filter. */
#define CHANNEL				0			/* Channel no. for test. */

/******************************************************************************/

/****************************** Global variables
******************************/ 
/******************************************************************************/

char	outputFile[MAXLINE], stParFile[MAXLINE], pEParFile[MAXLINE];
char	bMParFile[MAXLINE], hCParFile[MAXLINE];

double	rampInterval;

/******************************************************************************/

/****************************** Functions and subroutines
*********************/ 
/******************************************************************************/

/****************************** ReadParsFromFile
******************************/

/*
 * This program reads a specified number of parameters from a file.
 * It expects there to be one parameter per line.
 */
 
void
ReadParsFromFile(char *fileName)
{
	char	line[MAXLINE];
	FILE	*fp;
	
	if ((fp = fopen(fileName, "r")) == NULL) {
		NotifyError("ReadTestPars: Cannot open data file '%s'.\n", fileName);
		exit(1);
	}
	printf("Reading parameters from file: %s\n", fileName);
	Init_ParFile();
	GetPars_ParFile(fp, "%s", outputFile);
	GetPars_ParFile(fp, "%s", stParFile);
	GetPars_ParFile(fp, "%s", pEParFile);
	GetPars_ParFile(fp, "%s", bMParFile);
	GetPars_ParFile(fp, "%s", hCParFile);
	GetPars_ParFile(fp, "%lf", &rampInterval);
	fclose(fp);
	Free_ParFile();
	
}

/******************************************************************************/

/****************************** Main Body
*************************************/ 
/******************************************************************************/


int main()
{
	double	intensity[NUM_CHANNELS];
	EarObjectPtr	stimulus = NULL, pEFilter = NULL, bMFilter = NULL;
	EarObjectPtr	hairCell = NULL;
	
	printf("Starting Test Harness...\n");
	
	ReadParsFromFile(PARAMETERS_FILE);
	printf("\nIn this test a pure tone stimulus is presented to an\n");
	printf("auditory periphery model.\n");
	printf("A rise time of %g ms is applied to the stimulus.\n",
	  MSEC(rampInterval));
	printf("\n");
	
	/* Initialise EarObjects. */
	
	stimulus = Init_EarObject( "null" );
	pEFilter = Init_EarObject( "null" );
	bMFilter = Init_EarObject( "null" );
	hairCell = Init_EarObject( "null" );

	/* Set up EarObject connections. */
	
	ConnectOutSignalToIn_EarObject( stimulus, pEFilter );
	ConnectOutSignalToIn_EarObject( pEFilter, bMFilter );
	ConnectOutSignalToIn_EarObject( bMFilter, hairCell );

	/* Initialise modules. */

	printf("Module parameters...\n\n" );

	ReadPars_PureTone( stParFile );
	PrintPars_PureTone();

	ReadPars_PreEmphasis_BandPass( pEParFile );
	PrintPars_PreEmphasis_BandPass();

	ReadPars_BasilarM_GammaT( bMParFile );
	PrintPars_BasilarM_GammaT();

	ReadPars_IHC_Meddis86( hCParFile );
	PrintPars_IHC_Meddis86();
	
	/* Start main process and print diagonstics. */
	
	printf("\nStarting main process...\n\n" );
	GenerateSignal_PureTone( stimulus );
	PrintProcessName_EarObject( "1-stimulus: '%s'.\n", stimulus );
	RampUpOutSignal_Ramp( stimulus, Sine_Ramp, rampInterval );
	CalcIntensities_GenAnalysis(intensity, stimulus->outSignal,
rampInterval );
	printf("\tStimulus intensity = %g dB SPL.\n", intensity[CHANNEL] );
	RunModel_PreEmphasis_BandPass( pEFilter );
	PrintProcessName_EarObject("2-Outer-/middle-ear: '%s'.\n", pEFilter );
	RunModel_BasilarM_GammaT( bMFilter );
	PrintProcessName_EarObject("3-Basilar membrane: '%s'.\n", bMFilter );
	RunModel_IHC_Meddis86( hairCell );
	PrintProcessName_EarObject("4-Inner hair cell (IHC): '%s'.\n", hairCell
);
	WriteOutSignal_DataFile(outputFile, hairCell );

	FreeAll_EarObject();

	printf("Finished test.\n");
	exit(0);
	
}



previous next Up Title Contents