gensound.effect¶
The module of audio effects
-
class
gensound.effect.
Effect
[source]¶ Bases:
object
Base class of sound effect
-
apply
(sound)[source]¶ Apply effect to sound
Parameters: sound ( Sound
) –Sound
instance to appling effect.Return type: Sound
Returns: A Sound
instance that applied effect.You can use shift operator as apply() like a streaming operator of C++.
>>> effect = LinearFadeIn() >>> sound = Sound.from_sinwave(440) >>> effect.apply(sound) == (effect << sound) == (sound >> effect) True
-
then
(effect)[source]¶ Join effect
Effect: Effect that will apply after this effect. Return type: Effect
Returns: Joined effect. >>> in_ = LinearFadeIn() >>> out = LinearFadeOut() >>> sound = Sound.from_sinwave(440)
>>> out.apply(in_.apply(sound)) == in_.then(out).apply(sound) True
You can use shift operator as then() like a streaming operator of C++.
>>> sound >> in_ >> out == in_.then(out).apply(sound) True
-
-
class
gensound.effect.
JoinedEffect
(*effects: gensound.effect.Effect) → None[source]¶ Bases:
gensound.effect.Effect
Joined multiple effects
Parameters: effects ( Effect
) – Effect instances to joint.Raises: ValueError – If effects not given. >>> in_ = LinearFadeIn() >>> out = LinearFadeOut() >>> sound = Sound.from_sinwave(440)
>>> out.apply(in_.apply(sound)) == JoinedEffect(in_, out).apply(sound) True
>>> out.apply(in_.apply(sound)) == in_.then(out).apply(sound) True
>>> out << in_ << sound == JoinedEffect(in_, out).apply(sound) True
-
class
gensound.effect.
MaskEffect
(duration: typing.Union[float, NoneType] = None) → None[source]¶ Bases:
gensound.effect.Effect
Masking effect
Parameters: duration ( Optional
[float
]) – Duration in seconds of mask. Mathing to sound duration if None.
-
class
gensound.effect.
MaskStartEffect
(duration: typing.Union[float, NoneType] = None) → None[source]¶ Bases:
gensound.effect.MaskEffect
Effect that masking start of sound
-
class
gensound.effect.
MaskEndEffect
(duration: typing.Union[float, NoneType] = None) → None[source]¶ Bases:
gensound.effect.MaskEffect
Effect that masking end of sound
-
class
gensound.effect.
LinearFadeIn
(duration: typing.Union[float, NoneType] = None) → None[source]¶ Bases:
gensound.effect.MaskStartEffect
Linear fade-in effect
Parameters: duration ( Optional
[float
]) – Duration in seconds of mask. Mathing to sound duration if None.>>> s = Sound.from_array([1, 1, 1, 1, 1], 1) >>> (LinearFadeIn().apply(s) ... == Sound.from_array([0.0, 0.25, 0.5, 0.75, 1.0], 1)) True >>> (LinearFadeIn(duration=3).apply(s) ... == Sound.from_array([0.0, 0.5, 1.0, 1.0, 1.0], 1)) True
-
class
gensound.effect.
LinearFadeOut
(duration: typing.Union[float, NoneType] = None) → None[source]¶ Bases:
gensound.effect.MaskEndEffect
Linear fade-out effect
Parameters: duration ( Optional
[float
]) – Duration in seconds of mask. Mathing to sound duration if None.>>> s = Sound.from_array([1, 1, 1, 1, 1], 1) >>> (LinearFadeOut().apply(s) ... == Sound.from_array([1.0, 0.75, 0.5, 0.25, 0.0], 1)) True >>> (LinearFadeOut(duration=3).apply(s) ... == Sound.from_array([1.0, 1.0, 1.0, 0.5, 0.0], 1)) True
-
class
gensound.effect.
LowPassFilter
(freq: float) → None[source]¶ Bases:
gensound.effect.Effect
Low pass filter
Parameters: freq ( float
) – A threshold frequency.
-
class
gensound.effect.
HighPassFilter
(freq: float) → None[source]¶ Bases:
gensound.effect.Effect
High pass filter
Parameters: freq ( float
) – A threshold frequency.
-
class
gensound.effect.
Resampling
(samplerate: float, kind: str = 'cubic') → None[source]¶ Bases:
gensound.effect.Effect
Resampling effect
Parameters: Change sampling rate without changes sound duration.
If the sampling rate of passed sound is same as target sampling rate, will return the same instance without re-sampling process.
This example does resampling from 44100 Hz to 88200 Hz.
>>> original = Sound.from_sinwave(440, duration=1, samplerate=44100) >>> original.samplerate 44100 >>> abs(original.duration - 1) < 0.01 True
>>> resampled = Resampling(88200).apply(original) >>> resampled.samplerate 88200 >>> abs(resampled.duration - 1) < 0.01 True
-
class
gensound.effect.
ChangeSpeed
(speed_rate: float, kind: str = 'cubic') → None[source]¶ Bases:
gensound.effect.Effect
Change sound speed effect
Parameters: Change sound duration without changes sampling rate.
>>> original = Sound.from_sinwave(440, duration=1, smooth_end=False) >>> original.duration == 1.0 True
This example changes duration from 1sec to 2sec.
>>> slow = ChangeSpeed(2).apply(original) >>> slow.duration == 0.5 True
And, changes duration to 0.5sec.
>>> fast = ChangeSpeed(0.5).apply(original) >>> fast.duration == 2.0 True
Automatically use ReversePlay if speed_rate was lower than 0. >>> ChangeSpeed(-1).apply(original) == ReversePlay().apply(original) True
Sampling rate will not be changed.
>>> original.samplerate == slow.samplerate True >>> original.samplerate == fast.samplerate True
-
class
gensound.effect.
ChangeVolume
(new_volume: float) → None[source]¶ Bases:
gensound.effect.Effect
Change volume effect
Parameters: new_volume ( float
) – New target volume.Raises: InvalidVolumeError – Volume was lower than 0 or higher than 1. This volume means the maximum value of the wave. Please be careful that is not gain.
>>> sound = Sound.from_sinwave(440, volume=1.0)
>>> 0.999 <= sound.data.max() <= 1.0 True >>> -0.999 >= sound.data.min() >= -1.0 True
>>> half = ChangeVolume(0.5).apply(sound) >>> 0.499 <= half.volume <= 0.501 True
This effect will return the same instance if given sound had the same volume as the target volume.
-
class
gensound.effect.
ReversePlay
[source]¶ Bases:
gensound.effect.Effect
Reverse play effect
-
class
gensound.effect.
Trim
(start: typing.Union[float, NoneType] = None, end: typing.Union[float, NoneType] = None) → None[source]¶ Bases:
gensound.effect.Effect
Trim sound
Parameters: Raises: InvalidDurationError – If start was same or greater than end.
This is alias of
Sound.__getitem__
.>>> sound = Sound.from_sinwave(440)
>>> Trim(end=0.5).apply(sound) == sound[:0.5] True >>> Trim(start=0.5).apply(sound) == sound[0.5:] True >>> Trim(start=0.3, end=0.7).apply(sound) == sound[0.3: 0.7] True