Audio-Spectrum-Analyzer-in-Python
Audio-Spectrum-Analyzer-in-Python copied to clipboard
Conversion of audio data to numpy array seems to be buggy...
The two steps conversion of audio data to numpy array seems buggy to me.
It should take into account (and afaik it does not) that the most significant bit of every second byte has negative weight (i.e. the numeric representation is in two's complement).
Perhaps a good starting point is to use this one step conversion
data_np = np.frombuffer(data_inp, dtype='<i2')
which lands in the range [-32768..+32767] and add an offset if desired
yes, the method I used for converting the audio data is probably not the best. I was thinking of switching to
np.fromstring(data_int)
I just tried your suggestion of using np.frombuffer(data_int, dtype='<i2') and it's working nicely. I will update the files to use that instead.