Skip to main content

Basic audio functions for VapourSynth

Project description

VapourSynth ATools

This package contains the VS-AudioTools VapourSynth plugin.

Installation

pip install vapoursynth-atools

Building from source

uv build --package vapoursynth-atools

Detailed parameter information from the parent project follows.


VS-AudioTools

Some basic audio functions for VapourSynth.

Convert
Crossfade
Delay
FadeIn
FadeOut
FindPeak
Mix
Normalize
SineTone

Overflow handling

Build from source
License

Convert

Convert the sample type.

atools.Convert(clip: vs.AudioNode,
               sample_type: str,
               overflow: str = 'error',
               overflow_log: str = 'once'
               ) -> vs.AudioNode

clip - input audio clip

sample_type - sample type of the output clip

    'i16' - integer 16-bit
    'i24' - integer 24-bit
    'i32' - integer 32-bit
    'f32' - float   32-bit

overflow - sample overflow handling; default: 'error' - see explanation below

overflow_log - sample overflow logging; default: 'once' - see explanation below

Crossfade

Crossfade two audio clips. The output clip has the length: len(clip1) + len(clip2) - crossfade_samples

atools.Crossfade(clip1: vs.AudioNode,
                 clip2: vs.AudioNode,
                 samples: int = 0,
                 seconds: float = 0.0,
                 type: str = 'cubic',
                 overflow: str = 'error',
                 overflow_log: str = 'once'
                 ) -> vs.AudioNode

clip1 - first audio clip

clip2 - second audio clip (same format as clip1)

samples - crossfade length in samples

seconds - crossfade length in seconds

type - fade transition type

    'linear' - linear transition
    'cubic'  - cubic transition (Cubic Hermite spline)
    'sine'   - sine transition

overflow - sample overflow handling; default: 'error' - see explanation below

overflow_log - sample overflow logging; default: 'once' - see explanation below

Delay

Delay (or shift) an audio clip. The output length stays the same.
This effect could be also achieved with scripting.

atools.Delay(clip: vs.AudioNode,
             samples: int = 0,
             seconds: float = 0.0,
             channels: list[int] = None,
             overflow: str = 'error',
             overflow_log: str = 'once'
             ) -> vs.AudioNode

clip - input audio clip

samples - delay length in samples

seconds - delay length in seconds

channels - list of channels to delay; default: None (all channels)

overflow - sample overflow handling; default: 'error' - see explanation below

overflow_log - sample overflow logging; default: 'once' - see explanation below

FadeIn

Fade in an audio clip.

atools.FadeIn(clip: vs.AudioNode,
              samples: int = 0,
              seconds: float = 0.0,
              start_sample: int = 0,
              start_second: float = 0.0,
              channels: list[int] = None,
              type: str = 'cubic',
              overflow: str = 'error',
              overflow_log: str = 'once'
              ) -> vs.AudioNode

clip - input audio clip

samples - fade in length in samples

seconds - fade in length in seconds

start_sample - sample to start fading in

start_second - second to start fading in

channels - list of channels to fade in; default: None (all channels)

type - fade transition type

    'linear' - linear transition
    'cubic'  - cubic transition (Cubic Hermite spline)
    'sine'   - sine transition

overflow - sample overflow handling; default: 'error' - see explanation below

overflow_log - sample overflow logging; default: 'once' - see explanation below

FadeOut

Fade out an audio clip.

atools.FadeOut(clip: vs.AudioNode,
               samples: int = 0,
               seconds: float = 0.0,
               end_sample: int = len(clip),
               end_second: float = to_seconds(len(clip)),
               channels: list[int] = None,
               type: str = 'cubic',
               overflow: str = 'error',
               overflow_log: str = 'once'
               ) -> vs.AudioNode

clip - input audio clip

samples - fade out length in samples

seconds - fade out length in seconds

end_sample - sample to end fading out (exclusive!)

end_second - second to end fading out (exclusive!)

channels - list of channels to fade out; default: None (all channels)

type - fade transition type

    'linear' - linear transition
    'cubic'  - cubic transition (Cubic Hermite spline)
    'sine'   - sine transition

overflow - sample overflow handling; default: 'error' - see explanation below

overflow_log - sample overflow logging; default: 'once' - see explanation below

FindPeak

Return the peak value of all audio samples. This function is not an audio filter.

Note: Calling this function will read all audio frames in advance, which is a blocking process and can take a while to complete depending on the audio length.

