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
103
104
105
106
|
/*! \file header_templace.hcc
*
* \section generic Message build up information and more
*
* \section project Project information.
* Project Graphic Equalizer\n
* \author
* \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 "audiodriver.hch"
#include "audiodriver_shared.hch"
/*! \fn void audio_init(unsigned 4 gain_level,
* unsigned 1 input_source,
* unsigned 3 sample_rate)
*
* \brief Set some inital values to the audio hardware.
*
* \param unsigned 4 gain_level Set the input amplifier to this
* amplification level.
* \param unsigned 1 input_source Choose between microphone input
* or linein input
* \param unsigned 3 sample_rate Set the sample rate between 8000
* and 48000
*
* \return void
* \retval void
*
*/
void audio_init(unsigned 4 gain_level,
unsigned 1 input_source,
unsigned 3 sample_rate) {
/*
* 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() --- */
/*! \fn void audio_main(void);
* \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 void
*
* \return Never Returns.
* \retval void
*/
void audio_main(void) {
/*
* Setup audio pointers.
*/
macro expr AudioIn = PalAudioInCT(0);
macro expr AudioOut = PalAudioOutCT(0);
/*
* 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 16 sample_left_out, sample_right_out;
for (;;) {
PalAudioRead(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.
*/
}
PalAudioWrite(AudioOut, (signed OW)(sample_left @ 0), (signed OW)(sample_right @ 0));
}
} /* --- audio_main() --- */
|