Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,736,733 Members 54,708 Now Online
XDA Developers Android and Mobile Development Forum

[MOD] USB Audio Support

Tip us?
 
jacknorris
Old
(Last edited by jacknorris; 24th January 2013 at 05:15 PM.) Reason: Updated attachments
#1  
Member - OP
Thanks Meter 83
Posts: 55
Join Date: Nov 2010
Thumbs up [MOD] USB Audio Support

Nexus 7 USB Audio Support

I originally started looking into this as part of my Nexus 7 car project. Rebooting just to get USB audio working conflicted with my goal of being able to "dock and forget". It took a bit of experimenting and debugging but it's finally working

This program should enable USB audio support on your Nexus 7 - that means you are able to plug and unplug a USB sound card without having to reboot in order for it to work. Other devices should also work but I have not been able to fully test.

It works by downloading your devices services.jar which is then extracted and de-odexed if required. The necessary classes are then patched and a new services.jar is packaged up, re-odexed, re-signed and finally re-uploaded to your device. The previous method replaced the entire services.jar which turned out to be a really bad idea!

As always please let me know of any issues you stumble upon. The patching software was written quickly so there will most likely be bugs!

Instructions

  1. Obtain a full backup of your device. This patch is experimental.
  2. Ensure your device is ADB enabled, rooted and has busybox installed.
  3. Make sure your PC has Java and .NET 4 installed.
  4. Download usb-audio-patcher below and extract to a folder.
  5. Run usb-audio-patcher.exe, the software will guide you through the rest of the process.
  6. Flash a kernel with USB audio support. Nexus 7 Wifi kernels can be found below although any kernel with USB audio support will work.

Downloads

Software
[Windows] usb-audio-patcher-1.1.zip.

Kernels
[N7 CM10 / Stock 4.1.2] cm-10-n7-wifi-usb-audio-kernel.zip
[N7 CM10.1 / Stock 4.2.1] cm-10.1-n7-wifi-usb-audio-kernel.zip
[Timurs N7 Kernel] http://rootzwiki.com...ment-usb-audio/

Misc
[Volume Control] n7-volume-control-patch.zip - Allow media volume control when USB audio device is connected.
The Following 35 Users Say Thank You to jacknorris For This Useful Post: [ Click to Expand ]
 
jacknorris
Old
#2  
Member - OP
Thanks Meter 83
Posts: 55
Join Date: Nov 2010
reserved
The Following User Says Thank You to jacknorris For This Useful Post: [ Click to Expand ]
 
bobmorane83
Old
#3  
Junior Member
Thanks Meter 0
Posts: 6
Join Date: Nov 2012
Default thenfree subject

Hi,

I was exactly looking for such program !!
I've an HTC One XL stock ROM rooted. USB Audio is supported by kernel as I can use alsa_aplay on my external USB sound card.
But I was looking for a player. Your patchs are even more interesting !

Do you think this can be working on my phone ?
As I'am newbie to Android, I don't know if I can just copy services.jar in place of my current HTC file (making backup of course) ?
Here is what I can see in /system/framework

-rw-r--r-- root root 313 2012-11-08 18:21 services.jar
-rw-r--r-- root root 2983720 2012-11-08 18:21 services.odex

Thx for help,
Vincent.
 
jacknorris
Old
#4  
Member - OP
Thanks Meter 83
Posts: 55
Join Date: Nov 2010
Quote:
Originally Posted by bobmorane83 View Post
Hi,

I was exactly looking for such program !!
I've an HTC One XL stock ROM rooted. USB Audio is supported by kernel as I can use alsa_aplay on my external USB sound card.
But I was looking for a player. Your patchs are even more interesting !

Do you think this can be working on my phone ?
As I'am newbie to Android, I don't know if I can just copy services.jar in place of my current HTC file (making backup of course) ?
Here is what I can see in /system/framework

-rw-r--r-- root root 313 2012-11-08 18:21 services.jar
-rw-r--r-- root root 2983720 2012-11-08 18:21 services.odex

Thx for help,
Vincent.
To be honest I really don't know HTC tend to do alot of things to their ROMs so it could break things horribly for you.
Without a working services.jar the device doesn't even boot - it will just hang at the boot animation and you may never be able to restore the backup.

If you can get a copy of your ROM and place it on your device prior to testing then you could flash the ROM back over the top via CWM/TWRP to restore the original services.jar file without losing your user data.

I would be interested to hear how you get on should you decide to give this a go.

Good luck!
The Following User Says Thank You to jacknorris For This Useful Post: [ Click to Expand ]
 
bobmorane83
Old
#5  
Junior Member
Thanks Meter 0
Posts: 6
Join Date: Nov 2012
Quote:
Originally Posted by jacknorris View Post
To be honest I really don't know HTC tend to do alot of things to their ROMs so it could break things horribly for you.
Without a working services.jar the device doesn't even boot - it will just hang at the boot animation and you may never be able to restore the backup.

If you can get a copy of your ROM and place it on your device prior to testing then you could flash the ROM back over the top via CWM/TWRP to restore the original services.jar file without losing your user data.

I would be interested to hear how you get on should you decide to give this a go.

Good luck!
Thanks for your reply and warning.
I'll be very careful then on this topic even if I have TWRP installed and ROM backup done.

