Skip to content

Commit 4994a87

Browse files
committed
get sample && get_dc_offset
1 parent df6530e commit 4994a87

File tree

1 file changed

+0
-42
lines changed

1 file changed

+0
-42
lines changed

open_dubbing/pydub_audio_segment.py

-42
Original file line numberDiff line numberDiff line change
@@ -334,31 +334,6 @@ def __getitem__(self, millisecond):
334334

335335
return self._spawn(data)
336336

337-
def get_sample_slice(self, start_sample=None, end_sample=None):
338-
"""
339-
Get a section of the audio segment by sample index.
340-
341-
NOTE: Negative indices do *not* address samples backword
342-
from the end of the audio segment like a python list.
343-
This is intentional.
344-
"""
345-
max_val = int(self.frame_count())
346-
347-
def bounded(val, default):
348-
if val is None:
349-
return default
350-
if val < 0:
351-
return 0
352-
if val > max_val:
353-
return max_val
354-
return val
355-
356-
start_i = bounded(start_sample, 0) * self.frame_width
357-
end_i = bounded(end_sample, max_val) * self.frame_width
358-
359-
data = self._data[start_i:end_i]
360-
return self._spawn(data)
361-
362337
def __add__(self, arg):
363338
if isinstance(arg, AudioSegment):
364339
return self.append(arg, crossfade=0)
@@ -1112,23 +1087,6 @@ def max_dBFS(self):
11121087
def duration_seconds(self):
11131088
return self.frame_rate and self.frame_count() / self.frame_rate or 0.0
11141089

1115-
def get_dc_offset(self, channel=1):
1116-
"""
1117-
Returns a value between -1.0 and 1.0 representing the DC offset of a
1118-
channel (1 for left, 2 for right).
1119-
"""
1120-
if not 1 <= channel <= 2:
1121-
raise ValueError("channel value must be 1 (left) or 2 (right)")
1122-
1123-
if self.channels == 1:
1124-
data = self._data
1125-
elif channel == 1:
1126-
data = audioop.tomono(self._data, self.sample_width, 1, 0)
1127-
else:
1128-
data = audioop.tomono(self._data, self.sample_width, 0, 1)
1129-
1130-
return float(audioop.avg(data, self.sample_width)) / self.max_possible_amplitude
1131-
11321090
def remove_dc_offset(self, channel=None, offset=None):
11331091
"""
11341092
Removes DC offset of given channel. Calculates offset if it's not given.

0 commit comments

Comments
 (0)