1

I have been wondering, on how to capture Audio inputs through USB in Android.

My scenario is to receive audio through external hardware and play that received audio through android app. This transmission is to be done over USB.

Is there any way to do this using Android SDK / Android NDK.

Any suggestion will be helpful to me.

Task Done Right by time I am able to interact with Hardware using CDC class and also able to play some random noisy audio through USB in my app. Neither I am able to get clear sound by that approach, nor there is consistency within the transmission of audio.

Thanks.

Regards, Vivek

AndroidHacker
  • 3,596
  • 1
  • 25
  • 45
  • What is the external hardware you are using? Is it USB headset or some other audio device? Or is it a hardware of your own? If the latter is the case what is the USB chip/SW used in it? Since your question does not reveal your level of understanding on USB, those are important to know in order to ensure the answer is in line what you are doing. – diidu Feb 17 '17 at 11:01
  • I am trying to get FM radio audio over my android application. Here FM radio is a chip that will be attached to USB port of android device. For more refer : https://play.google.com/store/apps/details?id=kr.co.tvongo.tivizen.darshantvongodvbt2dongle&hl=en – AndroidHacker Feb 17 '17 at 11:03
  • Ok. If you don't implement the USB dongle yourself, but use some existing HW (e.g. https://www.adafruit.com/product/1497) it is important to find out what USB classes the device contains and implement (or hopefully just use) driver for those. One way to find out information about the dongle is to plug it in to windows PC and use e.g. this: http://www.nirsoft.net/utils/usb_devices_view.html or this: https://msdn.microsoft.com/en-us/library/windows/hardware/ff560019(v=vs.85).aspx to discover the device class(es) it implements. Most likely there is audio class. – diidu Feb 17 '17 at 11:41
  • Actually I am not able to find any USB Audio class implementation at Android end i.e. What Audio Class Callbacks is to be used to receive Audio data from hardware etc .? – AndroidHacker Feb 17 '17 at 11:46
  • If working on that level, you probably need to go to NDK. Only if Android detects your dongle as Audio device, you can use Java level, I think. If the dongle does not have things that are listed under "Host mode" here: http://source.android.com/devices/audio/usb.html it will not be supported by default. – diidu Feb 17 '17 at 12:04
  • @diidu : Thanks for your patience and cooperation. Will check this and update you accordingly. – AndroidHacker Feb 17 '17 at 12:05
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/135956/discussion-between-androidhacker-and-diidu). – AndroidHacker Feb 17 '17 at 12:06

1 Answers1

3

Most modern Android devices can act as USB host. So you can connect e.g. USB microphone for capturing the audio. Android also contains support for usb_audio class. Use that to get access to the audio on the device.

Since you have already experimented with Communication Device Class (CDC), you are aware of Android's USB host functionality. Now you need to ensure your peripheral has implemented USB audio class (the audio source part) and make your app to use the audio class to obtain the audio. This pretty well explained here, so it does not make sense to copy all the information to this post. If you are already using audio class, that page may explain some of the issues you have (e.g. using wrong format).

USB Audio class specifications can be found at USB.org website. The problem with those is that Audio class is pretty large and Android probably does not support everything.

diidu
  • 2,823
  • 17
  • 32
  • Thanks for the revert. Till time I was sending audio data over CDC profile itself. Was wondering if we could use USB Audio class using JAVA or we need to code that part using native NDK / C++ code. Will get great if you could assist me over the USB Audio class part. – AndroidHacker Feb 17 '17 at 09:19
  • 1
    Last I worked with USB Audio was with Symbian, so I may not be able to easily help with all Android related details. It is probably possible to transfer audio also over CDC, but the quality will not be great and you will need to find a way to package the audio to USB frames properly. Isochronous endpoints used in Audio class are designed for high bandwidth streaming, so that is much better. As fas as I understand, if your have an Android device that already supports relevant parts of USB Audio class (can use USB mic) you can work at Java level, unless you need more control and high quality. – diidu Feb 17 '17 at 09:42
  • Thanks for the revert once again. Will go with all your suggestions. Hope to resolve issue with that. – AndroidHacker Feb 17 '17 at 09:45