atools.FindPeak(clip: vs.AudioNode,
                normalize: bool = True,
                channels: list[int] = None
                ) -> float

clip - input audio clip

normalize - if True returns a normalized peak value between 0 and 1,
otherwise returns the exact peak sample value; default: True

channels - list of channels to read; default: None (all channels)

Mix

Mix two audio clips together. Optionally fade in / fade out clip2 respectively clip1 depending on the offset of clip2 and extend_start / extend_end.
This is a convenience function and can also be achieved with existing functions and scripting.

Note: This function is prone to overflowing. Please see the section about how to handle overflows.

atools.Mix(clip1: vs.AudioNode,
           clip2: vs.AudioNode,
           clip2_offset_samples: int = 0,
           clip2_offset_seconds: float = 0.0,
           clip1_gain: float = 1.0,
           clip2_gain: float = 1.0,
           relative_gain: bool = False,
           fadein_samples: int = 0,
           fadein_seconds: float = 0.0,
           fadeout_samples: int = 0,
           fadeout_seconds: float = 0.0,
           fade_type: str = 'cubic',
           extend_start: bool = False,
           extend_end: bool = False,
           channels: list[int] = None,
           overflow: str = 'error',
           overflow_log: str = 'once'
           ) -> vs.AudioNode

clip1 - base input audio clip

clip2 - audio clip to mix into clip1 (same format as clip1)

clip2_offset_samples - sample position (relative to clip1) of where to mix clip2 into clip1; can be negative

clip2_offset_seconds - time in seconds (relative to clip1) of where to mix clip2 into clip1; can be negative

clip1_gain - apply gain to clip1

clip2_gain - apply gain to clip2

relative_gain - if true clip1_gain and clip2_gain are relative values and the absolute gains will add up to 1;
e.g. if clip1_gain is 1 and clip2_gain is 4 then the absolute gain for clip1 will be 0.2 and for clip2 will be 0.8;
this can be used to prevent overflowing, but should not be used if you want to call Mix more than once, because it lowers the overall volume every time you call Mix;
default: False

fadein_samples - fade in length in samples; fade in clip2 if clip2 starts after clip1, otherwise clip1

fadein_seconds - fade in length in seconds; fade in clip2 if clip2 starts after clip1, otherwise clip1

fadeout_samples - fade out length in samples; fade out clip2 if clip2 ends before clip1, otherwise clip1

fadeout_seconds - fade out length in seconds; fade out clip2 if clip2 ends before clip1, otherwise clip1

fade_type - fade transition type

    'linear' - linear transition
    'cubic'  - cubic transition (Cubic Hermite spline)
    'sine'   - sine transition

extend_start - if the start of clip2 is outside of clip1 (negative clip2_offset) you can choose to extend the start of clip1 to match the start of clip2, which increases the output length; default: False

extend_end - if the end of clip2 is outside of clip1 you can choose to extend the end of clip1 to match the end of clip2, which increases the output length; default: False

channels - list of channels of clip2 to mix in; default: None (all channels)

overflow - sample overflow handling; default: 'error' - see explanation below

overflow_log - sample overflow logging; default: 'once' - see explanation below

Normalize

Simple peak normalization.
Applies a gain to the input clip to match the desired normalized peak value.

Note: Calling this function will read all audio frames in advance, which is a blocking process and can take a while to complete depending on the audio length.

atools.Normalize(clip: vs.AudioNode,
                 peak: float = 1.0,
                 lower_only: bool = False,
                 channels: list[int] = None,
                 overflow: str = 'error',
                 overflow_log: str = 'once'
                 ) -> vs.AudioNode

clip - input audio clip

peak - normalized peak value to scale the audio to; default: 1.0

lower_only - only reduce the volume to match the desired peak value; default: False

channels - list of channels to normalize; default: None (all channels)

overflow - sample overflow handling; default: 'error' - see explanation below

overflow_log - sample overflow logging; default: 'once' - see explanation below

SineTone

Create a constant beeping tone clip.

atools.SineTone(clip: vs.AudioNode = None,
                samples: int = 10 * sample_rate
                seconds: float = 10.0,
                sample_rate: int = 44100,
                sample_type: str = 'i16',
                freq: float = 500.0,
                amp: float = 1.0,
                channels: list[int] = [vs.FRONT_LEFT, vs.FRONT_RIGHT],
                overflow: str = 'error',
                overflow_log: str = 'once'
                ) -> vs.AudioNode

