I am playing a sine wave from a Rpi3 via pure userspace ALSA to the hw device of a USB sound card (using the official PCM example, no sound servers installed).

But the wave never stays perfect, after enough time there are audible errors (after 1 to 60 minutes, also tested on osciloscope). The strange thing is that ALSA does NOT report the errors as xruns.

I am running it with chrt -r 1 after setting scaling governor to performance. That way it should have enough priority to win over normal processes, but not so much that it would prevent hardware interrupts (I need USB to work).

I tried the realtime kernel and also RealtimePI, but they have WORSE performance than the standard kernel (first crackling after ~1.5 minutes). In top I see the USB interrupts consume as much CPU as the ALSA process. I also tried the OSADL FIQ workaround with no difference, even though the full fix is already in the RT kernel.

On normal kernel I let it play into xoscope running FFT, and after ~1 hour it detects more frequencies than the single sine wave being played.

Since ALSA does not notice the errors nor report them as xruns, I think the ALSA process is not even getting CPU time. I suspect it is being preempted by the USB interrupts, because I run a clean install of the Raspbian Lite, almost nothing else should be running.

But I do use WiFi and serial console on UART to communicate with the Pi, could they be possible causes?

Can the RPi play perfect sine wave through USB for days, or is the hardware just not made for such detailed playback? Do I have a chance with non-RT kernel if nothing much else would run on the Pi, or is RT the only way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.