Skip to main content

Priority queue with a sane API

Project description

Julius, fast PyTorch based resampling for audio and 1D signals

tests badge

This is an implementation of the sinc resample algorithm by Julius O. Smith. It is the same algorithm than the one used in resampy but to run efficiently on GPU it is limited to fractional changes of the sample rate. It will be fast if the old and new sample rate are small after dividing them by their GCD. For instance going from a sample rate of 2000 to 3000 (2, 3 after removing the GCD) will be extremely fast, while going from 20001 to 30001 will not.

Julius is faster than resampy even on CPU, and when running on GPU it makes resampling a completely negligible part of your pipeline. Finally, Julius is differentiable and can thus be integrated in an end-to-end training pipeline.

Representation of the convolutions filters used for the efficient resampling.

Installation

julius requires python 3.6. To install:

pip3 install julius

Usage

import julius
julius.resample_frac(signal, old_sr, new_sr, zeros=24, rollof=1)
  • signal is a multi dimensional PyTorch tensor, with the last dimension representing time.
  • resample_frac change the sample rate from old_sr to new_sr. The GCD is automatically removed for you.
  • zeros is the number of zero crossing to keep in the sinc filters, higher values can be more accurate but also slower. Default value is probably fine.
  • If rolloff < 1, the cutoff frequency of the low pass filter used before downsampling will be half the target sample_rate times this amount. This can potentially reduce aliasing if you notice such an issue. When doing upsampling, this is ignored.

If signal is a CUDA Tensor, then everything will run on GPU :)

Benchmark

On my laptop, the time taken to process a tensor of size (256, 40000) (roughly 256 seconds of audio at 44.1 kHz) is (on CPU):

Old sr New sr Julius (sec) Resampy (sec)
2 1 0.4 2.0
1 2 0.6 4.8
4 5 0.13 2.5
10 11 0.08 2.45
20001 30001 2.4 1.5

Except when new_sr / old_sr does not simplify to a small irreductible fraction, julius is faster even on CPU than resampy. When running on GPU, julius makes resampling take a negligible time of the order of a few milliseconds.

Running tests

Clone this repository, then

pip3 install .[test]'
python3 tests.py

License

julius is released 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

julius-0.1.1.tar.gz (5.7 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: julius-0.1.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for julius-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2c28328b145ee690cf1163874afc4c2745d55b83c67e9f662c7d1a6d53ce5f97
MD5 e0e1202ad072d20bc7f87b66a6b82ad6
BLAKE2b-256 bb76fc43a308aaf65568c5ffff9a5994da18549aba3b29ec01464d800c252250

See more details on using hashes here.

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