Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android (Java) Real-time Audio Input (microphone AND USB) and Output

I would like to build an Android App to take audio data from two microphones, mix the sound with some from memory, and play the sound through headphones. This needs to be done in real-time. Could you please refer me to some tutorials or any references, for real-time audio input, mixing, and output with Java eclipse?

So far, I am able to record sound, save it, and then play it, but I cannot find any tutorials for real-time interfacing with sound-hardware this way.

Note: One microphone is connected to the 3.5 mm headphone jack of the Android through a splitter and the other is connected through a USB port.

Thanks!

like image 488
user1854928 Avatar asked Nov 26 '12 23:11

user1854928


People also ask

Can you use external mic with Android?

If your Android has a headphone jack and doesn't need an adapter, then you can plug in a microphone with a 3.5mm TRRS connector jack, like this one! If you are using an app that requires permission to use external devices, ensure that you grant the app permission to do so.

How do I change my microphone settings on my Android?

Settings. Tap Site Settings. Tap Microphone or Camera. Tap to turn the microphone or camera on or off.


1 Answers

There are two issues that I see here:

1) Audio input via USB.
Audio input can be done using android 3.2+ and libusb but it is not easy (You will need to get the USB descriptors from libusb, parse them yourself and send the right control transfers to the device etc). You can get input latency via USB in the order of 5-10 mS with some phones.

2) Audio out in real-time. This is a perennial problem in Android and you are pretty much limited to the Galaxy Nexus at the moment if you want to approach real-time (using Native Audio output). However, if you master the USB you may be able to output with less latency as well.

I suppose if you go to the trouble of getting the USB to work, you can get a USB audio device with stereo in. If you had connected one mono mic to each of the input channels, then output via USB you would be very close to your stated goal. You might like to try "USB Audio Tester" or "usbEffects" apps to see what is currently possible.

In terms of coding the mixing and output etc, you will probably want one thread reading each separate input source and writing to a queue in small chunks (100-1000 samples at a time). Then have a separate thread reading off the queue(s) and mixing, placing the output onto another queue and finally a thread (possibly in native code if not doing output via USB) to read the mixed queue and do output.

The following Link http://code.google.com/p/loopmixer/ has a flavor for dealing with the audio itself.

like image 81
hack_on Avatar answered Sep 28 '22 06:09

hack_on