简体   繁体   English

Android(Java)实时音频输入(麦克风和USB)和输出

[英]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. 我想构建一个Android应用程序来从两个麦克风中获取音频数据,将声音与一些内存混合,然后通过耳机播放声音。 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? 你可以参考我的一些教程或任何参考资料,用于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. 注意:一个麦克风通​​过分离器连接到Android的3.5毫米耳机插孔,另一个麦克风通​​过USB端口连接。

Thanks! 谢谢!

There are two issues that I see here: 我在这里看到两个问题:

1) Audio input via USB. 1)通过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). 音频输入可以使用android 3.2+和libusb完成,但这并不容易(你需要从libusb获取USB描述符,自己解析它们并将正确的控制传输发送到设备等)。 You can get input latency via USB in the order of 5-10 mS with some phones. 对于某些手机,您可以通过USB获得大约5-10 mS的输入延迟。

2) Audio out in real-time. 2)实时音频输出。 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). 这在Android中是一个长期存在的问题,如果你想实时接近(使用Native Audio输出),你现在几乎只限于Galaxy Nexus。 However, if you master the USB you may be able to output with less latency as well. 但是,如果掌握USB,您也可以以较短的延迟输出。

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. 我想如果你遇到让USB工作的麻烦,你可以得到一个带有立体声输入的USB音频设备。如果你已经将一个单声道麦克风连接到每个输入通道,那么通过USB输出你就会非常接近你的既定目标。 You might like to try "USB Audio Tester" or "usbEffects" apps to see what is currently possible. 您可能想尝试“USB Audio Tester”或“usbEffects”应用程序来查看当前可能的内容。

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). 在编码混合和输出等方面,您可能希望一个线程读取每个单独的输入源并以小块(一次100-1000个样本)写入队列。 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. 然后有一个单独的线程读取队列和混合,将输出放到另一个队列,最后一个线程(如果没有通过USB输出,可能在本机代码中)读取混合队列并输出。

The following Link http://code.google.com/p/loopmixer/ has a flavor for dealing with the audio itself. 以下链接http://code.google.com/p/loopmixer/具有处理音频本身的风格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM