6 def __init__(self
, effect
, audio_segment
, initial_loop
, start
, end
,
8 if effect
in self
.effect_types
:
11 raise Exception("Unknown effect {}".format(effect
))
15 self
.audio_segment
= audio_segment
16 self
.initial_loop
= initial_loop
17 getattr(self
, self
.effect
+ "_init")(**kwargs
)
19 def get_last_gain(self
):
20 return getattr(self
, self
.effect
+ "_get_last_gain")()
22 def get_next_gain(self
, current_frame
, current_loop
, frame_count
):
23 # This returns two values:
24 # - The first one is the gain to apply on that frame
25 # - The last one is True or False depending on whether it is the last
26 # call to the function and the last gain should be saved permanently
27 return getattr(self
, self
.effect
+ "_get_next_gain")(
33 def fade_init(self
, gain
=0, **kwargs
):
34 self
.audio_segment_frame_count
= self
.audio_segment
.frame_count()
35 self
.first_frame
= int(
36 self
.audio_segment_frame_count
* self
.initial_loop
+\
37 self
.audio_segment
.frame_rate
* self
.start
)
38 self
.last_frame
= int(
39 self
.audio_segment_frame_count
* self
.initial_loop
+\
40 self
.audio_segment
.frame_rate
* self
.end
)
43 def fade_get_last_gain(self
):
46 def fade_get_next_gain(self
, current_frame
, current_loop
, frame_count
):
47 current_frame
= current_frame \
48 + (current_loop
- self
.initial_loop
) \
49 * self
.audio_segment_frame_count
51 if current_frame
>= self
.last_frame
:
52 return [self
.gain
, True]
53 elif current_frame
< self
.first_frame
:
57 (current_frame
- self
.first_frame
) / \
58 (self
.last_frame
- self
.first_frame
) * self
.gain
,