2020-02-18 11:05:27 +00:00
|
|
|
import numpy as np
|
2020-04-28 20:07:34 +00:00
|
|
|
import matplotlib
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
2020-03-30 09:40:19 +00:00
|
|
|
lookup_tables_u16 = []
|
2020-04-23 22:38:05 +00:00
|
|
|
lookup_tables_u8 = []
|
2019-12-03 23:00:54 +00:00
|
|
|
|
2020-04-01 10:04:42 +00:00
|
|
|
ADC_RESOLUTION = 4096
|
|
|
|
OUTPUT_RESOLUTION = 2 ** 16 - 1
|
2019-12-03 23:00:54 +00:00
|
|
|
|
|
|
|
# linear to exponential conversion
|
|
|
|
|
2020-04-28 20:07:34 +00:00
|
|
|
space = np.linspace(0, 1, num=ADC_RESOLUTION)
|
|
|
|
values = np.power(space, 2) * OUTPUT_RESOLUTION
|
2019-12-03 23:00:54 +00:00
|
|
|
|
2020-03-30 09:40:19 +00:00
|
|
|
lookup_tables_u16.append(('linear_to_exp', values))
|
2020-04-28 20:51:36 +00:00
|
|
|
print(values.size)
|
2019-12-03 23:44:46 +00:00
|
|
|
|
2020-04-28 20:07:34 +00:00
|
|
|
fig, ax = plt.subplots()
|
|
|
|
ax.plot(space, values)
|
|
|
|
other_values = OUTPUT_RESOLUTION - np.flip(values)
|
|
|
|
ax.plot(space, OUTPUT_RESOLUTION - (np.flip(values)))
|
|
|
|
|
|
|
|
ax.set(xlabel='space', ylabel='values')
|
|
|
|
ax.grid()
|
|
|
|
|
2020-05-10 23:08:50 +00:00
|
|
|
#plt.show()
|
2020-04-28 20:07:34 +00:00
|
|
|
|
2019-12-03 23:44:46 +00:00
|
|
|
|
|
|
|
# Left pan Lookup table
|
|
|
|
|
2020-04-28 20:51:36 +00:00
|
|
|
space = np.linspace(0, (np.pi / 2.0), num=ADC_RESOLUTION)
|
|
|
|
|
|
|
|
l_pan = np.sqrt(space * (2.0 / np.pi) * np.sin(space))
|
|
|
|
r_pan = np.sqrt(((np.pi / 2.0) - space) * (2.0 / np.pi) * np.cos(space))
|
|
|
|
|
|
|
|
l_pan = np.floor(l_pan * OUTPUT_RESOLUTION)
|
|
|
|
r_pan = np.floor(r_pan * OUTPUT_RESOLUTION)
|
|
|
|
|
|
|
|
fig, ax = plt.subplots()
|
|
|
|
ax.plot(space, l_pan)
|
|
|
|
ax.plot(space, r_pan)
|
2019-12-03 23:44:46 +00:00
|
|
|
|
2020-04-28 20:51:36 +00:00
|
|
|
ax.set(xlabel='space', ylabel='values')
|
|
|
|
ax.grid()
|
2019-12-03 23:44:46 +00:00
|
|
|
|
2020-04-28 20:51:36 +00:00
|
|
|
#plt.show()
|
2019-12-03 23:44:46 +00:00
|
|
|
|
2020-03-30 09:40:19 +00:00
|
|
|
lookup_tables_u16.append(('left_sin_pan', l_pan))
|
2020-04-28 20:51:36 +00:00
|
|
|
print(l_pan.size)
|
2020-03-30 09:40:19 +00:00
|
|
|
lookup_tables_u16.append(('right_cos_pan', r_pan))
|
2020-04-28 20:51:36 +00:00
|
|
|
print(r_pan.size)
|
2019-12-03 23:44:46 +00:00
|
|
|
|
2020-04-23 22:38:05 +00:00
|
|
|
# led gamma correction
|
2020-07-16 18:47:55 +00:00
|
|
|
gamma_green = 2.4
|
|
|
|
gamma_red = 2.8
|
2020-07-17 18:01:05 +00:00
|
|
|
max_in = 2048
|
2020-07-16 18:47:55 +00:00
|
|
|
max_out = 65535
|
2020-04-23 22:38:05 +00:00
|
|
|
input_vals = np.linspace(0, max_in, num=max_in + 1)
|
2020-07-16 18:47:55 +00:00
|
|
|
gamma_correction_red = ((input_vals / max_in) ** gamma_red) * max_out + 0.5
|
|
|
|
gamma_correction_green = ((input_vals / max_in) ** gamma_green) * max_out + 0.5
|
|
|
|
lookup_tables_u16.append(('led_red_gamma', np.floor(gamma_correction_red)))
|
|
|
|
lookup_tables_u16.append(('led_green_gamma', np.floor(gamma_correction_green)))
|