Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input from 20+ microphones

I've been asked (if it's possible) to write a program monitoring the input of at least 20 microphones, on a single computer.

Currently I'm prototyping in python (2.6), on a Ubuntu system using Alsa. My attempts so far have created quite a few questions...

Ubuntu is a requirement, Alsa isn't, and python is an ideal.

For hardware, one suggestion is multiple sound cards. The other is a series of usb hubs and microphone adaptors (like these) (In which case the devices would all be identical and on the same USB bus)

Questions:

How can I simultaneously record multiple microphones from a single sound card? (e.g. using line-in as well as mic, bonus for anyone who know how I can use more than just two inputs!)

In the USB setup, how can I identify which position a sound card (usb adapter) in plugged in to a USB hub (or chain of USB hubs).

If a solution is raw access to the microphones via USB, is a devices position on a usb bus depend only on which port on a USB hub they are plugged into, or do could it change between powering the computer on and off?

Last, if using raw access, how do I best get the data (no current experience with pyUSB) and what conversion (if any) is required from raw -> audio?

Edit:

By monitor, I've been asked to record input to disk (ideally above a set threshold, which the speex codec looks ideal for), monitor volume levels, provide graphic feedback and set up at least one output that cycles through all active microphones.

Python isn't a long term requirement, just the easiest way I've found so far to get the PCM data from a sound card (microphone only however)

I am intending to have the polling of the soundcards and data processing take place in separate threads, an area that I haven't got much experience with.

Where would I find more information on implementing a USB audio class driver?

like image 711
Paul O'Reilly Avatar asked Jun 23 '10 02:06

Paul O'Reilly


People also ask

How many mic inputs do I need?

Only a 1-input audio interface is needed for recording one sound source at a time. For one musician but two sources e.g. vocals and guitar, 2 inputs are required. For a drum set, a minimum of 8 is recommended. A full band requires at least 8, going up to 16 if the band has a full drum set.

What is the input of a microphone?

As for inputs, microphones are not designed to receive any analog (AC voltage) or digital audio signals. Instead, microphones react to the sound waves (changing sound pressure level) around their diaphragms. This mechanical wave energy is the “inputted information” of a microphone.

How do you use multiple mic inputs?

All you have to do is connect the microphones (and any other input) to the mixer with XLR cables. Then, connect the mixer to your laptop through a USB cable. It's that easy!

Can you run two microphones one input?

In music, recording, or conferencing applications, it is not recommended to parallel microphones into a single mixer input.


2 Answers

The definition of "monitor" is a very big variable here. Monitor could mean "record to disk", "detect volume levels above a particular threshold" or "perform higher level analysis in the frequency domain (i.e. conventional signal processing)." These three have very different implications for CPU usage and the feasibility of Python. Python may not be the best fit depending on what you want to do.

If you go with Python, I'll note the following:

  • Python's audio support is very weak
  • The python ALSA bindings (pyalsa) are for sequencer, mixer and hardware control, not reading PCM samples (though the bindings might be helpful for managing the devices)
  • Python has issues in certain multi-threaded conditions (cf. the GIL — the Global Interpreter Lock) which can be avoided entirely by having separate Python processes but this is not desirable in all cases either (I'm presuming that you are running on a multi-core/processor system and want to divide the load of monitoring the 20 audio inputs across the CPUs).
  • CPU and memory intense operations such as one would expect in audio analysis is not Python's strong suit. Having said that, PCM data could be unpacked via struct.unpack() and signal analysis could be done with routines found in NumPy and SciPy.

Each line input and mic should be stereoscopic, effectively providing two mic inputs each, that's four mic's per sound card. Assuming just 20 inputs that means five USB audio adapters. BTW, to use line-in you'll need some sort of mic pre-amp which might be more pricey than you'd want. In that case, you would need 10 USB audio adapters for 20 inputs.

I would caution that most low-end hubs will probably not be able to handle the traffic for 5-10 audio adapters. For that matter, I'd be sure that you had a USB 2.0 Highspeed hub (even if the actual audio devices are USB 1.1 full-speed or slower) to be sure you have enough upstream bandwidth. If you have the option, it is not hard to get PCI USB adapter cards with 4 or 5 external USB ports. BTW, the USB device you show only has stereo-out and mic-in (no line-in).

BTW, ideally you'd use USB isochronous transfer mode to have low latency and consistent delivery but I doubt that the ALSA drivers support it.

Regarding the logical to physical mapping of USB sound cards, a set of udev rules would allow you to give a useful and consistent device naming scheme based on the USB heirarchy or, if you wanted, serial numbers (if the devices have them) or other attributes. In any case, you should be able to use udev rules to stabilize the mapping of audio devices by their identity or their physical location (as you choose).

I know nothing about pyUSB but do see that it supports isochronous transfer mode. At a glance pyUSB would allow for very precise control but I suspect you'll do way more coding that you set out to do (you'd basically need to implement the better parts of a USB audio class driver in Python).

Hope that helps!

like image 171
Aaron Avatar answered Oct 13 '22 00:10

Aaron


For hardware, one suggestion is multiple sound cards. The other is a series of usb hubs and microphone adaptors (like these)

Those are also multiple sound cards: each one presents a USB Audio Device Class interface, independently clocked, which may cause you problems if you're trying to sync them.

I've never attempted to run anything like 20 of them at once, but my feeling is it's going to be highly unreliable. These things are cheap consumer kit that aren't designed for that kind of usage; though you wouldn't be troubling USB 2.0's bandwidth limit with them I think they'll stop working reliably long before that. For what it's worth the particular model you linked to has extremely poor reviews.

If you can, consider higher-end sound cards with multiple inputs. For example the Delta-1010LT is reasonably priced and apparently supported by ALSA. There are quite a few more 8+-input possibilities with external boxes (USB, Firewire, RME's stuff); ESI make a 16-input rack, but the driver situation for ALSA looks doubtful.

A single, synchronised device from which you can pull multiple channels of audio input in one go will be much easier to cope with than lots of separate soundcards. You still probably wouldn't want to be fiddling with the samples directly in Python, but you could hook up a higher-level processing/analysis toolkit to Python with something like PySndObj.

like image 32
bobince Avatar answered Oct 13 '22 00:10

bobince