striped_storage¶
This module contains the implementation of storage of audio for recording and playback.
- backlooper.striped_storage.KeyOffset¶
KeyOffsetis 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_memoryis used.alias of
Tuple[str,int]
- class backlooper.striped_storage.StripedStorage(identifier: str, stripe_size: int = 10000, channels: int = 2)¶
Bases:
objectStripedStoragestores 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.arrayof size (stripe_size,channels),key_1:
np.arrayof size (stripe_size,channels),key_2:
np.arrayof size (stripe_size,channels),…
Data in
StripedStoragecan 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
lengthdatapoints starting at indexstart_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_storestarting at indexstart_index. Ifoverwriteis set, existing data is overwritten. Ifoverwriteis not set,array_to_storeis added to the existing data.