blob: 000baf9e68aceeb3511b5a6861c82fa0ee0322df (
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
103
104
105
106
|
/*! \file sample.hcc
*
* \section generic Handle audio sampling and buffer rotation.
*
* \section project Project information.
* Project Graphic Equalizer\n
* \author O.M. Schinagl
* \date 20041021
* \version 0.1
*
* \section copyright Copyright
* Copyright ©2004 Koninklijke Philips Electronics N.V. All rights reserved
*
* \section history Change history
* 20041021: O.M. Schinagl\n Initial version
*
********************************************************************/
/******** System Includes *************/
/******** Application Includes ********/
#include "sample.hch"
/*
* Pointer that points towards the current 64 bits samples.
*/
signed 16 *audio_in_ptr;
/*
* 64 step counter to keep track of our samples. This is a private variable.
*/
unsigned 8 sample_count;
/*! \fn void sample_add(signed 16 in_sample);
* \brief This procedure adds the supplied sample to the input buffer.
*
* \param signed 16 in_sample 16 bits signed sample to be added.
*
* \return void
* \retval void
*/
void sample_add(signed 16 in_sample) {
/*
* We only sample 64 bits in our buffer, hence we circulate around the
* last 6 bits.
*/
audio_in_ptr[sample_count <-6] = in_sample;
sample_count++;
} /* --- sample_add() --- */
/*! \fn void sample_get(signed 16 *out_sample);
* \brief This procedure gets the sample from the current output buffer.
*
* \param * in_sample pointer to storage for sample.
*
* \return void
* \retval void
*/
void sample_get(signed 16 *out_sample) {
/*
* We circulate around a 64 bits buffer, therefor we only use the last
* 6 bits.
*/
*out_sample = audio_out_ptr[sample_count <-6];
} /* --- sample_get() --- */
/*! \fn unsigned 1 sample_rotate_buffers(void);
* \brief This procedure rotates our buffers around if 64 samples are
* read into our current buffer.
*
* \param in_sample 16 bits signed sample to be added.
*
* \return 1 when 64 samples have passed, 0 otherwise.
* \retval unsigned 1;
*/
unsigned 1 sample_rotate_buffers(void) {
unsigned 1 retval; /* store for returnvalue */
retval = 0;
/*
* We only want to read 64 samples, but calculations work nicer if we
* use 256 samples. Therefor we circulate our audio pointer around.
*/
if (!(sample_count <- 6)) {
/*
* 64 Samples have passed. We are back at '0'. Use the full
* sample count as index which is 0 64 128 or 192 and back to
* 0. Our Output is only 128 big so we only look at the
* 7 LSB. Also, notify the main application that 64 samples
* have been processed.
*/
par {
audio_in_ptr = &pcm_audio_in[sample_count];
audio_out_ptr = &pcm_audio_out[(sample_count <- 7)];
retval = 1;
}
}
} /* --- sample_rotate_buffers() --- */
|