MCPcopy Index your code
hub / github.com/ipython/ipython / _validate_and_normalize_without_numpy

Method _validate_and_normalize_without_numpy

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

Source from the content-addressed store, hash-verified

190
191 @staticmethod
192 def _validate_and_normalize_without_numpy(data, normalize):
193 import array
194 import sys
195
196 data = array.array('f', data)
197
198 try:
199 max_abs_value = float(max([abs(x) for x in data]))
200 except TypeError as e:
201 raise TypeError('Only lists of mono audio are '
202 'supported if numpy is not installed') from e
203
204 normalization_factor = Audio._get_normalization_factor(max_abs_value, normalize)
205 scaled = array.array('h', [int(x / normalization_factor * 32767) for x in data])
206 if sys.byteorder == 'big':
207 scaled.byteswap()
208 nchan = 1
209 return scaled.tobytes(), nchan
210
211 @staticmethod
212 def _get_normalization_factor(max_abs_value, normalize):

Callers 1

_make_wavMethod · 0.80

Calls 1

Tested by

no test coverage detected