6 def __init__(self
, effect
, audio_segment
, initial_loop
, start
, end
, **kwargs
):
7 if effect
in self
.effect_types
:
10 raise Exception("Unknown effect {}".format(effect
))
14 self
.audio_segment
= audio_segment
15 self
.initial_loop
= initial_loop
16 getattr(self
, self
.effect
+ "_init")(**kwargs
)
18 def get_last_gain(self
):
19 return getattr(self
, self
.effect
+ "_get_last_gain")()
21 def get_next_gain(self
, current_frame
, current_loop
, frame_count
):
22 # This returns two values:
23 # - The first one is the gain to apply on that frame
24 # - The last one is True or False depending on whether it is the last
25 # call to the function and the last gain should be saved permanently
26 return getattr(self
, self
.effect
+ "_get_next_gain")(
32 def fade_init(self
, gain
=0, **kwargs
):
33 self
.audio_segment_frame_count
= self
.audio_segment
.frame_count()
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
)
42 def fade_get_last_gain(self
):
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
50 if current_frame
>= self
.last_frame
:
51 return [self
.gain
, True]
52 elif current_frame
< self
.first_frame
:
56 (current_frame
- self
.first_frame
) / \
57 (self
.last_frame
- self
.first_frame
) * self
.gain
,