/*! @file audio.hcc * * @section generic Audio init and main loop * * @section project Project information. * Project Graphic Equalizer\n * @author O.M. Schinagl * @date 20041011 * @version 0.1 * * @section copyright Copyright * Copyright ©2004 Koninklijke Philips Electronics N.V. All rights reserved * * @section history Change history * 20041011: \n Initial version * ********************************************************************/ /******** System Includes *************/ #include #include "pal_master.hch" /******** Application Includes ********/ #include "configuration.hch" #include "audio.hch" /*! \fn macro proc audio_init(gain_level, input_source, sample_rate, AUDIOIN, AUDIOOUT) * * \brief Set some inital values to the audio hardware. * * \param gain_level Set the input amplifier to this amplification * level. * \param input_source Choose between microphone input or linein * input. * \param sample_rate Set the sample rate between 8000 * and 48000 * * \return void * \retval void * */ macro proc audio_init(gain_level, input_source, sample_rate, AUDIOIN, AUDIOOUT) { /* * We simply call the appropiate handlers and pass values along. We * Don't set the mute on input gain. We have volume control to do this. * Input and Output sampling rates are equal. We dont' need different * rates. */ RC200AudioInSetGain(FALSE, gain_level, gain_level); RC200AudioInSetInput(input_source); PalAudioInSetSampleRate(AUDIOIN, sample_rate); PalAudioOutSetSampleRate(AUDIOOUT, sample_rate); } /* --- audio_init() --- */ #if !USE_RUNFFT //TODO: put runfft here! /*! @fn macro proc audio_main(audiodata, AUDIOIN, AUDIOOUT); * * @brief Main audiodriver. This function never returns! It calls the * audiohandlers and stores samples into a global array. Once 64 * Samples are collected it raises a signal AUDIO_READY to let * other processes know it's ready. We use quadruple buffering for * audio input and double buffering for audio output. * * @param *audiodata pointer to audio information structure. * @param AUDIOIN Audio Input Handler * @param AUDIOOUT Audio Output Handler * * @return Never Returns. * @retval void */ macro proc audio_main(audiodata, AUDIOIN, AUDIOOUT) { /* * Determin the data width for the current platform. */ macro expr IW = PalAudioInGetMaxDataWidthCT(); macro expr OW = PalAudioOutGetMaxDataWidthCT(); signed IW sample_left_in, sample_right_in; signed OW sample_left_out, sample_right_out; while (TRUE) { PalAudioInRead(AUDIOIN, &sample_left_in, &sample_right_in); /* par { sample_add(sample_left_in); sample_get(&sample_left_out); sample_right_out = sample_right_in; } if (rotate_samples()) { / * * 64 Samples have been processed, calculate. * / } */ PalAudioOutWrite(AUDIOOUT, (signed OW)(sample_left_in @ 0), (signed OW)(sample_right_in @ 0)); } } /* --- audio_main() --- */ #endif