[MOD] USB Audio Support

Search This thread

jacknorris

Senior Member
Nov 8, 2010
55
83
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
wink2.png


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.
 
Last edited:

bobmorane83

Member
Nov 2, 2012
6
0
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

Senior Member
Nov 8, 2010
55
83
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!
 
  • Like
Reactions: Ssyyddii

bobmorane83

Member
Nov 2, 2012
6
0
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

Member
Feb 8, 2011
18
5
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

New member
Dec 5, 2012
2
1
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!
 
  • Like
Reactions: wildzero

bbop

Member
Nov 7, 2010
42
3
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

Senior Member
Feb 8, 2008
211
41
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.
 

jacknorris

Senior Member
Nov 8, 2010
55
83
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.


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.


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 :good:. 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.
 
Last edited:

henrylar

Senior Member
Feb 8, 2008
211
41
My first initial test did not work.

What i have done: I rooted the device ( so I am in standard rom 4.2.1) installed the trinity kernel, and your two zip files ( and the trinity instead of the CM10 kernel). No sound in the FIIO yet. Is there something I have missed? Do I need to also install another ROM - I thought that the trick was the kernel.

I will be willing to test what you like, so can you give me an advice of what to try?
 

henrylar

Senior Member
Feb 8, 2008
211
41
my next try was to install cm - I took the newest version, which apparently was a mistake. The installation went fine, but when I added the audio mod, it got stuck in the startup cm animation. Just to clarify - the CM version you are using is it a 4.2.1?
 
Last edited:

JS11

New member
Mar 11, 2012
1
0
Same here:

  • stock rom 4.2.1
  • rooted;
  • latest trinity kernel
  • flashed both zips
  • sound either works over speakers or over usual headphone jack but not over DAC
  • the tested soundcard is an asus xonar u3
Thank you very much for your work. I'm highly interested in this project and a solution for my problem. If this would be implemented in CM10/AOKP it would be a great feature. Greetings from Germany
 

jacknorris

Senior Member
Nov 8, 2010
55
83
Thanks for the input.

As previously mentioned changing the entire services file is probably not the best solution as you have seen it has caused a few roms to stop responding. As for things not working entirely I am not sure yet.

I will attach the separate service soon, providing I can get it to work reliably so you can test without having to change the services file.
If that doesn't work out I will attach a build with more logging enabled so we can workout what is going on.
 

henrylar

Senior Member
Feb 8, 2008
211
41
Thanks for the input.

As previously mentioned changing the entire services file is probably not the best solution as you have seen it has caused a few roms to stop responding. As for things not working entirely I am not sure yet.

I will attach the separate service soon, providing I can get it to work reliably so you can test without having to change the services file.
If that doesn't work out I will attach a build with more logging enabled so we can workout what is going on.

That sounds great. Can you say which version of android (CM) you working successful with ( 4.1.2, 4.2 or 4.2.1?).

All the best

Henry
 

henrylar

Senior Member
Feb 8, 2008
211
41
I can really get nothing to work. I installed a 4.1.2 rom, with the appropriate trinity, modded the asound.conf, but with no sound out.

I then also tried to but the pcm.usbdac command into a newly made asound.conf in the 4.1.2 rom, also that did not work. What am I doing wrong??
 

fristil

Member
Aug 11, 2009
16
1
Not working here either:

- M-Kernel
- 4.2.1 stock rom
- flashed both zips

USB DAC works with M-Kernel when Nexus 7 is booting with DAC connected, tested with Nuforce uDac 2 and Atoll DAC D100
Samsun S3 works on the fly, just plug in OTG and DAC and it works, remove and speaker sounds.

//Mike
 
  • Like
Reactions: danba

yukster

Senior Member
Apr 3, 2006
60
1
Tokyo
Thanks for all your hard work. It's great to see progress on this.

I tried on my Nexus 7 running the latest Faux kernel, stock 4.2.1 ROM. I plugged in a generic USB headset, with volume controls and a power on//off button. When you first plug it in, the volume buttons actually controls the Nexus 7 volume sliders! Very cool. But when you power the headset off and back on, it loses the ability.

As mentioned in the thread, hotplugging doesn't work. When you boot up with the USB headset connected, it works great.
 

CZ Eddie

