Linux ALSA "default" device: distortion

It’s hugely welcome to now be able to use ALSA “default” device.

But in practice I’m getting distorted playback. It doesn’t seem to be linked to the hardware, realtime priority or any other factors.

My default device is ALSA dmix (not PulseAudio) fixed at 48000Hz and period_size 64.

Playback seems slower and is constantly distorted (not momentary glitches)

  • Other applications play back fine on the same device
  • Changing “Periods/Buffer” in Renoise changes the nature of the sound but ultimate doesn’t help. Feels like if I could increase it to 32 or 64 maybe it could sound correct, but these are huge buffers.
  • Other apps using the same device successfully, including realtime use at 4x periods. Still sound ok even when Renoise is using the device.
  • Getting these same results with an actual hardware device, or with snd-aloop
  • Tried various “In device” settings in Renoise, with some intermittent effect (see case below)

So it seems to suggest this might be the way Renoise is using the ALSA API.

Snippet of .asoundrc:

        playback.pcm {
                type dmix
                ipc_key 3187
#               direct_memory_access on

                slave {
                        rate 48000
                        channels 2
                        format S24_LE
                        buffer_size 8192
                        period_size 64

                        pcm {
                                type hw
                                card "Local"
                                device 0
                                subdevice 3
                        }
                }
        }

Threads seem to be prioritised:

  PID   TID CLS RTPRIO  NI PRI PSR %CPU STAT WCHAN          COMMAND
 ... 
 6101  6101 TS       -   0  19   2 20.1 SLl+ futex_wait_que renoise
 6101  6110 TS       -   0  19   3  0.0 SLl+ do_epoll_wait  renoise
 6101  6111 TS       -   0  19   1  0.0 SLl+ futex_wait_que renoise
 6101  6112 TS       -   0  19   2  0.0 SLl+ do_epoll_wait  renoise
 6101  6119 RR      95   - 135   1  6.0 SLl+ futex_wait_que renoise
 6101  6120 RR      95   - 135   2  5.1 SLl+ futex_wait_que renoise
 6101  6121 RR      95   - 135   3  5.9 SLl+ futex_wait_que renoise
 6101  6209 RR      95   - 135   0 14.2 SLl+ do_sys_poll    renoise

Using the default device, distorted:

Renoise LOG> ALSA: Stopping ALSA playback...
Renoise LOG> ALSA: Opening ALSA Playback Device 'default (System Default Device)'...
Renoise LOG> ALSA: Open ALSA Output Device OK
Renoise LOG> ALSA: Max channels is 10000 for Playback...
Renoise LOG> ALSA: Device seems to use a virtual channel setup. Limiting max channels to 2 for Playback...
Renoise LOG> ALSA: Using 2 channels (2 requested) for Playback...
Renoise LOG> ALSA: Using access format RW_INTERLEAVED (requested RW_INTERLEAVED) for Playback...
Renoise LOG> ALSA: Using sample format S32_LE for Playback...
Renoise LOG> ALSA: Using samplerate 48000 (requested 48000) for Playback...
Renoise LOG> ALSA: Using period time 64 (requested 64) for Playback...
Renoise LOG> ALSA: Using 4 num periods (requested 4) for Playback...
Renoise LOG> ALSA: Using buffer size 256 (requested 256)...
Renoise LOG> ALSA: Setup Buffers...
Renoise LOG> ALSA: Configuring the Player...
Renoise LOG> ALSA: Preparing and starting devices...
Renoise LOG> ALSA: Creating the poll thread...
Renoise LOG> ALSA: Successfully created an ALSA RT thread
Renoise LOG> ALSA: Up and running...

For comparison, asking Renoise to select the hardware device plays fine with the same buffer settings:

Renoise LOG> ALSA: Stopping ALSA playback...
Renoise LOG> ALSA: Opening ALSA Playback Device 'hw:Layla3G,0 (Layla3G)'...
Renoise LOG> ALSA: Open ALSA Output Device OK
Renoise LOG> ALSA: Max channels is 8 for Playback...
Renoise LOG> ALSA: Force stereo I/O for Playback...
Renoise LOG> ALSA: Using 2 channels (2 requested) for Playback...
Renoise LOG> ALSA: Using access format RW_INTERLEAVED (requested RW_INTERLEAVED) for Playback...
Renoise LOG> ALSA: Using sample format S32_LE for Playback...
Renoise LOG> ALSA: Using samplerate 48000 (requested 48000) for Playback...
Renoise LOG> ALSA: Using period time 64 (requested 64) for Playback...
Renoise LOG> ALSA: Using 4 num periods (requested 4) for Playback...
Renoise LOG> ALSA: Using buffer size 256 (requested 256)...
Renoise LOG> ALSA: Setup Buffers...
Renoise LOG> ALSA: Configuring the Player...
Renoise LOG> ALSA: Preparing and starting devices...
Renoise LOG> ALSA: Creating the poll thread...
Renoise LOG> ALSA: Successfully created an ALSA RT thread
Renoise LOG> ALSA: Up and running...

Selecting a StreamCam as “In device” may intermittently create acceptable (but not stable) playback. I wouldn’t expect this to work because of the differing clocks, and it’s still terrible but at least has some stable playback:

Renoise LOG> ALSA: Stopping ALSA playback...
Renoise LOG> ALSA: Opening ALSA Playback Device 'default (System Default Device)'...
Renoise LOG> ALSA: Open ALSA Output Device OK
Renoise LOG> ALSA: Max channels is 10000 for Playback...
Renoise LOG> ALSA: Force stereo I/O for Playback...
Renoise LOG> ALSA: Using 2 channels (2 requested) for Playback...
Renoise LOG> ALSA: Using access format RW_INTERLEAVED (requested RW_INTERLEAVED) for Playback...
Renoise LOG> ALSA: Using sample format S32_LE for Playback...
Renoise LOG> ALSA: Using samplerate 48000 (requested 48000) for Playback...
Renoise LOG> ALSA: Using period time 64 (requested 64) for Playback...
Renoise LOG> ALSA: Using 4 num periods (requested 4) for Playback...
Renoise LOG> ALSA: Using buffer size 256 (requested 256)...
Renoise LOG> ALSA: Opening ALSA Capture Device 'hw:StreamCam,0 (USB Audio)'...
Renoise LOG> ALSA: Open ALSA Capture Device OK
Renoise LOG> ALSA: Max channels is 2 for Capture...
Renoise LOG> ALSA: Force stereo I/O for Capture...
Renoise LOG> ALSA: Using 2 channels (2 requested) for Capture...
Renoise LOG> ALSA: Using access format RW_INTERLEAVED (requested RW_INTERLEAVED) for Capture...
Renoise LOG> ALSA: Failed to set format S32_LE for Capture: Invalid argument...
Renoise LOG> ALSA: Failed to set format S24_3LE for Capture: Invalid argument...
Renoise LOG> ALSA: Using sample format S16_LE for Capture...
Renoise LOG> ALSA: Using samplerate 48000 (requested 48000) for Capture...
Renoise LOG> ALSA: Using period time 64 (requested 64) for Capture...
Renoise LOG> ALSA: Using 4 num periods (requested 4) for Capture...
Renoise LOG> ALSA: Setup Buffers...
Renoise LOG> ALSA: Configuring the Player...
Renoise LOG> ALSA: Preparing and starting devices...
Renoise LOG> ALSA: FAILED to link playback and capture device (Function not implemented)!
Renoise LOG> ALSA: Creating the poll thread...
Renoise LOG> ALSA: Successfully created an ALSA RT thread
Renoise LOG> ALSA: Up and running...