]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ALSA: firewire-motu: export meter information to userspace as float value
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 27 Oct 2021 12:55:29 +0000 (21:55 +0900)
committerTakashi Iwai <tiwai@suse.de>
Thu, 28 Oct 2021 07:10:41 +0000 (09:10 +0200)
In command DSP models, one meter information consists of 4 bytes for
IEEE 764 floating point (binary32). In previous patch, it is exported
to userspace as 32 bit storage since the storage is also handled in
ALSA firewire-motu driver as well in kernel space in which floating point
arithmetic is not preferable. On the other hand, ALSA firewire-motu driver
doesn't perform floating point calculation. The driver just gather meter
information from isochronous packets and fill structure fields for
userspace.

In 'header' target of Kbuild, UAPI headers are processed before installed.
In this timing, #ifdef macro with __KERNEL__ is removed. This mechanism
is useful in the case so that the 32 bit storage can be accessible as u32
type in kernel space and float type in user space. We can see the same
usage in ''struct acct_v3' in 'include/uapi/linux/acct.h'.

This commit is for the above idea. Additionally, due to message
protocol, meter information is filled with 0xffffffff in the end of
period but 0xffffffff is invalid as binary32. To avoid confusion in
userspace application, the last two elements are left without any
assignment.

Suggested-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Link: https://lore.kernel.org/r/20211027125529.54295-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/uapi/sound/firewire.h
sound/firewire/motu/motu-command-dsp-message-parser.c

index 68eb0e43c052ca040d7428f193bb6ddf7f261729..39cf6eb75940ea7b47e6b2b1fc3737141f2ae203 100644 (file)
@@ -248,12 +248,14 @@ struct snd_firewire_motu_register_dsp_parameter {
  *
  * The structure expresses the part of DSP status for hardware meter. The 32 bit storage is
  * estimated to include IEEE 764 32 bit single precision floating point (binary32) value. It is
- * expected to be linear value (not logarithm) for audio signal level between 0.0 and +1.0. However,
- * the last two quadlets (data[398] and data[399]) are filled with 0xffffffff since they are the
- * marker of one period.
+ * expected to be linear value (not logarithm) for audio signal level between 0.0 and +1.0.
  */
 struct snd_firewire_motu_command_dsp_meter {
+#ifdef __KERNEL__
        __u32 data[SNDRV_FIREWIRE_MOTU_COMMAND_DSP_METER_COUNT];
+#else
+       float data[SNDRV_FIREWIRE_MOTU_COMMAND_DSP_METER_COUNT];
+#endif
 };
 
 #endif /* _UAPI_SOUND_FIREWIRE_H_INCLUDED */
index 18689fcfb288f612e2cf4ac8baec8826e322ed87..9efe4d364baf5cc2de602d4be8b9c9c4f03156ec 100644 (file)
@@ -141,12 +141,15 @@ void snd_motu_command_dsp_message_parser_parse(struct snd_motu *motu, const stru
                                        ++parser->fragment_pos;
 
                                        if (parser->fragment_pos == 4) {
+                                               // Skip the last two quadlets since they could be
+                                               // invalid value (0xffffffff) as floating point
+                                               // number.
                                                if (parser->value_index <
-                                                   SNDRV_FIREWIRE_MOTU_COMMAND_DSP_METER_COUNT) {
+                                                   SNDRV_FIREWIRE_MOTU_COMMAND_DSP_METER_COUNT - 2) {
                                                        u32 val = (u32)(parser->value >> 32);
                                                        parser->meter.data[parser->value_index] = val;
-                                                       ++parser->value_index;
                                                }
+                                               ++parser->value_index;
                                                parser->fragment_pos = 0;
                                        }