As I haven't find Android source code for my phone (except kernel code available at HTCdev.com) I was wondering if this
method could be a way to patch the existing services.jar : www(.)jordanhotmann(.)com/2011/09/android-hacking-101-compiling-and.html
(sorry I'am still not allow to post url)
Have you ever try that ?

Thx,
V.
 
wildzero
Old
#6  
Junior Member
Thanks Meter 0
Posts: 2
Join Date: Feb 2011
Location: Frankfurt
Hello, i have a very similar goal for usb-audio. The difference is, i want to plug in a USB-Headset
when i do skype and other VoIP calles. So i want also audio input from the usb-device.

Where to find your scource?
 
grandrew
Old
#7  
Junior Member
Thanks Meter 1
Posts: 1
Join Date: Dec 2012
Hi!
I'm also interested in getting usb-audio-in to work!
My usb audio device is already supported by builtin usbaudio driver kernel module and is detected by ALSA

Do you think there are any chances to get it to work without patching? AFAIK android cannot switch automatically except for 'accessory mode' usb audio events which are supported for dock stations. Maybe it is possible to change audio cards priority via config files? As far as I understand audio_policy.conf is of no use?

For those who cannot find sources: the link is in the first message, read carefully!
The Following User Says Thank You to grandrew For This Useful Post: [ Click to Expand ]
 
bbop
Old
#8  
Member
Thanks Meter 3
Posts: 38
Join Date: Nov 2010
Quote:
Originally Posted by grandrew View Post
Hi!
I'm also interested in getting usb-audio-in to work!
My usb audio device is already supported by builtin usbaudio driver kernel module and is detected by ALSA

Do you think there are any chances to get it to work without patching? AFAIK android cannot switch automatically except for 'accessory mode' usb audio events which are supported for dock stations. Maybe it is possible to change audio cards priority via config files? As far as I understand audio_policy.conf is of no use?

For those who cannot find sources: the link is in the first message, read carefully!
I have no idea what tools are available on android for audio stuff yet but I'm getting a nexus 7 and this looks interesting. I have some experience of doing audio stuff with linux though.

In linux, you can specify the default sound device via alsa with asound.conf or .asoundrc file. You can make relatively complex setups that will make alsa switch automatically when plugging in usb devices. the wiki:
http://alsa.opensrc.org/.asoundrc

what sort of sound related commands are available to you in android any way? Can you try these in the terminal?

aplay -l
amixer
alsamixer

aplay -l is specifically useful for determining the names of your hardware to configure alsa correctly (you should use names such as USB Audio Codec rather than HW 1,0 values).

OK well this is very interesting. I'm off to check what's been made available to android so far...
 
henrylar
Old
#9  
Senior Member
Thanks Meter 25
Posts: 144
Join Date: Feb 2008
This is exactly what I am looking for. I have just got my N7, isn't even rooted yet. But I am going to try this out in a few days, and test it with the FIIO E17, which is why I bought the N7.

It will take a few days before I have access to a windows computer for the rooting, but then I will come back with my experience of it.
Phone: LG G2, D802
ROM: CloudyStock 2.2
Recovery: Philz Touch 6.19.7 (not anymore..)



Tablet: Nexus 7
rooted, with Faux kernel
 
jacknorris
Old
(Last edited by jacknorris; 6th December 2012 at 07:28 PM.)
#10  
Member - OP
Thanks Meter 83
Posts: 55
Join Date: Nov 2010
Quote:
Originally Posted by grandrew View Post
Hi!
I'm also interested in getting usb-audio-in to work!
My usb audio device is already supported by builtin usbaudio driver kernel module and is detected by ALSA

Do you think there are any chances to get it to work without patching? AFAIK android cannot switch automatically except for 'accessory mode' usb audio events which are supported for dock stations. Maybe it is possible to change audio cards priority via config files? As far as I understand audio_policy.conf is of no use?

For those who cannot find sources: the link is in the first message, read carefully!
I am working on moving the code to a separate service which should allow switching to USB audio without having to patch any files you could instead install an APK, it would also be much safer than replacing the entire services file. I'm afraid that a config modification alone isn't going to make this work as there is simply no detection code to make and execute the switch.


Quote:
Originally Posted by bbop View Post
I have no idea what tools are available on android for audio stuff yet but I'm getting a nexus 7 and this looks interesting. I have some experience of doing audio stuff with linux though.

In linux, you can specify the default sound device via alsa with asound.conf or .asoundrc file. You can make relatively complex setups that will make alsa switch automatically when plugging in usb devices. the wiki:
http://alsa.opensrc.org/.asoundrc

what sort of sound related commands are available to you in android any way? Can you try these in the terminal?

aplay -l
amixer
alsamixer

aplay -l is specifically useful for determining the names of your hardware to configure alsa correctly (you should use names such as USB Audio Codec rather than HW 1,0 values).

OK well this is very interesting. I'm off to check what's been made available to android so far...
The alsa-utils package was the first thing I tried when attempting to make this work and while it can be compiled and successfully used to play and record audio it cannot be used to make configuration changes that are respected by the Android audio system.


Quote:
Originally Posted by henrylar View Post
This is exactly what I am looking for. I have just got my N7, isn't even rooted yet. But I am going to try this out in a few days, and test it with the FIIO E17, which is why I bought the N7.

It will take a few days before I have access to a windows computer for the rooting, but then I will come back with my experience of it.
Sounds good - let me know how it goes . I have personally tested an E7 and it works fine, the E17 I believe needs to have USB charging disabled or it draws too much power.

Just a small note - I have had some people getting UI crashes after replacing the services file. As mentioned above I am working on moving things into a separate service which should solve compatibility issues across different roms.

The Following 4 Users Say Thank You to jacknorris For This Useful Post: [ Click to Expand ]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes