interleaveWithDynamicWeights¶
- maelzel.distribute.interleaveWithDynamicWeights(streamSizes, weightBpfs)[source]¶
Interleave items of multiple streams based on dynamic weights
- Parameters:
streamSizes (
list
[int
]) – the sizes of each streamweightBpfs (
list
[Callable
[[float
],float
]]) – for each stream, a bpf indicating the weighting. Each bpf is defined between 0-1 (for both x and y coords)
- Returns:
int, indexInStream: int)
- Return type:
a list of tuples of the form (streamIndex
Example
>>> import bpf4 >>> A = "AAAAAAAAAAAAAAAAAAA" >>> B = "BBBBBBBBBBBBB" >>> C = "CCCCC" >>> D = "DDD"
>>> streams = (A, B, C, D) >>> streamSizes = (len(A), len(B), len(C), len(D)) >>> bpfs = (bpf4.linear(0, 1, 1, 1), # bpfs must be defined within the unity ... bpf4.halfcos(0, 0, 0.5, 1, 1, 0), ... bpf4.linear(0, 1, 1, 0), ... bpf4.expon(0, 0, 1, 1, exp=3) ... ) >>> distributedItems = interleaveWithDynamicWeights(streamSizes, bpfs) >>> for stream, idx in distributedItems: ... print(streams[stream][idx], end=' ') ACAACABABCABABABCABBABABABDBACABABADAADA