Skip to content

Commit

Permalink
Compare values multiplied by max_poss
Browse files Browse the repository at this point in the history
  • Loading branch information
dmotte committed Dec 12, 2024
1 parent 2116c68 commit dbd9ba2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions python-scripts/percamptrim/compute-trim.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def compute_values(audio: AudioSegment,

frame_rate = audio.frame_rate

# Maximum possible (absolute) value of a sample
max_poss = 2 ** (8 * audio.sample_width - 1)

samples = audio.get_array_of_samples()
len_samples = len(samples)

Expand All @@ -28,14 +31,14 @@ def compute_values(audio: AudioSegment,
sample_start = 0 # First sample, inclusive
if level_start > 0:
for i in range(0, len_samples):
if samples_abs[i] >= level_start:
if samples_abs[i] >= level_start * max_poss:
sample_start = i
break

sample_end = len_samples # Last sample, exclusive
if level_end > 0:
for i in range(len_samples - 1, -1, -1):
if samples_abs[i] >= level_end:
if samples_abs[i] >= level_end * max_poss:
sample_end = i + 1
break

Expand Down

0 comments on commit dbd9ba2

Please sign in to comment.