[alsa-devel] strange code in pcm_route.c for 3 byte formats
Hi all,
While reading alsa-lib sources I've spotted some strange code in src/pcm/pcm_route.c: /* 3 bytes formats? */ route->params.use_getput = (snd_pcm_format_physical_width(src_format) + 7) / 3 == 3 || (snd_pcm_format_physical_width(dst_format) + 7) / 3 == 3;
Since snd_pcm_format_physical_width() returns a width in bits it seems to me that this would mean formats that are between 2 and 4 bits (inclusive) wide.
Before commit de63b942acf520 ("pcm: route: Use get/put labels for all 3 byte formats") this read as: route->params.use_getput = snd_pcm_format_physical_width(src_format) == 24 || snd_pcm_format_physical_width(dst_format) == 24;
The commit message of that commit says that this change was supposed to set this flag also for 18 and 20-bit physical width formats.
Is there a mistake in this code or am I wrong somewhere in my thinking?
Best regards, Maciej
Maciej S. Szmigiero wrote:
While reading alsa-lib sources I've spotted some strange code in src/pcm/pcm_route.c: /* 3 bytes formats? */ route->params.use_getput = (snd_pcm_format_physical_width(src_format) + 7) / 3 == 3 || (snd_pcm_format_physical_width(dst_format) + 7) / 3 == 3;
"(x + n-1) / n" is "divide by n while rounding up".
"/ 3" should have been "/ 8".
Regards, Clemens
On 20.11.2017 08:34, Clemens Ladisch wrote:
Maciej S. Szmigiero wrote:
While reading alsa-lib sources I've spotted some strange code in src/pcm/pcm_route.c: /* 3 bytes formats? */ route->params.use_getput = (snd_pcm_format_physical_width(src_format) + 7) / 3 == 3 || (snd_pcm_format_physical_width(dst_format) + 7) / 3 == 3;
"(x + n-1) / n" is "divide by n while rounding up".
"/ 3" should have been "/ 8".
Thanks for your explanation, I've submitted a patch for alsa-lib now.
Regards, Clemens
Best regards, Maciej
participants (2)
-
Clemens Ladisch
-
Maciej S. Szmigiero