]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/commitdiff
Apply initial gain to music file
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 24 Jun 2016 17:52:39 +0000 (19:52 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 24 Jun 2016 17:52:39 +0000 (19:52 +0200)
config.yml
helpers/__init__.py
helpers/music_file.py

index d5e6664d80811ecb8b689c59c0a952e4aea50375..c7d2c5f6d1ff51faabb8a322926a595454f4e989 100644 (file)
@@ -1,54 +1,75 @@
 aliases:
   intro_jonglacro:
     file: "PIRATE_01-1-intro_jonglacro.mp3"
-    name: Intro Jonglacro
   jonglacro_suite:
     file: "PIRATE_01-2-jonglacro_suite.mp3"
-    name: Jonglacro suite
   lancer_prisonniere:
     file: "PIRATE_02-lancers_de_prisonniere.mp3"
-    name: Lancer prisonnière
   quete:
-    file: "PIRATE_03-quete.mp3"
-    name: Quête
+    file: "PIRATE_03-1-quete.mp3"
+  monstre:
+    file: "PIRATE_03-2-monstre.mp3"
   entree_ondine:
     file: "PIRATE_04-entree_ondine.mp3"
-    name: Entrée Ondine
   cour_ondine:
     file: "PIRATE_05-cour_a_londine.mp3"
-    name: Cour à l'Ondine
   fouille_jonglage:
     file: "PIRATE_07-fouille_jonglage.mp3"
-    name: Fouille jonglage
   liberation_prisonniere:
-    file: "PIRATE_08-liberation_prisonniere.mp3"
-    name: Libération prisonnière
+    file: "PIRATE_08-1-liberation_prisonniere.mp3"
+  paf:
+    file: "PIRATE_08-2-paf_tombe.mp3"
   duo_pirate_ondine:
     file: "PIRATE_09-duo_pirate_ondine.mp3"
-    name: Duo pirate Ondine
   trio_jalousie:
-    file: "PIRATE_10-trios_jalousie.mp3"
-    name: Trio Jalousie
+    file: "PIRATE_10-1-trios_jalousie.mp3"
+  coup:
+    file: "PIRATE_10-2-coup.mp3"
   piquage_2_4:
     file: "PIRATE_11-piquage_2_4.mp3"
-    name: Piquage 2-4
   baston:
     file: "PIRATE_12-1-baston.mp3"
-    name: Baston
   baston_ascension:
     file: "PIRATE_12-3-baston_ascension.mp3"
-    name: Baston ascension
-  bruit:
-    file: "PIRATE_bruit.wav"
-    name: Bruit
-  paf:
-    file: "PIRATE_paf.mp3"
-    name: Paf
-  coup:
-    file: "PIRATE_coup.wav"
-    name: Coup
+    volume: 50
   ralenti:
     file: "PIRATE_12-2-ralenti.mp3"
+
+music_properties:
+  "PIRATE_01-1-intro_jonglacro.mp3":
+    name: Intro Jonglacro
+  "PIRATE_01-2-jonglacro_suite.mp3":
+    name: Jonglacro suite
+  "PIRATE_02-lancers_de_prisonniere.mp3":
+    name: Lancer prisonnière
+  "PIRATE_03-1-quete.mp3":
+    name: Quête
+  "PIRATE_03-2-monstre.mp3":
+    name: Monstre
+  "PIRATE_04-entree_ondine.mp3":
+    name: Entrée Ondine
+  "PIRATE_05-cour_a_londine.mp3":
+    name: Cour à l'Ondine
+  "PIRATE_07-fouille_jonglage.mp3":
+    name: Fouille jonglage
+  "PIRATE_08-1-liberation_prisonniere.mp3":
+    name: Libération prisonnière
+  "PIRATE_08-2-paf_tombe.mp3":
+    name: Paf tombe
+  "PIRATE_09-duo_pirate_ondine.mp3":
+    name: Duo pirate Ondine
+  "PIRATE_10-1-trios_jalousie.mp3":
+    name: Trio Jalousie
+  "PIRATE_10-2-coup.mp3":
+    name: Coup
+  "PIRATE_11-piquage_2_4.mp3":
+    name: Piquage 2-4
+  "PIRATE_12-1-baston.mp3":
+    name: Baston
+  "PIRATE_12-3-baston_ascension.mp3":
+    name: Baston ascension
+    gain: 2
+  "PIRATE_12-2-ralenti.mp3":
     name: Ralenti
 
 key_properties:
@@ -220,7 +241,7 @@ keys:
   'e':
     - stop:
         include: jonglacro_suite
-        fade_out: 5
+        fade_out: 3
   'r':
     - play:
         include: lancer_prisonniere
@@ -236,7 +257,7 @@ keys:
         include: quete
         value: 50
     - play:
-        include: bruit
+        include: monstre
     - wait:
         duration: 2
     - volume:
@@ -253,9 +274,9 @@ keys:
   'o':
     - stop:
         include: entree_ondine
-        fade_out: 5
+        fade_out: 4
     - wait:
-        duration: 5
+        duration: 4
     - play:
         include: cour_ondine
   'p':
@@ -273,11 +294,14 @@ keys:
     - play:
         include: liberation_prisonniere
   'f':
-    - volume:
-        include: liberation_prisonniere
-        value: 20
     - play:
         include: paf
+    - wait:
+        duration: 0.2
+    - volume:
+        include: liberation_prisonniere
+        value: 30
+
   'g':
     - stop:
         include: liberation_prisonniere
@@ -290,7 +314,7 @@ keys:
         include: duo_pirate_ondine
         fade_out: 2
     - wait:
-        duration: 2
+        duration: 1.5
     - play:
         include: trio_jalousie
   'k':
@@ -307,30 +331,36 @@ keys:
   'm':
     - stop:
         include: piquage_2_4
-        fade_out: 5
+        fade_out: 4
     - wait:
-        duration: 7
+        duration: 6
     - play:
         include: baston
   'w':
     - stop:
         include: baston
-        fade_out: 1
+        fade_out: 0.5
     - wait:
-        duration: 1
+        duration: 0.5
     - play:
         include: ralenti
   'x':
     - stop:
         include: ralenti
-        fade_out: 2
+        fade_out: 1.5
   'c':
     - play:
         include: baston_ascension
+#    - volume:
+#        include: baston_ascension
+#        value: 100
   'v':
     - stop:
         include: baston_ascension
         fade_out: 2
+#  'n':
+#    - play:
+#        include: baston_ascension
   'ESC':
     - stop: ~
     - stop_all_actions: ~
index 0e29f5dbde1717b11496460f5b9fd461df526e83..7fe9c35236806b009f4d06057c60757e25709385 100644 (file)
@@ -42,10 +42,17 @@ def parse_config(mapping):
                 if argument == 'file':
                     filename = action[action_name]['file']
                     if filename not in seen_files:
-                        if 'name' in action[action_name]:
-                            seen_files[filename] = MusicFile(filename, file_lock, channel_id, name = action[action_name]['name'])
+                        if filename in config['music_properties']:
+                            seen_files[filename] = MusicFile(
+                                    filename,
+                                    file_lock,
+                                    channel_id, 
+                                    **config['music_properties'][filename])
                         else:
-                            seen_files[filename] = MusicFile(filename, file_lock, channel_id)
+                            seen_files[filename] = MusicFile(
+                                    filename,
+                                    file_lock,
+                                    channel_id)
                         channel_id = channel_id + 1
 
                     action_args['music'] = seen_files[filename]
index 667c16905859c97d997ee2fc0d54b25c22f10805..892519d2e843be9423b98399aad37de6ce7060f4 100644 (file)
@@ -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))