Audio-Spectrum-Analyzer-in-Python icon indicating copy to clipboard operation
Audio-Spectrum-Analyzer-in-Python copied to clipboard

Conversion of audio data to numpy array seems to be buggy...

Open ginsi opened this issue 7 years ago • 2 comments

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

ginsi avatar Feb 19 '18 16:02 ginsi

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)

markjay4k avatar Feb 19 '18 20:02 markjay4k

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.

markjay4k avatar Feb 20 '18 00:02 markjay4k