Skip to content

Commit

Permalink
Fix trimming when file is all silent
Browse files Browse the repository at this point in the history
  • Loading branch information
rrealmuto committed Nov 12, 2024
1 parent c510c75 commit af28322
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Voices.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,12 @@ def process_soundfile_file(f, trim=False):
data = np.mean(data, axis=1)
data = data / max(abs(data.max()), abs(data.min())) # Normalize track
data = (data*32768).astype('>i2') # Convert to 16 bit big endian integers
if trim:
trim_index = list(map(lambda i: i > 0, data)).index(True)
data = data[trim_index:]
if trim: # Trim data - primarily used because ML64 sucks
try:
trim_index = list(map(lambda i: i > 0, data)).index(True)
data = data[trim_index:]
except ValueError as e:
pass
frames = data.tobytes()
numSampleFrames = len(data)
soundData = adpcm_encode(frames, len(data)) # Encode the raw samples
Expand Down

0 comments on commit af28322

Please sign in to comment.