alsa and snd_usb_audio configuration

hello
is there anything special set in alsa system … especially on modules as

/sbin/modinfo -p snd_usb_audio

i meant, did u apply some special patches to alsa/snd that are not in mainline or didnt go to mainline kernel?


thanks

We use the regular ALSA packages (alsa-utils, libasound2) from Debian, nothing special. But we apply a custom config: /etc/asound.conf

The kernel-side driver depends on the hardware, are you asking for Raspberry Pi?

Hi there
I am trying to set the default period size of the snd_usb_audio for ALSA but without success. Also tried to edit the asound.conf without any luck. Anyone has done it successfully?

P.s. It is always locked to 2048 period size but after sometime change to 4096. Is there anyway to override the auto config of the card?

I want it to have it permanent to 2048.

Can you show how you tried it via /etc/asound.conf?

Yes here it is maybe I have done something wrong:

pcm.!default {
        type hw
        card 1
        device 0
}

ctl.!default {
        type hw
        card 1
}



pcm "snd_usb_audio_hw"
            format S32_LE
            period_size 2048
            buffer_size 12288
            rate 192000

Please try this:

pcm.!default {
        type hw
        card 1
        device 0
        format S32_LE
        period_size 2048
        buffer_size 12288
        rate 192000
}

ctl.!default {
        type hw
        card 1
}

The same thing it still shows period_size 4096. I am checking it on /proc/asound/card1/pcm0p/sub0/hw_params. Still no luck.

What I wonder about is that I find the “period_size” setting only set as part of a child/slave PCM definition but never directive as part of a hw PCM definition :thinking:.

Another test: speaker-test
It should also show you a period_size range.

With the speaker_test if I override the settings it is seems to be working with this command speaker-test -F S32_LE -c 2 -r 192000 -p 2048
:

Playback device is default
Stream parameters are 192000Hz, S32_LE, 2 channels
Using 16 octaves of pink noise
Rate set to 192000Hz (requested 192000Hz)
Buffer size range from 48 to 131072
Period size range from 24 to 65536
Requested period time 2048 us
Periods = 4
was set period_size = 393
was set buffer_size = 1572
0 - Front Left
1 - Front Right

Without override the period it give me this:

Playback device is default
Stream parameters are 192000Hz, S32_LE, 2 channels
Using 16 octaves of pink noise
Rate set to 192000Hz (requested 192000Hz)
Buffer size range from 48 to 131072
Period size range from 24 to 65536
Using max buffer size 131072
Periods = 4
was set period_size = 32768
was set buffer_size = 131072
0 - Front Left
1 - Front Right

Okay, with “Period size range from 24 to 65536” it should work. You did set the period time (in microseconds) now instead of the period size (in frames). If you want a period size of 2048 frames, it would be:

2048 frames/(192000 frames/second) = 0,010666... seconds = 10667 microseconds period time



speaker-test -F S32_LE -c 2 -r 192000 -p 10667

Just to verify that this period time really works. Then you could also try to replace the period_size setting in asound.conf with this calculated period_time and the buffer_size setting with the buffer_time of buffer_time 64002 (10667 microseconds/period * 6 periods) accordingly, and see if that works. Probably also skip the buffer time/size, which should result in default 4 periods.

Check out the plugin docs: https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html
As you can see, setting period/buffer time/size is somehow only documented for slave definitions. But this means you need a master plugin type for the default PCM. If we want no kind of conversion, but only test to use a no-op master to assign buffer settings to the hw slave, then probably the “copy” plugin can be used for that, as it doesn’t seem to do anything else than copying the stream from master to slave. If you need help, I can show you the syntax to try that, but whether this is the intended way, will work or not, is also above my ALSA/audio knowledge :wink:.

Yes it is accepted it with the speaker set, but when i put the new settings on asound.conf it rollback to the defaults one. Maybe it can be a driver limitation? The weird thing thing is that on after reboot the driver starts at 2048 period_size and the then goes to 4096. Weird.

I have to edit here. It is fixed by putting only the buffer size and not the period size. It is now stable at 2048 period_size. Thank you very much for the help.

Great that it works like that and thanks for providing the solution. Good to keep in mind when this question arises again or someone wants to add an option to our scripts :slight_smile:.