summaryrefslogtreecommitdiffstats
path: root/Graphic_Equalizer_Original_Port/src/audio.hcc
blob: 91901e19f2976c68e158ace4318ef5f9d6e1dd40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*! @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 <stdlib.hch>

#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