/******************************************************************* * * * lrf_audio.h - Audio Port Functions Header File * * * * * WRITTEN BY: Bill Kapralos * * DATE: Monday, June 16 1997 * * * * York University * * Department of Computer Science * * * * Part of the port initialization code (audioInit) was obtained * * from soundtool.c (SUN Microsystems). * * * *******************************************************************/ #include #include #include #include #include #include #include #include #include #include "audio_device.h" #include "lrf_functions.h" #include "audio_hdr.h" #ifndef LRF_AUDIO #define LRF_AUDIO #define AUDIO_PORT "/dev/audio" /* Audio control device name. */ #define FREQ_SAMPLING_RATE 22050 #define NUM_OF_SAMPLES 4000 /* Sampling Rate / readings per sec.*/ #define AUDIO_GAIN 40 /* Audio port volume setting. */ #define SAMPLE_PRECISION 16 /* Number of bits per sample. */ #define MAX_DISTANCE 15.0 /* Maximum distance reading. */ #define MIN_DISTANCE 0.5 /* Minimum distance reading */ #define DISTANCE_INCR 0.10 /* Distance reading accuracy.*/ #define NUM_OF_WAVES 150 /* Number of waves cos table.*/ /* The following 2 values are used two values are used in the cosine wave generation equation. */ #define FREQ_CONST 4200 #define ADJUSTMENT 0.15 static int audioFd = -1; /* Since there is a minimum dist. defined, determine how many indeces this represents. */ static int tableOffset = (int) (MIN_DISTANCE / DISTANCE_INCR); static int audioPortInitialized = 0; /* Table holding the constant values required to eliminate the effects of "The Curves of Equal Loudness" for several frequencies. This value allows all tones to be perceived equally loud. (as a 1000Hz tone). */ static double amplitudeTable[] = { 1, 2238.7, 398.1, 251.2, 199.5, 100.0, 89.1, 35.5, 28.2, 25.1, 3.5, 2.5, 1.8, 1.4, 1.3, 1.12, 1.0, 1.0, 1.0, 1.0, 0.63, 0.3, 0.3, 0.65, 1.0, 1.3, 1.6, 1.8, 1.8 }; /******************************************************/ /* Open and initialize audio port. */ int audioInit(char *); /* Close the audio port. */ int audioClose(); /* Send data to the audio port. */ int sendAudio(short *, int); /* Create and initialize a table containing cosine wave samples. */ void tableInit(short **, int); /* Generate a cosine wave with the frequency specified. */ short *makeWave(double, double, int); /* Generate the depth-discontinuity signal (a pulse). */ short *makeDepthSignal(int); /* Creates and returns a buffer representing noise when output.*/ short *createNoise(int, double); /* Look-up & return the amplitude value corresponding to 'frequency' arg. */ double findAmplitude(double frequency); #endif