Search code examples
androidaudiousbsensorsmicrophone

How do I get Data from a USB acceleration sensor that pretends to be a Mircophone?


this is my first app and I'm trying to get data from a sensor.
The sensor is a Digiducer and according to their website it uses generic USB Audio Drivers.

No drivers or DLL’s required! USB Audio drivers are standard in most operating systems (iOS, Windows, MacOS, Android) LINK

I've read the USB Digital Audio Article and it says that I don't need any specific driver to be installed, if the device is class compliant (which it claims to be).

The term driverless is a common synonym for class compliant, indicating that it is possible to use the standard features of such a peripheral without requiring an operating-system specific driver to be installed. LINK

I checked all conditions mentioned in the chapter Android support for USB audio class and the sensor matches them perfectly

Android 5.0 (API level 21) and above supports a subset of USB audio class 1 (UAC1) features:
- The Android device must act as host
- The audio format must be PCM (interface type I)
- The bit depth must be 16-bits, 24-bits, or 32-bits where 24 bits of useful audio data are left-justified within the most significant bits of the 32-bit word
- The sample rate must be either 48, 44.1, 32, 24, 22.05, 16, 12, 11.025, or 8 kHz
- The channel count must be 1 (mono) or 2 (stereo)

I don't understand what I have to do, to get the data from my sensor.


Solution

  • I figured it out by myself. Actually I had to do nothing.
    I just had to call the AudioManager and search for the device name in the input devices

        AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        AudioDeviceInfo[] adiArray = am.getDevices(1); // INPUT_DEVICES = 1
    
        for (AudioDeviceInfo deviceInfo : adiArray) {
            String name = deviceInfo.getProductName().toString().toLowerCase();
            if (name.contains("33d01")) {
                externalMic = deviceInfo;
                break;
            }
        }