Senior Member
Sep 27, 2011
6,397
2,442
Austin, TX
Hahhah, whatever you guys do... don't flash these files on a Galaxy S3 !!!

Hard bricked my phone. No display, no turn-on buzz, no download mode... nada! :eek:

Ahh well, I shoulda known better than to flash kernel files meant for an entirely different device on my S3. I just really, really wanted my S3 and CM10 to work with a DAC!
 

Top Liked Posts

  • There are no posts matching your filters.
  • 35
    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
    wink2.png


    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.
    8
    Working USB DAC solution for KitKat!

    Here's a small New Year present to all audio lovers!

    This patcher was originally developed by JackNorris and was later modified by _crue_ - many thanks!
    However, 4.4.zip patch disabled headphone functionality. So I ripped contents of WiredAccessoryManager from Timur's USB-ROM and updated 4.2 and 4.4 zips with them.

    Results:

    1. USB DAC hotplug works!
    2. Switching between internal speakers and DAC - works!
    3. Once headphones are plugged in, sound switches from speakers or DAC to them - works!
    4. No volume control for USB DAC - this requires another patch for AudioPolicyManagerBase.cpp before ROM compilation (http://xdaforums.com/showthread.php?t=2222374&page=93 post #928 - again, all credits to JackNorris). I do not have the environment to build my own ROM...

    It's strange that FineVolumeControl app is able to control DAC volume.

    As of now, it's a partial success, but hope is not lost! Please look for 1st post in this thread for instructions.

    Tested with Oxydo v15 version 1 (BTW, v1 boot failure can be caused by different SEPOLICY binary in CM11 and AOSP ROMs, binary from latest CM11 kernel works even if installed in AOSP kernel ramdisk) and CM11 nightly from 12/25.

    Credits:

    To JackNorris and _crue_ for the patcher
    To Timur Mehrvarz for his tremendous development work on USB ROM.

    Happy New Year!

    P.S. Additional info (as per recommendation from redeyedjedi)

    Java JRE 1.6 (16u45 recommended) must be installed (included SMALI binaries might not work with Java 1.7), as well as .NET v4 or v4.5

    Hotplug on boot does not work (not an issue for me) no matter which options I adjust under /sys/kernel/usbhost - I must unplug OTG cable from Nexus first.
    However, if I boot without OTG cable, then connect it without DAC and only later connect the DAC, it is detected properly.
    If I boot with OTG Y-cable (with power connected to it) and plug the DAC after boot completion it is detected properly.
    It seems that initial DAC detection routine in the kernel is affected by OTG charging patch (as Timur stated a while ago). There might be something else in his ROM to force initial DAC detection. I played with Timur's kernel during my 4.2.2 days and it did not detect DAC on boot as well when using stock ROM.
    If I boot with stock CM11 kernel, DAC is detected on boot, hotplug works, but no OTG charging (and I need it for USB peripherals)
    And there's still a volume control issue...:(

    WARNING: It seems that this patch will only work on CM11-based ROMs! It can render AOSP ROMs (such as Purity) unbootable! Please use with caution!
    8
    Just a quick update to let you guys know that I will be posting a new simpler patch method soon which will also include the option to enable volume control. I'm hoping to finish things off tonight/tomorrow.
    6
    Thanks so much for your help, if you could make a flashable version as sadly my android knowledge is somewhat limited :highfive:

    I have a flashable version already.....its what I run. just need to upload to devhost.....got a reply from showp so its all good. give me a bit....I might even be able to from my tablet......otherwise itll be tomorrow cause im not home.



    OK.......its rude to hijack a thread.....so I will take the time in the next days to do a proper thread. I'm also on my personal tablet and this particular build has 100mb of modules you don't need but it will work just fine. So please.... Save any questions for a bit till I get a chance on my desktop to do this right.

    Just install...... Apply this Ops mod....... And enjoy.! http://d-h.st/QhW
    5
    I'll submit the required patches to CM at the weekend (I promise :p) that should at least get things going for CM based ROMs.

    I am also hoping to release something based on the Xposed framework for people who either don't have a CM based ROM or don't want to change/update. Using Xposed should make the patch more compatible and stable across devices, it will also allows patching the fixed volume limitation when a USB DAC is connected. The volume patch is extremely simple when built into a ROM but it becomes tricky when patching at runtime.