Reading samples from stream #17
-
When I want to read a number of samples from a stream I convert the number of samples to the corresponding number of bytes. Then I request them from the stream. If the stream does not have the number of bytes available it will return the available bytes and let me know how many were available. My questions are:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In general: The API operates with bytes and not samples! When reading data it is recommended to use a multiple of the sample size * channels to make sure that full frames are received. In any case the result of the readBytes() should be used to determine the number of effectively returned bytes. But in most cases this corresponds to the requested number of bytes since I am using blocking reads in most of the cases. Since the bits per sample can be 16 or 32, good values would be 1024, 512, 256, 128 and 64 bytes since this will return full samples both for mono and stereo. The same applies when you have the possibility to define an buffer size. So to answer your question: I expect that you would only get an odd number of bytes when you explicitly requested it (which should be avoided) and it will never provide more data then requested. Do you have a specific class in mind or did you see any other behavior ? ps. This project is only here to configure the DAC (or ADC) and no audio data is involved: this is the responsibility of the I2S API. |
Beta Was this translation helpful? Give feedback.
In general: The API operates with bytes and not samples!
When reading data it is recommended to use a multiple of the sample size * channels to make sure that full frames are received. In any case the result of the readBytes() should be used to determine the number of effectively returned bytes. But in most cases this corresponds to the requested number of bytes since I am using blocking reads in most of the cases.
Since the bits per sample can be 16 or 32, good values would be 1024, 512, 256, 128 and 64 bytes since this will return full samples both for mono and stereo. The same applies when you have the possibility to define an buffer size.
So to answer your question: I expect that you …