Skip to content

Reduce RTL-SDR buffer length#383

Merged
argilo merged 1 commit into
masterfrom
rtlsdr-buffer
Mar 26, 2025
Merged

Reduce RTL-SDR buffer length#383
argilo merged 1 commit into
masterfrom
rtlsdr-buffer

Conversation

@argilo
Copy link
Copy Markdown
Collaborator

@argilo argilo commented Mar 26, 2025

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).

@argilo argilo merged commit a54643c into master Mar 26, 2025
@argilo argilo deleted the rtlsdr-buffer branch March 26, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant