... Why only 240? That's the next logical question. If you have a clarification for it, it may be the rigid reason to introduce such a hw constraint.
According to Brent, the DSP is using 240 period regardless the hw_param. If the period size is 256, DSP will read 256 samples each time but only consume 240 samples until the ring buffer of DSP is full. This behavior makes the samples in the ring buffer of kernel consumed quickly.
Not sure whether the explanation is correct. Hi Brent, can you confirm it?
This seems to be going round and round in circles. Userspace lets the kernel pick the period size, if the period size isn't 240 (or a multiple of it?) the DSP doesn't properly pay attention to that apparently due to internal hard coding in the DSP firmware which we can't change so the constraint logic needs to know about this DSP limitation - it seems like none of this is going to change without something new going into the mix? We at least need a new question to ask about the DSP firmware I think.
I just tested aplay -Dhw: on a Cyan Chromebook with the Ubuntu kernel 5.4, and I see no issues with the 240 sample period. Same with 432, 960, 9600, etc.
I also tried just for fun what happens with 256 samples, and I don't see any underflows thrown either, so I am wondering what exactly the problem is? Something's not adding up. I would definitively favor multiple of 1ms periods, since it's the only case that was productized, but there's got to me something a side effect of how CRAS programs the hw_params.
root@chrx:~# aplay -Dhw:0,0 --period-size=240 --buffer-size=480 -v 1.wav Playing WAVE '1.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo Hardware PCM card 0 'chtmax98090' device 0 subdevice 0 Its setup is: stream : PLAYBACK access : RW_INTERLEAVED format : S16_LE subformat : STD channels : 2 rate : 48000 exact rate : 48000 (48000/1) msbits : 16 buffer_size : 480 period_size : 240 period_time : 5000 tstamp_mode : NONE tstamp_type : MONOTONIC period_step : 1 avail_min : 240 period_event : 0 start_threshold : 480 stop_threshold : 480 silence_threshold: 0 silence_size : 0 boundary : 8646911284551352320 appl_ptr : 0 hw_ptr : 0
root@chrx:~# aplay -Dhw:0,0 --period-size=256 --buffer-size=512 -v 1.wav Playing WAVE '1.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo Hardware PCM card 0 'chtmax98090' device 0 subdevice 0 Its setup is: stream : PLAYBACK access : RW_INTERLEAVED format : S16_LE subformat : STD channels : 2 rate : 48000 exact rate : 48000 (48000/1) msbits : 16 buffer_size : 512 period_size : 256 period_time : 5333 tstamp_mode : NONE tstamp_type : MONOTONIC period_step : 1 avail_min : 256 period_event : 0 start_threshold : 512 stop_threshold : 512 silence_threshold: 0 silence_size : 0 boundary : 4611686018427387904 appl_ptr : 0 hw_ptr : 0