clip - use audio format from this clip; values can be overwritten with the parameters below

samples - audio length in samples

seconds - audio length in seconds

sample_rate - sample rate of the output clip

sample_type - sample type of the output clip

    'i16' - integer 16-bit
    'i24' - integer 24-bit
    'i32' - integer 32-bit
    'f32' - float   32-bit

freq - frequency of the sine tone

amp - amplitude of the sine tone

channels - channels for the channel layout; default: [vs.FRONT_LEFT, vs.FRONT_RIGHT]

overflow - sample overflow handling; default: 'error' - see explanation below

overflow_log - sample overflow logging; default: 'once' - see explanation below

Overflow handling

All functions have an 'overflow' parameter that determines how to handle overflows,
and an 'overflow_log' parameter that determines how to log overflows.

overflow - sample overflow handling; default: 'error'

    'error'      - raise an error (default)
    'clip'       - clip overflowing samples (all types)
    'clip_int'   - clip overflowing samples for integer output sample types
                   keep overflowing samples for float output sample types
    'keep_float' - keep overflowing samples for float output sample types
                   raise an error if output sample type is not float

To properly handle overflows the clip should be converted to a float sample type first ('f32'), if not already.

⚠️ Overflowing samples of integer output sample types are always clipped (disruptive), or they raise an error

Use overflow='keep_float' for float output sample types to leave overflowing samples unchanged.
Then call a scaling function like atools.Normalize or std.AudioGain that scales the peak sample value below or to equal 1.0 (see Example)

overflow_log - sample overflow logging; default: 'once'

    'all'  - log all sample overflows (not recommended, this can be a lot)
    'once' - log only the first sample overflow (default)
    'none' - do not log any sample overflows

Note: a summary of all overflowing samples will be logged at the end of each function (if any)

Example

import vapoursynth as vs

# load audio (integer or float sample type)

# e.g. create a new integer sample type clip
audio = vs.core.atools.SineTone(sample_type='i24')

# convert sample type to 32-bit float
audio = vs.core.atools.Convert(audio, sample_type='f32')

# process audio

# make the audio overflow
audio = vs.core.std.AudioGain(audio, 1.2)

# apply FadeIn and FadeOut to the overflowing clip
# keep overflowing samples with 'keep_float'
audio = vs.core.atools.FadeIn(audio, seconds=2.0, overflow='keep_float')
audio = vs.core.atools.FadeOut(audio, seconds=2.0, overflow='keep_float')

# fix overflows

# scale peak to 1.0 with Normalize
audio = vs.core.atools.Normalize(audio)

# convert sample type back to integer if needed
audio = vs.core.atools.Convert(audio, sample_type='i24')

# Note: Normalize and Convert would both raise an error if any overflow would occur
#       on their output samples, since the default value for overflow is 'error'

Dependencies

None

Build from source

Use cmake to configure your preferred build system and run it.
e.g. cmake with Ninja:

cmake -G Ninja -B ./build-ninja -DCMAKE_BUILD_TYPE=Release

