diff options
Diffstat (limited to 'helpers/music_effect.py')
-rw-r--r-- | helpers/music_effect.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/helpers/music_effect.py b/helpers/music_effect.py index ef8dc90..23583cd 100644 --- a/helpers/music_effect.py +++ b/helpers/music_effect.py | |||
@@ -3,7 +3,7 @@ class GainEffect: | |||
3 | 'fade' | 3 | 'fade' |
4 | ] | 4 | ] |
5 | 5 | ||
6 | def __init__(self, effect, audio_segment, start, end, **kwargs): | 6 | def __init__(self, effect, audio_segment, initial_loop, start, end, **kwargs): |
7 | if effect in self.effect_types: | 7 | if effect in self.effect_types: |
8 | self.effect = effect | 8 | self.effect = effect |
9 | else: | 9 | else: |
@@ -12,30 +12,41 @@ class GainEffect: | |||
12 | self.start = start | 12 | self.start = start |
13 | self.end = end | 13 | self.end = end |
14 | self.audio_segment = audio_segment | 14 | self.audio_segment = audio_segment |
15 | self.initial_loop = initial_loop | ||
15 | getattr(self, self.effect + "_init")(**kwargs) | 16 | getattr(self, self.effect + "_init")(**kwargs) |
16 | 17 | ||
17 | def get_last_gain(self): | 18 | def get_last_gain(self): |
18 | return getattr(self, self.effect + "_get_last_gain")() | 19 | return getattr(self, self.effect + "_get_last_gain")() |
19 | 20 | ||
20 | def get_next_gain(self, current_frame, frame_count): | 21 | def get_next_gain(self, current_frame, current_loop, frame_count): |
21 | # This returns two values: | 22 | # This returns two values: |
22 | # - The first one is the gain to apply on that frame | 23 | # - The first one is the gain to apply on that frame |
23 | # - The last one is True or False depending on whether it is the last | 24 | # - The last one is True or False depending on whether it is the last |
24 | # call to the function and the last gain should be saved permanently | 25 | # call to the function and the last gain should be saved permanently |
25 | return getattr(self, self.effect + "_get_next_gain")( | 26 | return getattr(self, self.effect + "_get_next_gain")( |
26 | current_frame, | 27 | current_frame, |
28 | current_loop, | ||
27 | frame_count) | 29 | frame_count) |
28 | 30 | ||
29 | # Fading | 31 | # Fading |
30 | def fade_init(self, gain=0, **kwargs): | 32 | def fade_init(self, gain=0, **kwargs): |
31 | self.first_frame = int(self.audio_segment.frame_rate * self.start) | 33 | self.audio_segment_frame_count = self.audio_segment.frame_count() |
32 | self.last_frame = int(self.audio_segment.frame_rate * self.end) | 34 | self.first_frame = int( |
35 | self.audio_segment_frame_count * self.initial_loop +\ | ||
36 | self.audio_segment.frame_rate * self.start) | ||
37 | self.last_frame = int( | ||
38 | self.audio_segment_frame_count * self.initial_loop +\ | ||
39 | self.audio_segment.frame_rate * self.end) | ||
33 | self.gain= gain | 40 | self.gain= gain |
34 | 41 | ||
35 | def fade_get_last_gain(self): | 42 | def fade_get_last_gain(self): |
36 | return self.gain | 43 | return self.gain |
37 | 44 | ||
38 | def fade_get_next_gain(self, current_frame, frame_count): | 45 | def fade_get_next_gain(self, current_frame, current_loop, frame_count): |
46 | current_frame = current_frame \ | ||
47 | + (current_loop - self.initial_loop) \ | ||
48 | * self.audio_segment_frame_count | ||
49 | |||
39 | if current_frame >= self.last_frame: | 50 | if current_frame >= self.last_frame: |
40 | return [self.gain, True] | 51 | return [self.gain, True] |
41 | elif current_frame < self.first_frame: | 52 | elif current_frame < self.first_frame: |