Filters#

A Filter is used with Player.add_filter() to modify the playback of a Track.

class mafic.Filter(*, equalizer=None, karaoke=None, timescale=None, tremolo=None, vibrato=None, rotation=None, distortion=None, channel_mix=None, low_pass=None, volume=None)#

Bases: object

Represents a filter which can be applied to audio.

x | y

Merges two filters together, favouring attributes from y.

x |= y

Merges two filters together, favouring attributes from x, assigning to x.

x & y

Merges two filters together, favouring attributes from x.

x &= y

Merges two filters together, favouring attributes from y, assigning to x.

Changed in version 2.1: equalizer now accepts a list of any of the following:

equalizer#

The equalizer to use.

Type:

Optional[Equalizer]

karaoke#

The karaoke filter to use.

Type:

Optional[Karaoke]

timescale#

The timescale filter to use.

Type:

Optional[Timescale]

tremolo#

The tremolo filter to use.

Type:

Optional[Tremolo]

vibrato#

The vibrato filter to use.

Type:

Optional[Vibrato]

rotation#

The rotation filter to use.

Type:

Optional[Rotation]

distortion#

The distortion filter to use.

Type:

Optional[Distortion]

channel_mix#

The channel mix filter to use.

Type:

Optional[ChannelMix]

low_pass#

The low pass filter to use.

Type:

Optional[LowPass]

volume#

The volume to use.

Type:

Optional[float]

class mafic.ChannelMix(left_to_left=None, left_to_right=None, right_to_left=None, right_to_right=None)#

Bases: object

Represents a filter which can be used to mix the audio channels.

Setting all of these to 0.5 will make the audio mono.

left_to_left#

The amount of the left channel to mix into the left channel. This defaults to 1.0.

Type:

Optional[float]

left_to_right#

The amount of the left channel to mix into the right channel. This defaults to 0.0.

Type:

Optional[float]

right_to_left#

The amount of the right channel to mix into the left channel. This defaults to 0.0.

Type:

Optional[float]

right_to_right#

The amount of the right channel to mix into the right channel. This defaults to 1.0.

Type:

Optional[float]

class mafic.Distortion(sin_offset=None, sin_scale=None, cos_offset=None, cos_scale=None, tan_offset=None, tan_scale=None, offset=None, scale=None)#

Bases: object

Represents a filter which can be used to add a distortion effect to audio.

This applies sine, cosine and tangent distortion to the audio. The formula that is used:

sample_sin = sin_offset + math.sin(sample * sin_scale);
sample_cos = cos_offset + math.cos(sample * cos_scale);
sample_tan = tan_offset + math.tan(sample * tan_scale);
sample = max(
    -1,
    min(
        1,
        offset +
        scale * sample_sin * sample_cos * sample_tan
    )
)
sin_offset#

The offset of the sine distortion. This defaults to 0.0.

Type:

Optional[float]

sin_scale#

The scale of the sine distortion. This defaults to 1.0.

Type:

Optional[float]

cos_offset#

The offset of the cosine distortion. This defaults to 0.0.

Type:

Optional[float]

cos_scale#

The scale of the cosine distortion. This defaults to 1.0.

Type:

Optional[float]

tan_offset#

The offset of the tangent distortion. This defaults to 0.0.

Type:

Optional[float]

tan_scale#

The scale of the tangent distortion. This defaults to 1.0.

Type:

Optional[float]

offset#

The offset of the distortion. This defaults to 0.0.

Type:

Optional[float]

scale#

The scale of the distortion. This defaults to 1.0.

Type:

Optional[float]

Attributes
class mafic.EQBand(band, gain)#

Bases: object

Represents an equaliser band.

band#

The band to set the gain of. Must be between 0 and 14.

Type:

int

gain#

The gain to set the band to. Must be between -0.25 and 1.0.

Type:

float

Attributes
class mafic.Equalizer(bands)#

Bases: object

Represents an equaliser.

Changed in version 2.1: Added support for lists of tuple[int, float] and float to the constructor.

bands#

The bands to set the gains of.

Type:

list[EQBand]

class mafic.Karaoke(level=None, mono_level=None, filter_band=None, filter_width=None)#

Bases: object

Represents a filter which can be used to eliminate part of a band.

This usually targets vocals, to sound like karaoke music.

level#

The level of the karaoke effect. Must be between 0.0 and 1.0. Where 0.0 is no effect and 1.0 is full effect. This defaults to 1.0.

Type:

Optional[float]

mono_level#

The level of the mono effect. Must be between 0.0 and 1.0. Where 0.0 is no effect and 1.0 is full effect. This defaults to 1.0.

Type:

Optional[float]

filter_band#

The frequency of the filter band in Hz. This defaults to 220.0.

Type:

Optional[float]

filter_width#

The width of the filter band. This defaults to 100.0.

Type:

Optional[float]

Attributes
class mafic.LowPass(smoothing=None)#

Bases: object

Represents a filter which can be used to apply a low pass filter to audio.

High frequencies are suppressed, while low frequencies are passed through.

smoothing#

The smoothing of the low pass filter. This defaults to 0.0.

Type:

Optional[float]

Attributes
class mafic.Rotation(rotation_hz=None)#

Bases: object

Represents a filter which can be used to add a rotating effect to audio.

An example can be with “8D audio” (without the reverb).

rotation_hz#

The rotation speed in Hz. Must be at least 0.0. 0.2 is similar to the example above.

Type:

Optional[float]

Attributes
class mafic.Timescale(speed=None, pitch=None, rate=None)#

Bases: object

Represents a filter which is used to change the speed, pitch and rate of audio.

speed#

The speed of the audio. Must be at least 0.0. 1.0 is normal speed.

Type:

Optional[float]

pitch#

The pitch of the audio. Must be at least 0.0. 1.0 is normal pitch.

Type:

Optional[float]

rate#

The rate of the audio. Must be at least 0.0. 1.0 is normal rate.

Type:

Optional[float]

Attributes
class mafic.Tremolo(frequency=None, depth=None)#

Bases: object

Represents a filter which can be used to add a tremolo effect to audio.

Tremolo oscillates the volume of the audio.

frequency#

The frequency of the tremolo effect. Must be at least 0.0. This defaults to 2.0.

Type:

Optional[float]

depth#

The depth of the tremolo effect. Must be between 0.0 and 1.0. Where 0.0 is no effect and 1.0 is full effect. This defaults to 0.5.

Type:

Optional[float]

Attributes
class mafic.Vibrato(frequency=None, depth=None)#

Bases: object

Represents a filter which can be used to add a vibrato effect to audio.

Vibrato oscillates the pitch of the audio.

frequency#

The frequency of the vibrato effect. Must be at least 0.0. This defaults to 2.0.

Type:

Optional[float]

depth#

The depth of the vibrato effect. Must be between 0.0 and 1.0. Where 0.0 is no effect and 1.0 is full effect. This defaults to 0.5.

Type:

Optional[float]