Skip to content

Commit 05c05e3

Browse files
committed
better naming conventions
1 parent 11f1bbb commit 05c05e3

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

Diff for: API.markdown

+21-3
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,33 @@ Creates an equivalent version of this `AudioSegment` with the specified number o
378378

379379
Splits a stereo `AudioSegment` into two, one for each channel (Left/Right). Returns a list with the new `AudioSegment` objects with the left channel at index 0 and the right channel at index 1.
380380

381-
### AudioSegment(…).set_gain(left_channel_gain, right_channel_gain)
381+
### AudioSegment(…).apply_gain_stereo()
382382

383+
```python
384+
from pydub import AudioSegment
385+
sound1 = AudioSegment.from_file("sound1.wav")
386+
387+
# make left channel 6dB quieter and right channe 2dB louder
388+
stereo_balance_adjusted = sound1.apply_gain_stereo(-6, +2)
389+
```
383390
Apply gain to the left and right channel of a stereo `AudioSegment`. If the `AudioSegment` is mono, it will be converted to stereo before applying the gain.
384391

385392
Both gain arguments are specified in dB.
386393

387-
### AudioSegment(…).pan(pan_amount)
394+
### AudioSegment(…).pan()
395+
396+
```python
397+
from pydub import AudioSegment
398+
sound1 = AudioSegment.from_file("sound1.wav")
399+
400+
# pan the sound 15% to the right
401+
panned_right = sound1.pan(+0.15)
402+
403+
# pan the sound 50% to the left
404+
panned_left = sound1.pan(-0.50)
405+
```
388406

389-
Takes one argument, `pan_amount`, which should be between -1.0 (100% left) and +1.0 (100% right)
407+
Takes one positional argument, *pan amount*, which should be between -1.0 (100% left) and +1.0 (100% right)
390408

391409
When pan_amount == 0.0 the left/right balance is not changed.
392410

Diff for: pydub/effects.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,13 @@ def pan(seg, pan_amount):
276276
boost_db = boost_db / 2.0
277277

278278
if pan_amount < 0:
279-
return seg.set_gain(boost_db, reduce_db)
279+
return seg.apply_gain_stereo(boost_db, reduce_db)
280280
else:
281-
return seg.set_gain(reduce_db, boost_db)
281+
return seg.apply_gain_stereo(reduce_db, boost_db)
282282

283283

284284
@register_pydub_effect
285-
def set_gain(seg, left_gain=0.0, right_gain=0.0):
285+
def apply_gain_stereo(seg, left_gain=0.0, right_gain=0.0):
286286
"""
287287
left_gain - amount of gain to apply to the left channel (in dB)
288288
right_gain - amount of gain to apply to the right channel (in dB)

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name='pydub',
11-
version='0.13.0',
11+
version='0.14.0',
1212
author='James Robert',
1313
author_email='[email protected]',
1414
description='Manipulate audio with an simple and easy high level interface',

Diff for: test/test.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def test_split_to_mono(self):
270270
self.assertEqual(seg_rchannel.frame_count(), seg.frame_count())
271271

272272

273-
def test_set_gain(self):
273+
def test_apply_gain_stereo(self):
274274
seg = self.seg1
275275

276276
orig_l, orig_r = seg.split_to_mono()
@@ -286,20 +286,20 @@ def assertAlmostEqual(v1, v2, **kwargs):
286286
else:
287287
self.assertAlmostEqual(v1, v2, **kwargs)
288288

289-
def test_gain(left_dbfs_change, right_dbfs_change):
290-
panned = seg.set_gain(left_dbfs_change, right_dbfs_change)
289+
def check_stereo_gain(left_dbfs_change, right_dbfs_change):
290+
panned = seg.apply_gain_stereo(left_dbfs_change, right_dbfs_change)
291291
self.assertEqual(panned.channels, 2)
292292

293293
l, r = panned.split_to_mono()
294294
assertAlmostEqual(l.dBFS, orig_dbfs_l + left_dbfs_change, places=2)
295295
assertAlmostEqual(r.dBFS, orig_dbfs_r + right_dbfs_change, places=2)
296296

297297
# hard left
298-
test_gain(0.0, -inf)
299-
test_gain(0.0, -6.0)
300-
test_gain(0.0, 0.0)
301-
test_gain(-6.0, 0.0)
302-
test_gain(-inf, 0.0)
298+
check_stereo_gain(0.0, -inf)
299+
check_stereo_gain(0.0, -6.0)
300+
check_stereo_gain(0.0, 0.0)
301+
check_stereo_gain(-6.0, 0.0)
302+
check_stereo_gain(-inf, 0.0)
303303

304304
def test_pan(self):
305305
seg = self.seg1

0 commit comments

Comments
 (0)