Patch usb-audio: I need guidelines
Hi Alsa-Gurus,
I've found how to patch the snd-usb-audio driver in order to get the Audiophile_USB analog capture to work. This device uses different synchronization methods whether the the SPDIF input is connected or not.
This information should be given by the user at driver-loading-time and thus I need a new init parameter for the snd-usb-audio module: I know that this could be a blocking point, but please read below in order to see how I try to make this patch "non-intrusive".
I've already designed an ugly patch that is working but I'd like to make it clean before publishing it. Could you please give me comments and/or advice on the following description ?
This is how I think things _could_ be done:
* add a new parameter called "device_setup" (integer)
- this parameter uses a generic name, so that it could be used by any
subsequent devices (well..., only if needed of course)
- the parameter bits signification depends on the USB_ID for the device
* if this parameter is not given, the _default_value_0x00_does_nothing_new_ (returns to previous behaviour)
- This will ensure that no setup modification is needed for current happyAudiophile_USB users ;-)
* use constants to name each significant bit of this parameter
- "#defines" could go to "usbquirks.h" (for instance "#defineAUDIOPHILE_SET_DIGITAL_INPUT 0x04"). Or is there a better include file?
- Are they any naming convention for these device specific constants?
* I am currently only using the least significant 8bits of the "int" value, do you think an 'int' is enough to cover _would-be_ future needs? (I know that this question seems stupid since no one but me has asked for such a parameter ;-) but anyway I think it is worth asking)
* for Audiophile_USB, I need to patch "parse-audio-endpoints":
- I have seen a "case USB_ID" section with existing quirks and would
integrate my patch in the already existing Audiophile_USB subsection
Is everything described above sounds good?
Thanks in advance for your comments,
Regards,
Thibault
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
At Tue, 21 Feb 2006 18:10:34 +0100,
Quoted 37 lines · Thibault LE MEUR
Hi Alsa-Gurus,
I've found how to patch the snd-usb-audio driver in order to get the
Audiophile_USBanalog capture to work. This device uses different synchronization methods whether the the SPDIF input is connected or not.This information should be given by the user at driver-loading-time and thus I need a new init parameter for the snd-usb-audio module: I know that this could be a blocking point, but please read below in order to see how I try to make this patch "non-intrusive".
I've already designed an ugly patch that is working but I'd like to make it clean before publishing it. Could you please give me comments and/or advice on the following description ?
This is how I think things _could_ be done:
* add a new parameter called "device_setup" (integer)
- this parameter uses a generic name, so that it could be used by any
subsequent devices (well..., only if needed of course)
- the parameter bits signification depends on theUSB_IDfor the device* if this parameter is not given, the _default_value_0x00_does_nothing_new_ (returns to previous behaviour)
- This will ensure that no setup modification is needed for current happyAudiophile_USBusers ;-)* use constants to name each significant bit of this parameter
- "#defines" could go to "usbquirks.h" (for instance "#defineAUDIOPHILE_SET_DIGITAL_INPUT0x04"). Or is there a better include file?
- Are they any naming convention for these device specific constants?* I am currently only using the least significant 8bits of the "int" value, do you think an 'int' is enough to cover _would-be_ future needs? (I know that this question seems stupid since no one but me has asked for such a parameter ;-) but anyway I think it is worth asking)
Quoted 5 lines
* for
Audiophile_USB, I need to patch "parse-audio-endpoints":
- I have seen a "caseUSB_ID" section with existing quirks and would
integrate my patch in the already existingAudiophile_USBsubsectionIs everything described above sounds good?
Reading the above, I feel creating a new driver would be cleaner rather than adding tons of workarounds for special cases. It could use most of functions in usb*.c.
I don't know what change you need in parse_audio_endpoints(), but if it's complicated, it'd be better to make a change more generic. For example, we can add a hook as the argument to this function. It's a function pointer which is called in the place where many USB_ID checks are for overriding with device-speicific values.
Just my $0.02.
Takashi
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
Hi Takashi,
Quoted 3 lines
Reading the above, I feel creating a new driver would be cleaner rather than adding tons of workarounds for special cases. It could use most of functions in usb*.c.
Yes that could be a solution but 99% of the usbaudio.c code is fine for the device, and I think little has to be done in order to get it work better. So I think it would be better not to "fork" and customize this driver.
Quoted 1 line
I don't know what change you need in
parse_audio_endpoints(),
In fact the m-audio audiophile usb has several usb interfaces each with several Altsettings but some Altsettings are mutually exclusive.
Let me be more specific:
* Usb Interface 2 is the Analog Out audio function
* Usb Interface 3 is the Digital Out audio function
* Usb Interface 4 is the Analog In audio function
* Usb Interface 5 is the Digital In audio function
Usb Interfaces 2,3 and 4 has Altsettings 1,2,3,4,5 and Usb Intercace 5 only has Altsetting 1,2,4:
* AltSetting 1 is used in 24bits 96KHz mode only
* AltSettings 3 and 5 (Synch and Adaptive mode) are used in 24bits/48KHz and 16bits/48KHz mode respectively _if_and_only_if_ Digital Input is _not_ used
* AltSettings 2 and 4 (ASync mode) are used in 24bits/48KHz and 16bits/48KHz mode respectively _if_and_only_if_ Digital Input is used and an SPDIF source is connected to it
--> Not respecting this constraint may result in a byte alignment error
for the Analog Input stream see bug
https://bugtrack.alsa-project.org/alsa-bug/view.php?id=1801.
Currently, the ALSA driver sets all the Interfaces/Altsettings at "probing time", and then chooses the correct interface/altsettings "on-demand".
My first patch only "hides" Altsettings that do not correspond to the "device_setup" module parameter I introduced (because I have no other way to know if the user is planning to use Digital Input or not).
- the "device_setup" contains bits that say what the user is willing to
do: sample Resolution/Rate, which interface to enable (including Digital Input activation or not)...
Quoted 1 line
but if it's complicated, it'd be better to make a change more
I don't thinks it's that tricky a couple of lines checking bit of device_setup and just skipping some Interface/AltSettings initializations.
Quoted 4 lines
generic. For example, we can add a hook as the argument to this function. It's a function pointer which is called in the place where many
USB_IDchecks are for overriding with device-speicific values.
Yes, that's possible. I could create a quirk function "parse_audio_endpoints_audiophile_quirk" and call it from parse_audio_endpoints. I don't know if adding it as a function pointer parameter to parse_audio_endpoints is interresting: it would be usefull only if several other devices need quirks at the exact same point in the function... But why not...
I'm also wondering if patching the "Interface/AltSetting" selection process instead of the parse_audio_endpoint process would be cleaner: but I'm afraid that the audiophile usb device is touchy and doesn't like the whole Interfaces/Altsettings to have been initialized at first (and especially the one that do not correspond to the Digital-Input state).
By the way, I still have an issue when trying to unregister the snd-usb-audio module then probe it again with correct device_setup value: it seems that my device is not reinitialized completely (even if I added interfaces resets, set clear on endpoints and even a set configuration at reprobing time [just testing patches]). I always need to turn off and then on again the device so that the correct initlization is taken into account.
* Do you know a way of completely reset a usb device without having to turn it off/on ?
Thanks for your comments and support.
Regards,
Thibault
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642