cpal
cpal copied to clipboard
Add (more clear?) information to the docs on how channels work in terms of streams.
This is something that I've been struggling with because I'm used to working with audio streams broken by channels and sets of samples for each frame that represent a sample for each channel. With CPAL though, all that you get is a callback that effectively gives an array for individual samples devoid of any notion of channels save the number you have from the StreamConfig you used. At time of writing, I'm still not quite sure how to do multichannel audio. My best guess is that channel samples are interleaved but even if that's correct, the fact that I had to scour the docs and came back absolutely no wiser to this than when I went in is a major indication that this needs to be clarified in the docs if not for the audio pros who could assume how it works, than for the people like me who know a bit about low-level audio but are trying to learn to use an even more bare-metal library like this one.
The audio samples are interleaved and splitting them with that works fine but I agree, there should be something about that in the docs. When searching for that, the only place with some info around splitting channels I could find was a single question on Reddit.
Indeed, I was also desperate searching for this information, and couldn't find anything. In general it would be great to add some more details to the documentation of build_output_stream
explaining the semantics of the callback etc.
What I couldn't figure out so far: Is the interleaved data in stereo expecting samples in the order "R L R L ..." or "L R L R ..."? Or does this even depend on the device, and some logic is needed to decide which order is right?
Related issues:
- https://github.com/RustAudio/cpal/issues/427
- https://github.com/RustAudio/cpal/issues/246
@bluenote10 I've tested the order twice on different machines with different sound systems and OS's and for both, the channel order is LRLRL... I suspect that this is ultimately dependent on the device but I'd have to assume that there's some unspoken agreement between sound system makers and OS devs that the channels go from left to right but then again, what do I know. I've assumed for some basic stuff that it's interleaved left to right and its always worked out so 🤷
Same experience here, every time I had an interleaved audio signal somewhere it was always LRLR. No matter the OS.
The stride https://docs.rs/stride/latest/stride/ crate can help with this