While developing an application, I noticed strange behaviour while using scipy.io.wavfile to write audio files. The documentation says that floating-point data is written within a range between -1 and 1. However, files written this way seemingly can go past that. This is a MWE to illustrate what I mean:
import numpy as np
from scipy.io import wavfile
# %% Writing supposedly saturated file
A = 2
f = 5
fs = 44100
t = np.linspace(0, 1, fs + 1)
testSignal = A * np.sin(2 * np.pi * f * t)
wavfile.write('test.wav', fs, testSignal.astype(float))
# %% Reading file with intact values
_, writtenData = wavfile.read('test.wav')
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
plt.plot(t, writtenData)
plt.ylabel("Signal")
plt.xlabel("Time")
plt.show()
As you can see, even though I explicitly specified that the array past was to be in the floating-point format (and beyond -1 to 1), I was able to retrieve it without alterations.
After all, what gives? Are .wav files in float format really only capable of storing data between (-1,1)? Is there any hidden conversion going on that I might be missing out on?
TIA