Skip to main content

Python bindings for libsamplerate based on CFFI and NumPy

Project description

This is a wrapper around Erik de Castro Lopo’s libsamplerate (aka Secret Rabbit Code) for high-quality sample rate conversion.

It implements all three APIs available in libsamplerate:

  • Simple API: for resampling a large chunk of data with a single library call

  • Full API: for obtaining the resampled signal from successive chunks of data

  • Callback API: like Full API, but input samples are provided by a callback function

Library calls to libsamplerate are performed using CFFI.

Installation

$ pip install samplerate

Binaries of libsamplerate for macOS and Windows (32 and 64 bit) are included and used if not present on the system.

Usage

import numpy as np
import samplerate

# Synthesize data
fs = 1000.
t = np.arange(fs * 2) / fs
input_data = np.sin(2 * np.pi * 5 * t)

# Simple API
ratio = 1.5
converter = 'sinc_best'  # or 'sinc_fastest', ...
output_data_simple = samplerate.resample(input_data, ratio, converter)

# Full API
resampler = samplerate.Resampler(converter, channels=1)
output_data_full = resampler.process(input_data, ratio, end_of_input=True)

# The result is the same for both APIs.
assert np.allclose(output_data_simple, output_data_full)

# See `samplerate.CallbackResampler` for the Callback API, or
# `examples/play_modulation.py` for an example.

See samplerate.resample, samplerate.Resampler, and samplerate.CallbackResampler in the API documentation for details.

See also

  • scikits.samplerate implements only the Simple API and uses Cython for extern calls. The resample function of scikits.samplerate and this package share the same function signature for compatiblity.

  • resampy: sample rate conversion in Python + Cython.

License

This project is licensed under the MIT license.

As of version 0.1.9, libsamplerate is licensed under the 2-clause BSD 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

samplerate-0.1.0.tar.gz (4.0 MB view details)

Uploaded Source

Built Distribution

samplerate-0.1.0-py2.py3-none-any.whl (4.0 MB view details)

Uploaded Python 2 Python 3

File details

Details for the file samplerate-0.1.0.tar.gz.

File metadata

  • Download URL: samplerate-0.1.0.tar.gz
  • Upload date:
  • Size: 4.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for samplerate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 75ef725e6cd9c4545569caf4c47147beab7b53b2c36e5122e8c285d348f88847
MD5 8309a43d9c362da4bc38eac979ee8857
BLAKE2b-256 da9c6a13fbc59b1ceaef194a53d3aeafa983057133fb13660c423854184eafa7

See more details on using hashes here.

File details

Details for the file samplerate-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for samplerate-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f55e5c9d0a8ba3c82a53b7d9c34a2d145439c61166a7f310efaec88f2781b8f8
MD5 79be4b973d23617c602b54e7d35d10af
BLAKE2b-256 0c3c4c1aa376332d18e708dcc3289e4dbdd2c508bcac1b8eb1b35b73092fa00f

See more details on using hashes here.

Supported by

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