AllenDowney / ThinkDSP

Think DSP: Digital Signal Processing in Python, by Allen B. Downey.
https://allendowney.github.io/ThinkDSP/
3.93k stars 3.2k forks source link

if read_wave() then write(), the new audio is different in amp. #82

Open fangpo opened 3 years ago

fangpo commented 3 years ago

https://github.com/AllenDowney/ThinkDSP/blob/eeef574b4b94c95d57c70c96d9083cd7cd33f346/code/thinkdsp.py#L124

In read_wave(), the call to normalize() makes issue: if read_wave() then write(), the new audio is different in amp. Suggest don't call normalize(), but convert data to [-1.0, 1.0] using: ys = ys * 1.0 / ( 2 * (sampwidth 8 - 1));

122,123d121 < ys = ys * 1.0 / ( 2 * (sampwidth 8 - 1)); < 126,127c124 < < # wave.normalize()

wave.normalize()
AllenDowney commented 2 years ago

This is probably a good idea, but I'm going to leave this open for now.

Thanks for this suggestion!