mirror of
https://github.com/jhbruhn/eurorack.git
synced 2025-03-15 02:55:49 +00:00
Improved gamma handling
This commit is contained in:
parent
77721bcd00
commit
d4335820ba
5 changed files with 80 additions and 79 deletions
|
@ -26,7 +26,8 @@ class Leds {
|
|||
}
|
||||
void Write()
|
||||
{
|
||||
pwm_counter += 2;
|
||||
pwm_counter++;
|
||||
pwm_counter &= 0x1ff; // equals to if(pwm_counter > 512) pwm_counter = 0;
|
||||
|
||||
for (size_t i = 0; i < kNumChannels; i++) {
|
||||
if (intensities[0] && lut_led_gamma[intensities[i]] >= pwm_counter) {
|
||||
|
@ -44,6 +45,6 @@ class Leds {
|
|||
}
|
||||
|
||||
private:
|
||||
uint8_t pwm_counter;
|
||||
uint16_t pwm_counter;
|
||||
uint8_t intensities[kNumChannels];
|
||||
};
|
||||
|
|
|
@ -3112,85 +3112,85 @@ const uint16_t lut_right_cos_pan[] = {
|
|||
176, 151, 126, 101,
|
||||
75, 50, 25, 0,
|
||||
};
|
||||
const uint16_t lut_led_gamma[] = {
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 1, 1,
|
||||
1, 1, 1, 1,
|
||||
1, 1, 1, 1,
|
||||
2, 2, 2, 2,
|
||||
2, 2, 2, 3,
|
||||
3, 3, 3, 4,
|
||||
4, 4, 4, 4,
|
||||
5, 5, 5, 6,
|
||||
6, 6, 7, 7,
|
||||
7, 8, 8, 8,
|
||||
9, 9, 10, 10,
|
||||
11, 11, 12, 12,
|
||||
13, 13, 14, 14,
|
||||
15, 15, 16, 17,
|
||||
17, 18, 19, 19,
|
||||
20, 21, 21, 22,
|
||||
23, 24, 24, 25,
|
||||
26, 27, 28, 29,
|
||||
29, 30, 31, 32,
|
||||
33, 34, 35, 36,
|
||||
37, 38, 39, 40,
|
||||
42, 43, 44, 45,
|
||||
46, 47, 49, 50,
|
||||
51, 52, 54, 55,
|
||||
56, 58, 59, 61,
|
||||
62, 63, 65, 66,
|
||||
68, 70, 71, 73,
|
||||
74, 76, 78, 79,
|
||||
81, 83, 84, 86,
|
||||
88, 90, 92, 94,
|
||||
96, 97, 99, 101,
|
||||
103, 105, 107, 110,
|
||||
112, 114, 116, 118,
|
||||
120, 122, 125, 127,
|
||||
129, 132, 134, 136,
|
||||
139, 141, 144, 146,
|
||||
149, 151, 154, 157,
|
||||
159, 162, 165, 167,
|
||||
170, 173, 176, 178,
|
||||
181, 184, 187, 190,
|
||||
193, 196, 199, 202,
|
||||
205, 208, 212, 215,
|
||||
218, 221, 225, 228,
|
||||
231, 235, 238, 242,
|
||||
245, 249, 252, 256,
|
||||
259, 263, 267, 270,
|
||||
274, 278, 282, 286,
|
||||
289, 293, 297, 301,
|
||||
305, 309, 313, 318,
|
||||
322, 326, 330, 334,
|
||||
339, 343, 347, 352,
|
||||
356, 361, 365, 370,
|
||||
374, 379, 384, 388,
|
||||
393, 398, 402, 407,
|
||||
412, 417, 422, 427,
|
||||
432, 437, 442, 447,
|
||||
453, 458, 463, 468,
|
||||
474, 479, 484, 490,
|
||||
495, 501, 506, 512,
|
||||
};
|
||||
|
||||
|
||||
const uint16_t* lookup_table_u16_table[] = {
|
||||
lut_linear_to_exp,
|
||||
lut_left_sin_pan,
|
||||
lut_right_cos_pan,
|
||||
};
|
||||
|
||||
const uint8_t lut_led_gamma[] = {
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 1, 1,
|
||||
1, 1, 1, 1,
|
||||
1, 1, 1, 2,
|
||||
2, 2, 2, 2,
|
||||
2, 3, 3, 3,
|
||||
3, 3, 4, 4,
|
||||
4, 4, 5, 5,
|
||||
5, 5, 6, 6,
|
||||
6, 7, 7, 7,
|
||||
8, 8, 8, 9,
|
||||
9, 9, 10, 10,
|
||||
11, 11, 11, 12,
|
||||
12, 13, 13, 14,
|
||||
14, 14, 15, 15,
|
||||
16, 16, 17, 17,
|
||||
18, 18, 19, 20,
|
||||
20, 21, 21, 22,
|
||||
22, 23, 24, 24,
|
||||
25, 25, 26, 27,
|
||||
27, 28, 29, 29,
|
||||
30, 31, 31, 32,
|
||||
33, 33, 34, 35,
|
||||
36, 36, 37, 38,
|
||||
39, 40, 40, 41,
|
||||
42, 43, 44, 44,
|
||||
45, 46, 47, 48,
|
||||
49, 50, 51, 51,
|
||||
52, 53, 54, 55,
|
||||
56, 57, 58, 59,
|
||||
60, 61, 62, 63,
|
||||
64, 65, 66, 67,
|
||||
68, 69, 70, 71,
|
||||
72, 73, 75, 76,
|
||||
77, 78, 79, 80,
|
||||
81, 83, 84, 85,
|
||||
86, 87, 88, 90,
|
||||
91, 92, 93, 95,
|
||||
96, 97, 98, 100,
|
||||
101, 102, 104, 105,
|
||||
106, 107, 109, 110,
|
||||
112, 113, 114, 116,
|
||||
117, 118, 120, 121,
|
||||
123, 124, 126, 127,
|
||||
129, 130, 131, 133,
|
||||
134, 136, 137, 139,
|
||||
141, 142, 144, 145,
|
||||
147, 148, 150, 151,
|
||||
153, 155, 156, 158,
|
||||
160, 161, 163, 165,
|
||||
166, 168, 170, 171,
|
||||
173, 175, 176, 178,
|
||||
180, 182, 183, 185,
|
||||
187, 189, 191, 192,
|
||||
194, 196, 198, 200,
|
||||
202, 203, 205, 207,
|
||||
209, 211, 213, 215,
|
||||
217, 219, 221, 223,
|
||||
225, 226, 228, 230,
|
||||
232, 234, 236, 238,
|
||||
241, 243, 245, 247,
|
||||
249, 251, 253, 255,
|
||||
};
|
||||
|
||||
|
||||
const uint8_t* lookup_table_u8_table[] = {
|
||||
lut_led_gamma,
|
||||
};
|
||||
|
||||
|
||||
|
||||
const uint8_t* lookup_table_u8_table[] = {
|
||||
};
|
||||
|
||||
|
||||
} // namespace stereo_mix
|
||||
|
|
|
@ -49,14 +49,14 @@ extern const uint8_t* lookup_table_u8_table[];
|
|||
extern const uint16_t lut_linear_to_exp[];
|
||||
extern const uint16_t lut_left_sin_pan[];
|
||||
extern const uint16_t lut_right_cos_pan[];
|
||||
extern const uint8_t lut_led_gamma[];
|
||||
extern const uint16_t lut_led_gamma[];
|
||||
#define LUT_LINEAR_TO_EXP 0
|
||||
#define LUT_LINEAR_TO_EXP_SIZE 4096
|
||||
#define LUT_LEFT_SIN_PAN 1
|
||||
#define LUT_LEFT_SIN_PAN_SIZE 4096
|
||||
#define LUT_RIGHT_COS_PAN 2
|
||||
#define LUT_RIGHT_COS_PAN_SIZE 4096
|
||||
#define LUT_LED_GAMMA 0
|
||||
#define LUT_LED_GAMMA 3
|
||||
#define LUT_LED_GAMMA_SIZE 256
|
||||
|
||||
} // namespace stereo_mix
|
||||
|
|
|
@ -28,10 +28,10 @@ lookup_tables_u16.append(('left_sin_pan', l_pan))
|
|||
lookup_tables_u16.append(('right_cos_pan', r_pan))
|
||||
|
||||
# led gamma correction
|
||||
gamma = 2.1
|
||||
gamma = 2.8
|
||||
max_in = 255
|
||||
max_out = 255
|
||||
max_out = 512
|
||||
input_vals = np.linspace(0, max_in, num=max_in + 1)
|
||||
gamma_correction = ((input_vals / max_in) ** gamma) * max_out + 0.5
|
||||
lookup_tables_u8.append(('led_gamma', np.floor(gamma_correction)))
|
||||
lookup_tables_u16.append(('led_gamma', np.floor(gamma_correction)))
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ void Init(void)
|
|||
HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM3_IRQn);
|
||||
__HAL_RCC_TIM3_CLK_ENABLE();
|
||||
htim3.Init.Prescaler = 24;
|
||||
htim3.Init.Prescaler = 14;
|
||||
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim3.Init.Period = 128;
|
||||
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
|
|
Loading…
Reference in a new issue