maad.sound.normalize

maad.sound.normalize(s, max_amp=0.7, max_db=None)[source]

Normalize audio signal to desired amplitude or decibell full scale value (dBFS).

Parameters:
snp.ndarray

Mono audio signal as NumPy array.

max_ampfloat, optional

Maximum amplitude. Must be between 0-1. The default is 0.7.

max_dbfloat, optional

Maximum amplitude in dBFS. Must be a negative value.

Returns:
s_outnp.ndarray

Normalized mono signal.

See also

sound.trim

Examples

>>> import numpy as np
>>> from maad import sound

Use normalized amplitude value for normalization

>>> s, fs = sound.load('../data/spinetail.wav')
>>> s_out = sound.normalize(s, max_amp=0.8)
>>> print('s_out maximum amplitude:', np.abs(s_out).max())
s_out maximum amplitude: 0.8

Use a dBFS value for normalization:

>>> s, fs = sound.load('../data/spinetail.wav')
>>> s_out = sound.normalize(s, max_db=-3)
>>> print('s_out maximum value in dBFS:', np.max(20*np.log10(np.abs(s_out))))
s_out maximum value in dBFS: -3.0