Skip to content

Commit

Permalink
Merge pull request #234 from ywwg/fix-tomono
Browse files Browse the repository at this point in the history
When converting stereo to mono, divide samples by two to avoid clipping
  • Loading branch information
jiaaro authored Nov 22, 2017
2 parents 0cd5dbb + 76cd25b commit c95b814
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pydub/audio_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,11 +752,13 @@ def set_channels(self, channels):
if channels == 2 and self.channels == 1:
fn = audioop.tostereo
frame_width = self.frame_width * 2
fac = 1
elif channels == 1 and self.channels == 2:
fn = audioop.tomono
frame_width = self.frame_width // 2
fac = 0.5

converted = fn(self._data, self.sample_width, 1, 1)
converted = fn(self._data, self.sample_width, fac, fac)

return self._spawn(data=converted,
overrides={
Expand Down

0 comments on commit c95b814

Please sign in to comment.