ALSA: usb-audio: Expose sample resolution through proc interface
PATCH 1/1 ALSA: usb-audio: Expose sample resolution through proc interface
At least some USB devices use (MSB-aligned) audio format larger than the actual resolution of the device. In order to expose the actual device resolution (bBitResolution), add extra field to the procfs stream info interface.
--- sound/usb/card.h | 1 + sound/usb/format.c | 2 ++ sound/usb/proc.c | 1 + 3 files changed, 4 insertions(+)
sound/usb/card.h +1 -0
@@ -14,6 +14,7 @@ struct audioformat {u64 formats;/* ALSA format bits */ unsigned int channels;/* # channels */ unsigned int fmt_type;/* USB audio format type (1-3) */ +unsigned int fmt_bits;/* number of significant bits */ unsigned int frame_size;/* samples per frame for non-audio */ int iface;/* interface number */ unsigned char altsetting;/* corresponding alternate setting */
sound/usb/format.c +2 -0
@@ -87,6 +87,8 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip, } } + fp->fmt_bits = (unsigned int ) sample_width; +if ((pcm_formats ==0 ) && (format ==0 || format == (1 <<UAC_FORMAT_TYPE_I_UNDEFINED ))) {/* some devices don't define this correctly... */
sound/usb/proc.c +1 -0
@@ -109,6 +109,7 @@ static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct sif (subs->speed !=USB_SPEED_FULL )snd_iprintf (buffer," Data packet interval: %d us\n" ,125 * (1 << fp->datainterval)); +snd_iprintf (buffer," Bits: %d\n" , fp->fmt_bits);// snd_iprintf(buffer, " Max Packet Size = %d\n", fp->maxpacksize); // snd_iprintf(buffer, " EP Attribute = %#x\n", fp->attributes); }
Signature · 1 line
2.17.1
Quoted 7 lines · Jussi Laako
At least some USB devices use (MSB-aligned) audio format larger than the actual resolution of the device. In order to expose the actual device resolution (bBitResolution), add extra field to the procfs stream info interface.
Signed-off-by Jussi Laako <[email protected]>
The code change looks but, just some minor issues:
Quoted 11 lines
--- sound/usb/card.h | 1 + sound/usb/format.c | 2 ++ sound/usb/proc.c | 1 + 3 files changed, 4 insertions(+)sound/usb/card.h +0
-0
sound/usb/card.h struct audioformat { · line 17
Quoted 4 lines
sound/usb/card.h +1
-0@@ -14,6 +14,7 @@ struct audioformat {u64 formats;/* ALSA format bits */ unsigned int channels;/* # channels */ unsigned int fmt_type;/* USB audio format type (1-3) */ +unsigned int fmt_bits;/* number of significant bits */
Please use tabs. checkpatch will catch such a problem, so please run it at the next time before submission.
sound/usb/format.c static u64 parse_audio_format_i_type(struct snd_usb_audio *chip, · line 90
Quoted 12 lines
sound/usb/card.h +0
-0unsigned int frame_size;/* samples per frame for non-audio */ int iface;/* interface number */ unsigned char altsetting;/* corresponding alternate setting */ sound/usb/format.c +1
-0@@ -87,6 +87,8 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip, } } + fp->fmt_bits = (unsigned int ) sample_width;
Such cast is superfluous in Linux kernel code.
I applied the patch with these fixed locally.
Thanks!
Takashi
Quoted 7 lines · Takashi Iwai
The code change looks but, just some minor issues:
Please use tabs. checkpatch will catch such a problem, so please run it at the next time before submission.
I applied the patch with these fixed locally.
OK, thanks! Will do!
Ultimately I would like to get the sample resolution for example through snd_pcm_hw_params_get_sbits(), but I didn't find a nice way to get this information to the ALSA API without lot of changes all over the place, or alternatively introducing a new sample format which I think is not a good idea in this case.
I can parse the stream info from proc though, so it is not so much issue.
Best regards,
- Jussi