Skip to content

Commit b1c03bc

Browse files
improve bitmap resolution; fix scale factor calculation
improve resolution: remove debug remnant fix scale factor calculation: determine maximum sample value from extracted samples rather than source samples (values that may not be used for plotting)
1 parent a20f140 commit b1c03bc

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

cedargrove_waveviz.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,26 @@ def palette(self):
8888
return self._palette
8989

9090
def _plot_wave(self):
91-
"""Plot the wave_table as a bitmap."""
92-
samples = len(self._wave_table)
93-
max_value = max(abs(min(self._wave_table)), abs(max(self._wave_table)))
94-
scale_y = self._size[1] / max_value / 2
91+
"""Plot the wave_table as a bitmap. Extract samples from the wave
92+
table to fill the bitmap object's x-axis. Y-axis scale factor is
93+
determined from the extracted sample values."""
94+
samples = len(self._wave_table) # Samples in wave table
95+
96+
# Detect maximum value of extracted values and calculate scale factor
97+
max_sample_value = 0
98+
for x in range(self._size[0]):
99+
table_idx = int(x * (samples / self._size[0]))
100+
max_sample_value = max(
101+
abs(min(max_sample_value, self._wave_table[table_idx])),
102+
abs(max(max_sample_value, self._wave_table[table_idx])),
103+
)
104+
scale_y = self._size[1] / max_sample_value / 2
95105

96106
self._prev_point = (0, 0) # (display x index, wave_table index)
97107

98-
for x in range(0, self._size[0], 2):
99-
table_index = int(x * (samples / self._size[0]))
100-
self._next_point = (x, table_index)
108+
for x in range(0, self._size[0]):
109+
table_idx = int(x * (samples / self._size[0]))
110+
self._next_point = (x, table_idx)
101111

102112
bitmaptools.draw_line(
103113
self._bmp,

0 commit comments

Comments
 (0)