From 87f211fb622ef640249628b65d0bc8daca889f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Fri, 24 Jun 2016 19:52:39 +0200 Subject: Apply initial gain to music file --- helpers/music_file.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'helpers/music_file.py') diff --git a/helpers/music_file.py b/helpers/music_file.py index 667c169..892519d 100644 --- a/helpers/music_file.py +++ b/helpers/music_file.py @@ -1,13 +1,15 @@ import threading import pydub import pygame +import math class MusicFile: - def __init__(self, filename, lock, channel_id, name = None): + def __init__(self, filename, lock, channel_id, name = None, gain = 1): self.filename = filename self.channel_id = channel_id self.name = name or filename self.raw_data = None + self.gain = gain self.loaded = False self.flag_paused = False @@ -16,7 +18,8 @@ class MusicFile: def load_sound(self, lock): lock.acquire() print("Loading « {} »".format(self.name)) - audio_segment = pydub.AudioSegment.from_file(self.filename).set_frame_rate(44100) + volume_factor = 20 * math.log10(self.gain) + audio_segment = pydub.AudioSegment.from_file(self.filename).set_frame_rate(44100).apply_gain(volume_factor) self.sound_duration = audio_segment.duration_seconds self.raw_data = audio_segment.raw_data print("Loaded « {} »".format(self.name)) -- cgit v1.2.3