Skip to main content

Python: Buffer audio samples into fixed-sized blocks, with overlap

This small utility package encapsulates a single-consumer, single-producer ringbuffer.

  • Populate the buffer with arbitrary-length arrays
  • Query the buffer, and it returns blocks of a specified fixed length, optionally with overlap between successive blocks

It is designed primarily for applying the short-time Fourier transform (STFT) to successive blocks of an input audio stream (see below for example).

It is safe for usage in real-time audio applications, as no memory allocation or system I/O is done within the extend method as long as auto_resize=False is specified when initialising.

Usage

To do block-sized buffering with overlap in conjunction with sounddevice:

import sounddevice as sd
import numpy as np
import blockbuffer

block_size = 1024
hop_size = 128

bb = blockbuffer.BlockBuffer(block_size=block_size,
                             hop_size=hop_size,
                             num_channels=2)

def input_callback(data, num_frames, time, status):
    global bb
    bb.extend(data)
    for block in bb:
        block_windowed = block.T * np.hanning(block_size)
        block_spectrum = np.fft.rfft(block_windowed)

stream = sd.InputStream(callback=input_callback, channels=1)
stream.start()

Source code

Source code is available on GitHub.

Metadata

Release files for blockbuffer 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for blockbuffer 0.0.4
File Size Uploaded Provenance Actions
blockbuffer-0.0.4.tar.gz 4.9 kB Without provenance Details for blockbuffer-0.0.4.tar.gz

Release files / blockbuffer-0.0.4.tar.gz

Download URL blockbuffer-0.0.4.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
fd7560a692f44900bfabc1db9fef6acabfcbe3f5a37e83f8c26ede956e35888b
BLAKE2b-256 checksum
How to use checksums
71c5dfe0b6018a41124024383f4c2a287f02508f235cc91bfa2ac16648d89383
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.7

Security for blockbuffer 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.4 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page