]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - helpers/__init__.py
Some new features:
[perso/Immae/Projets/Python/MusicSampler.git] / helpers / __init__.py
index 3b97f2fb435d5837c803895e479184b9c16b694d..2339b9ba7852318d043abf45373a3a38f089089c 100644 (file)
@@ -2,6 +2,7 @@
 import argparse
 import sys
 import os
+import math
 
 class Config:
     def __init__(self, **kwargs):
@@ -60,3 +61,10 @@ def duration_to_min_sec(duration):
         return "{:2}:{:0>2}".format(minutes, seconds)
     else:
         return "{}:{:0>2}".format(minutes, seconds)
+
+def gain(volume, old_volume = None):
+    if old_volume is None:
+        return 20 * math.log10(volume / 100)
+    else:
+        return [20 * math.log10(max(volume, 0.1) / max(old_volume, 0.1)), max(volume, 0)]
+