MCPcopy Create free account
hub / github.com/ipython/ipython / _validate_and_normalize_without_numpy

Method _validate_and_normalize_without_numpy

IPython/lib/display.py:177–194  ·  view source on GitHub ↗
(data, normalize)

Source from the content-addressed store, hash-verified

175
176 @staticmethod
177 def _validate_and_normalize_without_numpy(data, normalize):
178 import array
179 import sys
180
181 data = array.array('f', data)
182
183 try:
184 max_abs_value = float(max([abs(x) for x in data]))
185 except TypeError:
186 raise TypeError('Only lists of mono audio are '
187 'supported if numpy is not installed')
188
189 normalization_factor = Audio._get_normalization_factor(max_abs_value, normalize)
190 scaled = array.array('h', [int(x / normalization_factor * 32767) for x in data])
191 if sys.byteorder == 'big':
192 scaled.byteswap()
193 nchan = 1
194 return scaled.tobytes(), nchan
195
196 @staticmethod
197 def _get_normalization_factor(max_abs_value, normalize):

Callers 1

_make_wavMethod · 0.80

Calls 1

Tested by

no test coverage detected