Skip to content

Commit

Permalink
Move dB conversion in Gain from apply to randomize_parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
iver56 committed Aug 17, 2020
1 parent 7b9c5fe commit 4732160
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions audiomentations/augmentations/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,12 +775,9 @@ def __init__(self, min_gain_in_db=-12, max_gain_in_db=12, p=0.5):
def randomize_parameters(self, samples, sample_rate):
super().randomize_parameters(samples, sample_rate)
if self.parameters["should_apply"]:
self.parameters["gain_in_db"] = random.uniform(
self.min_gain_in_db, self.max_gain_in_db
self.parameters["amplitude_ratio"] = convert_decibels_to_amplitude_ratio(
random.uniform(self.min_gain_in_db, self.max_gain_in_db)
)

def apply(self, samples, sample_rate):
amplitude_ratio = convert_decibels_to_amplitude_ratio(
self.parameters["gain_in_db"]
)
return samples * amplitude_ratio
return samples * self.parameters["amplitude_ratio"]

0 comments on commit 4732160

Please sign in to comment.