summaryrefslogtreecommitdiffstats
path: root/Graphic_Equalizer/src/events.hcc
blob: 275bc25b61a1df6bae2aaaf448c4b4f83d71d7ab (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*! \file events.hcc
 *
 * \section generic	This module contains the various actions and events
 *			that need to be performed.
 *
 * \section project Project information.
 * Project Graphic Equalizer\n
 * \author O.M. Schinagl
 * \date 20041710
 * \version 0.1
 *
 * \section copyright Copyright
 * Copyright ©2004 Koninklijke Philips Electronics N.V. All rights reserved
 *
 * \section history Change history
 * 20041710: O.M. Schinagl\n	Initial version
 *
 *****************************************************************************/



/******** System Includes *************/
#include <stdlib.hch>

#include "pal_master.hch"

/******** Application Includes ********/
#include "configuration.hch"
#include "display_shared.hch"
#include "eventhandler_shared.hch"
#include "events.hch"

#if HAVE_DEBUG
	#include "debug.hch"
#endif


ram unsigned 8 presets_default_values[768] = {
#include "presets_hardcoded.txt"
};



/*! \fn		void set_preset(unsigned 10 *active_preset,
 *			unsigned 10 *preset_offset, unsigned 8 new_preset,
 *			unsigned 4 *equalizer_levels_ptr,
 *			unsigned 4 *equalizer_levels)
 * \brief	This function changes the active preset to the new_preset
 *		received from the userinterface and updates internal pointers.
 *
 * \param	*active_preset		Local store that holds the current
 *					active preset.
 * \param	*preset_offset		Local store that holds the index to the
 *					current active preset in the presets
 *					array.
 * \param	new_preset		The new preset.
 * \param	*equalizer_levels_ptr	Pointer pointing to the current
 *					equalizer settings.
 * \param	*equalizer_levels	Local store with all presets.
 */
inline void set_preset(unsigned 10 *active_preset, unsigned 10 *preset_offset, unsigned 8 new_preset, unsigned 4 *equalizer_levels_ptr, unsigned 4 *equalizer_levels) {
	/*
	 * The active preset is determined by the mask minus an offset. Hence
	 * ranging our active preset from 0 to 6.
	 */
	*active_preset = 0 @ new_preset;
	/*
	 * Each equalizer is 128 bands wide, thus we need to add 128 the preset
	 * for each different preset. This offset is calculated here.
	 */
	*preset_offset = *active_preset << 7;
	/*
	 * We set the pointer to the active part of the array by using the
	 * preset offset as our index. Hence depending on the selected preset
	 * we point to 0, 128, 256, 384, 512 or 640.
	 */
	equalizer_levels_ptr = &equalizer_levels[*preset_offset];
}



/*
 */
inline unsigned 5 change_volume_from_coordinate(unsigned 11 coordinate, events_t *events, skindata_t *skindata) {
	unsigned 5 retval;
	unsigned 5 volumeleft;

	/*
	 * Copy the current Y cursor position to the events struct. This we
	 * need for drawing purposes.
	 */
	events->volume_position = coordinate;
	/*
	 * Look the relative y-coordinate up in the volumecontrol lookup table.
	 * We make a local copy here because the RC200 call doesn't behave
	 * nicely when passing anything else.
	 */
	volumeleft = volumecontrol_table[(coordinate -skindata->volume.top) <- 6];
	/*
	 * We feel that volume gets softer the closer it gets to the 0, and
	 * louder as it approaches 0x1f. The SetVolume RC200 call does this in
	 * an unnatural reverse way. Therefor we 'fix' it.
	 */
	RC200AudioOutSetVolume(!volumeleft, (0x1f -volumeleft), (0x1f -volumeleft));
	/*
	 * Now that we have set the gain, we return it incase someone needs it.
	 */
	retval = volumeleft;

	return retval;
}



/*
 */
inline unsigned 4 change_inputgain_from_coordinate(unsigned 11 coordinate, events_t *events, skindata_t *skindata) {
	unsigned 4 retval;
	unsigned 4 gainleft;

	/*
	 * Copy the current Y cursor position to the events struct. This we
	 * then later use for drawing purposes.
	 */
	events->inputgain_position = coordinate;
	/*
	 * Look the relative y-coordinate up in the inputgain lookup table. We
	 * make a local copy here because the RC200 call doesn't behave nicely
	 * when passing anything else.
	 */
	gainleft = inputgain_table[(coordinate -skindata->inputgain.top) <- 6];
	/*
	 * Finally we set the gain as calculated.
	 */
	RC200AudioInSetGain(!gainleft, gainleft, gainleft);
	/*
	 * Now that we have set the gain, we return it incase someone needs it.
	 */
	retval = gainleft;

	return retval;
}



/*! \fn		void load_preset(unsigned 10 preset, unsigned 4 *equalizer_levels_ptr);
 * \brief	This function loads 768 4bits presets into the equalizer_levels
 *		array pointed to by equalizer_levels.
 *
 * \param	*equalizer_levels	Location where to store presets loaded
 *					from blockram.
 *
 * \return	void
 * \retval	void
 */
void load_preset(unsigned 10 preset, unsigned 4 *equalizer_levels_ptr) {
	unsigned 10 equalizer_index;
	unsigned 4 temp;

	equalizer_index = 0;
	while (equalizer_index != 768) {
		temp = presets_default_values[preset +(0 @ (equalizer_index \\ 1))][7:4];
		equalizer_levels_ptr[equalizer_index] = temp;
		temp = presets_default_values[preset +(0 @ (equalizer_index \\ 1))][3:0];
		equalizer_levels_ptr[equalizer_index +1] = temp;

		equalizer_index += 2;
	}
} /* --- load_preset() --- */



/*
 * Equalizer lookuptabes.
 * TODO: This table is now hardcoded. To ensure full skinability this table
 * should be dynamically loaded.
 */
ram unsigned 4 equalizer_table[640] = {15, 15, 15, 15, 15, 14, 14, 14, 14, 13, 13, 13, 13, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0};
ram unsigned 11 equalizer_table_inv[16] = {446, 444, 440, 436, 432, 428, 424, 420, 416, 412, 408, 404, 400, 396, 392, 384};