MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / decode_input_to_float

Function decode_input_to_float

examples/csv2wav/csv2wav.py:87–105  ·  view source on GitHub ↗
(audio, in_format)

Source from the content-addressed store, hash-verified

85
86
87def decode_input_to_float(audio, in_format):
88 if in_format == "float32":
89 x = audio.astype(np.float32)
90 peak = np.max(np.abs(x))
91 return x / peak if peak > 1.0 else x
92
93 if in_format == "int16":
94 return np.clip(audio / 32768.0, -1.0, 1.0).astype(np.float32)
95
96 if in_format == "uint8":
97 return np.clip((audio - 128.0) / 127.5, -1.0, 1.0).astype(np.float32)
98
99 if in_format == "int24":
100 return np.clip(audio / 8388608.0, -1.0, 1.0).astype(np.float32)
101
102 if in_format == "int32":
103 return np.clip(audio / 2147483648.0, -1.0, 1.0).astype(np.float32)
104
105 raise ValueError(f"Unsupported input format {in_format}")
106
107
108def remove_dc(audio):

Callers 1

convert_csv_to_wavFunction · 0.85

Calls 1

clipMethod · 0.80

Tested by

no test coverage detected