Reduce RTL-SDR buffer length#383
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently nrsc5 receives samples from the RTL-SDR in batches of 512 kB (= 262144 I/Q samples = 176 milliseconds). This adds a corresponding amount of latency (inconvenient for #380), and is somewhat problematic for elastic buffering (#343) since it forces audio output to occur in relatively large 176-ms bursts.
The RTL-SDR header file notes that the buffer length must be a multiple of 512 bytes, and should be a multiple of 16384 bytes. While testing the nrsc5 API, I found that reading samples in very small batches causes extra CPU overhead, but the effect becomes negligible once the batch size reaches 32768 bytes (= 16384 I/Q samples = 11 milliseconds). This seems like a reasonable buffer length to use.
To maintain the total amount of buffer space, I increased the number of buffers to 120. This gives 3932160 bytes (= 1.321 seconds) of buffer space, which is a slight reduction from the current 4194304 bytes (= 1.409 seconds), but matches the default value used by the RTL-SDR library (15 buffers of 262144 bytes each, which was presumably chosen so that four RTL-SDRs can be used without consuming the entire 16 MB of available USBFS buffer space, the default on Linux).