kopia lustrzana https://github.com/corrscope/corrscope
Refactor Wave class and add support for float waves
rodzic
7a818c0cd3
commit
332413e8ef
|
@ -28,15 +28,27 @@ class Wave:
|
|||
# TODO extract function, unit tests... switch to pysoundfile and drop logic
|
||||
dtype = self.data.dtype
|
||||
|
||||
max_val = np.iinfo(dtype).max + 1
|
||||
assert max_val & (max_val - 1) == 0 # power of 2
|
||||
def is_type(parent: type) -> bool:
|
||||
return np.issubdtype(dtype, parent)
|
||||
|
||||
if np.issubdtype(dtype, np.uint):
|
||||
self.offset = -max_val // 2
|
||||
self.max_val = max_val // 2
|
||||
else:
|
||||
if is_type(np.integer):
|
||||
max_int = np.iinfo(dtype).max + 1
|
||||
assert max_int & (max_int - 1) == 0 # power of 2
|
||||
|
||||
if is_type(np.unsignedinteger):
|
||||
self.offset = -max_int // 2
|
||||
self.max_val = max_int // 2
|
||||
|
||||
elif is_type(np.signedinteger):
|
||||
self.offset = 0
|
||||
self.max_val = max_int
|
||||
|
||||
elif is_type(np.float):
|
||||
self.offset = 0
|
||||
self.max_val = max_val
|
||||
self.max_val = 1
|
||||
|
||||
else:
|
||||
raise ValueError(f'unexpected wavfile dtype {dtype}')
|
||||
|
||||
def __getitem__(self, index: int) -> 'np.ndarray[FLOAT]':
|
||||
""" Copies self.data[item], converted to a FLOAT within range [-1, 1). """
|
||||
|
|
Ładowanie…
Reference in New Issue