Skip to main content

A Velvet-Noise Decorrelator for audio

Project description

VNDecorrelate

VersionPyPITests

A Velvet-Noise Decorrelator for audio.

Decorrelation refers to the process of transforming an audio source signal into multiple output signals with different waveforms from each other, but with the same sound as the source signal [1].

In music production, decorrelation is typically applied to the left and right audio channels, creating the perception of stereo width and space. This, however, may come at the cost of potential coloration or transient smearing artifacts.

Velvet-Noise Decorrelation (VND) attempts to minimize these artifacts as well as computation cost while reducing the correlation of the outputs as much as possible [2].

Velvet Noise

Velvet Noise is a sparse noise sequence generated from randomly time-shifted impulses with a random value of either -1 or 1 [2]:

Basic Velvet Noise

To reduce transient smearing and frequency coloration you can apply a segmented decay envelope [2]:

Segmented Decaying Velvet Noise

As well as logarithmically distributing the impulses towards the start of the sequence [2]:

Segmented Decaying Log Distributed Velvet Noise

Quick Start

First install the package into your environment: pip install vndecorrelate

Then load an audio file.

import scipy.io.wavfile as wavfile
from vndecorrelate.decorrelation import *

fs, input_signal = wavfile.read("audio/viola.wav")

Then you can simply use the VelvetNoise class:

velvet_noise = VelvetNoise(
    duration_seconds=0.03,
    num_impulses=30,
)
output_signal = velvet_noise.decorrelate(input_signal)

Or:

# manually generate the velvet noise as numpy NDArrays
velvet_noise = generate_velvet_noise(
    duration_seconds=0.03,
    num_impulses=30,
)
# numerically equivalent to VelvetNoise.convolve
output_signal = convolve_velvet_noise(input_signal, velvet_noise)

Or you can create a chain of signal processors:

chain = (
    SignalChain(sample_rate_hz=fs)
    .velvet_noise(
        duration_seconds=0.03,
        num_impulses=30,
        log_distribution_strength=1.0,
        seed=1,
    )
    .haas_effect(
        delay_time_seconds=0.02,
        delayed_channel=1, # Right Channel
        mode='LR',
    )
)
# SignalChain is lazy, so instatiation of its signal processors happens here
output_signal = chain(input_signal)

To listen back to the processed audio, simply save to a wav file locally.

wavfile.write('audio/viola_out.wav', fs, output_signal)

Optimization

optimization.py contains functions for optimizing VelvetNoise or HaasEffect for maximizing stereo seperation while maintaining polar sample symmetry and mono compatiblilty.

optimize_velvet_noise optimizes the concentration of impulses towards the start of the filter: $\kappa \in [0.0, 1.0]$, referred to as log_distribution_strength.

optimize_haas_delay optimizes the delay_time_seconds parameter: $\tau \in [0.0, \text{max\_delay\_seconds}]$

symmetry_aware_objective takes the input signal and converts it to polar samples to compute the scalar objective function defined by:

$f(\alpha) = E_w[\theta^2] - \lambda_1(E_w[\theta])^2 - \lambda_2(E_w[\theta^3])^2 - \lambda_3r^2 - \lambda_4(max|{\theta}| - \phi)^2$

where $\alpha$ is the input scalar to optimize, each $E_w[\theta^n]$ is a moment of the polar sample distribution: $E_w[\theta^2]$ is the weighted angular variance, $(E_w[\theta])^2$ is the weighted mean (centroid), and $(E_w[\theta^3])^2$ is the skewness. $r$ is the correlation between the input left and right channels, $\phi$ is the angle_limit parameter, and each $\lambda_n$ is a penalty weight.

Sample runs of VelvetNoise.decorrelate with unoptimized and optimized filters can be compared by their polar sample plots generated from plot_polar_sample:

Unoptimized VN Vectorscope VN Optimized Vectorscope

Visualization

To provide further visualization of the effects decorrelation plot_correlogram is provided. Short windows of typically ~20ms are taken from two signals to calculate normalized cross-correlation values at various lag distances. sine_sweep can be used to generate a test signal that can be compared before and after applying a velvet noise decorrelation. Sine Sweep Signal We can use the auto correlogram as a baseline: Sine Sweep Auto Correlogram Plot the cross correlogram after filtering each channel with velvet noise: Velvet Noise Filtered Sine Sweep Cross Correlogram And compare to the behavior of filtering with white noise: White Noise Filtered Sine Sweep Cross Correlogram

References

[1] “What is ‘Decorrelation’? | Sweetwater”. https://www.sweetwater.com/insync/decorrelation/ (accessed Aug. 10, 2020).

[2] “Velvet-Noise Decorrelator”. http://www.dafx17.eca.ed.ac.uk/papers/DAFx17_paper_96.pdf (accessed Aug. 04, 2020).

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

vndecorrelate-1.0.0.tar.gz (24.2 kB view details)

Uploaded Source

Built Distribution

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

vndecorrelate-1.0.0-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file vndecorrelate-1.0.0.tar.gz.

File metadata

  • Download URL: vndecorrelate-1.0.0.tar.gz
  • Upload date:
  • Size: 24.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vndecorrelate-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cdd94fbb89da49e5816fad6b15d4abdaff061032f07728b753feb468262b2e41
MD5 2ba83b9ded3daad342a820eb27b79460
BLAKE2b-256 a8d7540051d66440b5130f705e2fd96678aa7523a6f199c57255d4cd791415d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for vndecorrelate-1.0.0.tar.gz:

Publisher: release.yaml on ckonst/VNDecorrelate

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

File details

Details for the file vndecorrelate-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: vndecorrelate-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vndecorrelate-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 69e2a509cc671335f77c7d7c57ef5edf376e6dfe6ba25d8d35b2d81546270b84
MD5 f4edfdf83d7b97abe99ba711df1f2b3c
BLAKE2b-256 9eeb621831d6ca17a240005123be921a65f021b61a13f5da0abaa238c00ba85c

See more details on using hashes here.

Provenance

The following attestation bundles were made for vndecorrelate-1.0.0-py3-none-any.whl:

Publisher: release.yaml on ckonst/VNDecorrelate

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