mirror of
https://github.com/romanz/amodem.git
synced 2026-04-21 05:36:42 +08:00
use specific exception for saturation
This commit is contained in:
@@ -42,6 +42,10 @@ def to_byte(bits):
|
|||||||
return chr(byte)
|
return chr(byte)
|
||||||
|
|
||||||
|
|
||||||
|
class SaturationError(ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def load(fileobj, time=False):
|
def load(fileobj, time=False):
|
||||||
return loads(fileobj.read(), time=time)
|
return loads(fileobj.read(), time=time)
|
||||||
|
|
||||||
@@ -49,8 +53,9 @@ def load(fileobj, time=False):
|
|||||||
def loads(data, time=False):
|
def loads(data, time=False):
|
||||||
x = np.fromstring(data, dtype='int16')
|
x = np.fromstring(data, dtype='int16')
|
||||||
x = x / scaling
|
x = x / scaling
|
||||||
if np.max(np.abs(x)) > SATURATION_THRESHOLD:
|
peak = np.max(np.abs(x))
|
||||||
raise ValueError('saturation')
|
if peak > SATURATION_THRESHOLD:
|
||||||
|
raise SaturationError(peak)
|
||||||
|
|
||||||
if time:
|
if time:
|
||||||
t = np.arange(len(x)) / Fs
|
t = np.arange(len(x)) / Fs
|
||||||
|
|||||||
Reference in New Issue
Block a user