music.horizontal_stack

music.horizontal_stack(*arrays)[source]

Join sounds end to end, mono or stereo.

This function takes multiple arrays as input and stacks them horizontally. If any of the input arrays are bidimensional (have two dimensions), the function ensures that they are treated as stereo data by duplicating mono channels to both left and right channels.

Parameters:
*arraysarray_like

The arrays to be stacked horizontally. Can be one-dimensional (mono) or two-dimensional (stereo).

Returns:
ndarray

A numpy array representing the horizontal stack of input arrays. No arrays stack to no samples.

Parameters:

arrays (ArrayLike)

Return type:

NDArray[float64]

Notes

The article’s concatenation, eq:concatenacao [1]: the samples of each sound follow the last of the one before, so the result lasts the sum of their durations. A sound that does not start and end in silence joins the next with a step, heard as a click; shape each with adsr() or fade() first.

References

[1]

Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)

Examples

>>> mono_array1 = np.array([0.1, 0.2, 0.3])
>>> mono_array2 = np.array([0.4, 0.5, 0.6])
>>> stereo_array = np.array([[1, 2, 3], [4, 5, 6]])
>>> stacked_array = horizontal_stack(mono_array1, stereo_array,
...                                  mono_array2)
>>> stacked_array.shape
(2, 9)