ninja -C ./build-ninja

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vapoursynth_atools-0.1.1.tar.gz (56.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

vapoursynth_atools-0.1.1-py3-none-win_amd64.whl (235.1 kB view details)

Uploaded Python 3Windows x86-64

vapoursynth_atools-0.1.1-py3-none-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

vapoursynth_atools-0.1.1-py3-none-musllinux_1_2_aarch64.whl (1.1 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

vapoursynth_atools-0.1.1-py3-none-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl (241.2 kB view details)

Uploaded Python 3manylinux: glibc 2.26+ x86-64manylinux: glibc 2.28+ x86-64

vapoursynth_atools-0.1.1-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (213.6 kB view details)

Uploaded Python 3manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

vapoursynth_atools-0.1.1-py3-none-macosx_13_0_x86_64.whl (104.3 kB view details)

Uploaded Python 3macOS 13.0+ x86-64

vapoursynth_atools-0.1.1-py3-none-macosx_13_0_arm64.whl (91.7 kB view details)

Uploaded Python 3macOS 13.0+ ARM64

File details

Details for the file vapoursynth_atools-0.1.1.tar.gz.

File metadata

  • Download URL: vapoursynth_atools-0.1.1.tar.gz
  • Upload date:
  • Size: 56.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for vapoursynth_atools-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4547538cad479c5d1f104dd1864101970e97f00f636774a70e1784dabfb75619
MD5 95605a6c388fee2374ab67ef6e417996
BLAKE2b-256 fd99c0a07a2ceb01c0ca19afa2ca53b7fa9abc660f4daf0aab1716284db444c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_atools-0.1.1.tar.gz:

Publisher: cd-publish.yml on Jaded-Encoding-Thaumaturgy/vs-wheels

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_atools-0.1.1-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for vapoursynth_atools-0.1.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 323686f1e90e68b51d5f198588a27a0ee607eb8cd120798dd3fdf2eab5247696
MD5 3ab1a8d4429c803b7029072582a02edb
BLAKE2b-256 daca6d166789ba8246b15c9aa03512f76cbce8d00fed19627106f1f7b193aecc

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_atools-0.1.1-py3-none-win_amd64.whl:

Publisher: cd-publish.yml on Jaded-Encoding-Thaumaturgy/vs-wheels

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_atools-0.1.1-py3-none-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_atools-0.1.1-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7a6e30bd9ecd1db2c7d5d30d1cdd8fc8bc892a61914723eb8c1dfdf75bb9e676
MD5 202a64690f930c1bfe35d248725dc59d
BLAKE2b-256 ac7583f96625d0882a29ce39d19eab14f770fc2b35abd7d7cbbb45f97f586e57

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_atools-0.1.1-py3-none-musllinux_1_2_x86_64.whl:

Publisher: cd-publish.yml on Jaded-Encoding-Thaumaturgy/vs-wheels

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_atools-0.1.1-py3-none-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for vapoursynth_atools-0.1.1-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 11bc356a1ba5d0e357efa2bbc2e24e3cf155d1f1cea584e4a776f7ae9d8c75a4
MD5 b74c92a46adbe2748d7bffeed55417fd
BLAKE2b-256 6fa1f654ab7ccc08f486775d05ef87dc4aecac3a4fbe5fc4a5507aac601ccabb

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_atools-0.1.1-py3-none-musllinux_1_2_aarch64.whl:

Publisher: cd-publish.yml on Jaded-Encoding-Thaumaturgy/vs-wheels

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_atools-0.1.1-py3-none-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_atools-0.1.1-py3-none-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c42a43f09c9881d0a2ac26e9bd414426bf302fbf64207d17381d98dd9d20de6c
MD5 4c0f659db8e7697511be1ae2b15bc6ce
BLAKE2b-256 e121f5e136a63930a9a8a39a5f847dcc6027a40d38e197072d6525018ac493ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_atools-0.1.1-py3-none-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl:

Publisher: cd-publish.yml on Jaded-Encoding-Thaumaturgy/vs-wheels

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_atools-0.1.1-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for vapoursynth_atools-0.1.1-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 43e341b43ad51b1c1c65c520708b84534edbacfc4e83cbf3b551d32ed1e2686c
MD5 aea1a7232757af3706afbc50ff4de7af
BLAKE2b-256 ffffb9d9753c74f979eba3374986d81fe06e9c7423f5d7679e11481fab195450

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_atools-0.1.1-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:

Publisher: cd-publish.yml on Jaded-Encoding-Thaumaturgy/vs-wheels

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_atools-0.1.1-py3-none-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_atools-0.1.1-py3-none-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 03ddd68ac1909eafadda1334c53f20a52bfbe446cd967389f881b224f8b393ee
MD5 651a830a13a079e3185965b82c1597cf
BLAKE2b-256 0fc31b7a7a8e78bfe9d03d87aa5bfa5cd0af04825c2ee88cc12016693fd2449a

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_atools-0.1.1-py3-none-macosx_13_0_x86_64.whl:

Publisher: cd-publish.yml on Jaded-Encoding-Thaumaturgy/vs-wheels

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_atools-0.1.1-py3-none-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for vapoursynth_atools-0.1.1-py3-none-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 30db8ae896da64e7c90e890ce6d93e6f5aaa99a63f958ebb295c36b5432997f0
MD5 7d7bdb2b37b0ae83f921a1fdb69b2987
BLAKE2b-256 f1e7f1bf7ead6ec532d88238eff9bdb3692d7f62b94676b1c8eb88675146b4a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_atools-0.1.1-py3-none-macosx_13_0_arm64.whl:

Publisher: cd-publish.yml on Jaded-Encoding-Thaumaturgy/vs-wheels

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page