Author Topic: Bass for Android USB sound card support?  (Read 753 times)

aterial

  • Posts: 3
Bass for Android USB sound card support?
« on: 7 Dec '19 - 04:07 »
Heya, i'm working on a project that requires multiple audio outputs. I'm using Unity Game Engine as the frontend on Android Marshmallow, and it's running on an ASUS TinkerBoard. I've been using a USB sound card (Sewell 7.1 CM6206 based card) and can confirm it works properly on linux when building Unity for Linux. Unfortunately, when making an android build, Bass seems unable to find the sound card at all. Here's the code i've been using to get all sound devices.

Code: [Select]
log.Log($"Checking all available playback devices");
        var deviceInfos = Bass.BASS_GetDeviceInfos();
        log.Log($"There are {deviceInfos.Length} devices");
        int deviceIndex = 0;
        foreach (var device in deviceInfos)
        {
            log.Log($"Device {device.id} en : {device.IsEnabled}, def : {device.IsDefault}, type : {device.type}, drv : {device.driver}");
            if (!device.IsEnabled) continue;

            log.Indent();
            {
                bool initialized = Bass.BASS_Init(deviceIndex, 44100, BASSInit.BASS_DEVICE_SPEAKERS, IntPtr.Zero);
                if (initialized)
                {
                    var deviceInfo = Bass.BASS_GetInfo();
                    log.Log($"Init success! {deviceInfo.freq}hz spkcnt {deviceInfo.speakers}");
                    Bass.BASS_Free();
                }
                else
                {
                    var error = Bass.BASS_ErrorGetCode();
                    log.Log($"Init fail! eCode = {error}");
                }
               
            }
            log.Outdent();

            deviceIndex++;
        }

        var recordDeviceInfos = Bass.BASS_RecordGetDeviceInfos();
        log.Log($"There are {recordDeviceInfos.Length} recording devices");
        deviceIndex = 0;
        foreach (var device in recordDeviceInfos)
        {
            log.Log($"RDevice {device.id} en : {device.IsEnabled}, def : {device.IsDefault}, type : {device.type}, drv : {device.driver}");
            if (!device.IsEnabled) continue;

            log.Indent();
            {
                bool initialized = Bass.BASS_RecordInit(deviceIndex);
                if (initialized)
                {
                    var deviceInfo = Bass.BASS_RecordGetInfo();
                    log.Log($"Init success! {deviceInfo.freq}hz spkcnt {deviceInfo.Channels}");
                    Bass.BASS_RecordFree();
                }
                else
                {
                    var error = Bass.BASS_ErrorGetCode();
                    log.Log($"Init fail! eCode = {error}");
                }

            }
            log.Outdent();

            deviceIndex++;
        }

This code properly finds the USB sound card on linux, but in android i get nothing at all. Running the code without the USB card plugged in finds 4 playback devices. When plugging in the USB card, Bass still only finds 4 playback devices. Is there something obvious i'm missing? Or is Bass on Android unable to work at all with USB sound cards?

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: Bass for Android USB sound card support?
« Reply #1 on: 9 Dec '19 - 17:41 »
It isn't currently possible to set which device BASS uses on Android. It always uses the primary output device, which will usually automatically switch to a USB soundcard when one is connected. Is it not switching in your case?

Android's OpenSLES API has no way to set which device is used but the newer AAudio API (which recent BASS builds support) does, so it may be possible to add support for using multiple devices in future. One issue is that an AudioManager instance is needed to enumerate devices, which I don't think BASS can get without some assistance from the app. Perhaps a BASS_SetConfigPtr option can be used for that.

aterial

  • Posts: 3
Re: Bass for Android USB sound card support?
« Reply #2 on: 9 Dec '19 - 23:55 »
I assumed it didn't switch since the log output for when the USB card was plugged in and when it wasn't plugged in was the same
Code: [Select]
Checking all available playback devices
There are 4 devices
Device en : true, def : true, type : BASS_DEVICE_NONE drv :
    Init success! 0hz spkcnt 0
Device en : true, def : true, type : BASS_DEVICE_NONE drv :
    Init success! 96000hz spkcnt 2
Device en : true, def : true, type : BASS_DEVICE_NONE drv :
    Init success! 96000hz spkcnt 2
Device en : true, def : true, type : BASS_DEVICE_NONE drv :
    Init success! 96000hz spkcnt 2
96000hz 2 speakers seems like the analog audio output for the TinkerBoard (the analog audio jack). The usb card i'm currently using has support for 192000hz 8 speakers, and I can confirm with tinypcminfo that the card is correctly detected as such by ALSA, unfortunately no matter what I do, i can never get 192000hz 8 speakers to come up in the log.
To elaborate a little bit more on the project, I either need to be able to output to multiple audio devices (output to both the Audio Jack and the USB card with 2 channels) or to output in multichannel (at least 6 channels of the USB sound card). If that's not possible I can always move the audio processing from the tinkerboard to a separate helper RPi that's running linux.

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: Bass for Android USB sound card support?
« Reply #3 on: 10 Dec '19 - 13:02 »
Is there a newer Android version available for the device? AAudio support (available on Android 8 or above) is required for more than stereo output.

aterial

  • Posts: 3
Re: Bass for Android USB sound card support?
« Reply #4 on: 10 Dec '19 - 13:32 »
Doesn't look like it unfortunately, and I dont think I have enough experience with that to even attempt that. Seems like i'll stick to the original plan of putting the audio processing on the helper RPi. Thanks for confirming the stereo output stuff, couldn't seem to find a definitive reference that said AAudio is necessary for more than stereo.