7 def __init__(self
, effect
, audio_segment
, initial_loop
, start
, end
,
9 if effect
in self
.effect_types
:
16 self
.audio_segment
= audio_segment
17 self
.initial_loop
= initial_loop
18 getattr(self
, self
.effect
+ "_init")(**kwargs
)
20 def get_last_gain(self
):
21 return getattr(self
, self
.effect
+ "_get_last_gain")()
23 def get_next_gain(self
, current_frame
, current_loop
, frame_count
):
24 # This returns two values:
25 # - The first one is the gain to apply on that frame
26 # - The last one is True or False depending on whether it is the last
27 # call to the function and the last gain should be saved permanently
28 return getattr(self
, self
.effect
+ "_get_next_gain")(
34 def noop_init(self
, **kwargs
):
37 def noop_get_last_gain(self
, **kwargs
):
40 def noop_get_next_gain(self
, **kwargs
):
44 def fade_init(self
, gain
=0, **kwargs
):
45 self
.audio_segment_frame_count
= self
.audio_segment
.frame_count()
46 self
.first_frame
= int(
47 self
.audio_segment_frame_count
* self
.initial_loop
+\
48 self
.audio_segment
.frame_rate
* self
.start
)
49 self
.last_frame
= int(
50 self
.audio_segment_frame_count
* self
.initial_loop
+\
51 self
.audio_segment
.frame_rate
* self
.end
)
54 def fade_get_last_gain(self
):
57 def fade_get_next_gain(self
, current_frame
, current_loop
, frame_count
):
58 current_frame
= current_frame \
59 + (current_loop
- self
.initial_loop
) \
60 * self
.audio_segment_frame_count
62 if current_frame
>= self
.last_frame
:
63 return [self
.gain
, True]
64 elif current_frame
< self
.first_frame
:
68 (current_frame
- self
.first_frame
) / \
69 (self
.last_frame
- self
.first_frame
) * self
.gain
,