striped_storage

This module contains the implementation of storage of audio for recording and playback.

backlooper.striped_storage.KeyOffset

KeyOffset is a pointer towards audio data in the striped storage. It contains of two parts:

  • The key of the striped storage

  • The offset in the striped storage

To allow multiple processes to read and write the same storage, multiprocessing.shared_memory is used.

alias of Tuple[str, int]

class backlooper.striped_storage.StripedStorage(identifier: str, stripe_size: int = 10000, channels: int = 2)

Bases: object

StripedStorage stores audio data and can be thought of as a tape storage with a start and end. In order to prevent having to allocate a big amount of memory, the data is partitioned in chunks, called “stripes”.

The underlying data has a dictionary structure with the following keys and values:

  • key_0: np.array of size (stripe_size, channels),

  • key_1: np.array of size (stripe_size, channels),

  • key_2: np.array of size (stripe_size, channels),

Data in StripedStorage can be referenced in two ways:

  • Either by an absolute index, starting from zero (the first datapoint),

  • Or by a KeyOffset, which includes the stripe key and offset within the stripe.

channels: int = 2

Number of channels per data point (stereo).

identifier: str

Unique identifier of the shared memory which stores the audio data. Different processes can use this identifier to access the shared memory.

read(start_index: int, length: int) array

Reads length datapoints starting at index start_index.

stripe_size: int = 10000

Size in samples of a single stripe.

write(start_index: int, array_to_store: array, overwrite: bool = True)

Writes array array_to_store starting at index start_index. If overwrite is set, existing data is overwritten. If overwrite is not set, array_to_store is added to the existing data.