Find the maximum peak (positive or negative, so use abs) in any channel. For instance in a 16 bits file, imagine you find 25000. Compute the ratio of that value relatively to the maximum in the signed 16 bit range and invert it :
ratio = 32767.0 / 25000 #(equivalent to 1 / (25000 / 32767.0))
Now iterate all samples and multiply them by the inverted ratio so that 25000 becomes 32767 :
for(sample in samples):
sample = round(sample * ratio)
This operation is called "normalization" or "optimization" depending on the software.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…