BASS for iOS (iPhone/iPad)

Started by Ian @ un4seen,

Ian @ un4seen

The iOS version of the BASSMIDI 2.4.11 release is now up in the 1st post.

draenorr

#1176
Hello, I have a problem with bitRate
I'm trying to open online stream
http://radio.sosimc.ru:9000/838264aac
BASS_ChannelGetAttribute(chan, BASS_ATTRIB_BITRATE, &_bitRate)bass return me 4294967

This value returned for any AAC stream. Is this attribute unsupported for AAC or I'm made an error somewhere?

Ian @ un4seen

A BASS update to fix that problem is up now in the 1st post, so please re-download to get that.


Oleg the soundman

#1179
Has anyone had this problem?
When starting a track on iOS device from iTunes library using "ipod-library://" URL it takes 2 to 7 seconds before playback actually starts.
- tracks are usually 320 kbps AAC, without DRM, synced from iTunes on mac.
- reproduces randomly on iPhone 5S, 6S, 7+, with iOS 10.3, built on XCode 8;
- no particular track on which this happens, problem seems to disappear after 3-4 tracks, but then suddenly sometimes appears again

    DWORD flags = BASS_SAMPLE_FLOAT | BASS_ASYNCFILE;
    _sourceChannel = BASS_StreamCreateURL(iPodURL.absoluteString.UTF8String, 0, flags, NULL, NULL);

Ian @ un4seen

Is the delay in the stream creation or in starting playback, ie. in the BASS_StreamCreateURL or BASS_ChannelPlay call?

With "ipod-library://" URLs, iOS (rather than BASS) handles the file reading. I'm not entirely sure what iOS does internally with them, eg. what sort of overhead iPod library access has.

Oleg the soundman

#1181
QuoteIs the delay in the stream creation or in starting playback, ie. in the BASS_StreamCreateURL or BASS_ChannelPlay call?

With "ipod-library://" URLs, iOS (rather than BASS) handles the file reading. I'm not entirely sure what iOS does internally with them, eg. what sort of overhead iPod library access has.


Ian, I switched to using our own plugin for iPod-library URLs and problem is gone. My plugin uses AudioFile and ExtAudioFile as appropriate. Standart   BASS_StreamCreateURL seems to spend some time on locked background thread when executing BASS_StreamCreateURL(). That could be partially because once stream is created, I am often creating the second temporary stream with the same url, for analysis, and Apple documented these API as not thread - safe. So actually not BASS problem, but maybe the point for improvement.

Ian @ un4seen

BASS uses AudioFile and ExtAudioFile too when dealing with "ipod-library://" URLs, but perhaps it's doing something different to what you did. I will send you a debug version to try to locate where the delay is coming from.

Oleg the soundman

Turns out, using up-to-date BASS lib build solved my problem with delay on ipod-library resources. Thank You, Ian!

StephBel

#1184
Hello,
Apple now reject App that are listening to device lock notifications.
I can't spot with 3rd party library is making my App rejected  :(
Does BASS use com.apple.springboard.lockstate ?


Spotted, you are not the bad guy  ;D

Oleg the soundman

#1185
Quote from: StephBelHello,
Apple now reject App that are listening to device lock notifications.

Wow... Did You have this string somewhere in the code (com.apple.springboard.lockstate)? Or can they detect the fact of app listening to Springboard even if it's not simply hardcoded in?

StephBel

Yes, I made a grep and a 3rd party library was registering an observer on "com.apple.springboard.lockstate".
I think Apple is looking for the string because my App binary was rejected just after the submission.

Oleg the soundman

So, anyone had a chance to couple BASS with new Airplay2 AVSampleBufferAudioRenderer / AVSampleBufferRenderSynchronizer capability already? seems like an answer to 3-year Airplay dis-functionality for multiple devices support...

https://devstreaming-cdn.apple.com/videos/wwdc/2017/509v96e4gd96rlqyq/509/509_introducing_airplay_2.pdf
(from page 61)

Ge0rges

Hi, How can I get notified by BASS when my channel created with BASS_StreamCreateFile has finished playing the file?

Ian @ un4seen

You can set a BASS_SYNC_END sync via BASS_ChannelSetSync to get notified when playback reaches the end, something like this:

BASS_ChannelSetSync(stream, BASS_SYNC_END, 0, EndSyncProc, NULL);
BASS_ChannelPlay(stream, 0);

...

void EndSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
// do something here
}

AldoIlsant

Hi,

I am having some issues with the latest version of BASS in iOS 10.

Basically, BASS is randomly unable to detect a plugged in MIDI keyboard (we have tried several models). Sometimes it just works perfectly, but others the keyboard is never detected, no matter how many times you plug or unplug.

Here is the code for initialising the device:

   int dev;
    for (dev=0;BASS_MIDI_InGetDeviceInfo(dev,&_bassInputDeviceInfo);dev++) {
    }
    if (dev) {
        int a;
        for (a=0;a<dev;a++) {
            BASS_MIDI_DEVICEINFO info;
            BASS_MIDI_InGetDeviceInfo(a,&info);
            NSString * deviceName = [NSString stringWithCString:info.name encoding:NSASCIIStringEncoding];
            if (info.flags & BASS_DEVICE_ENABLED){ // session 1 is Core Midi network port?
                if (BASS_MIDI_InInit(a,MidiInProc,(__bridge void *)(self))) {
                    _bassMidiInputDevice=a;
                    BASS_MIDI_InStart(_bassMidiInputDevice);
                    _bassInputDeviceInfo=info;
                    break;
                }
            }
        }
    }

Thanks

Ian @ un4seen

Is the MIDI device missing from the BASS_MIDI_InGetDeviceInfo list, or is the BASS_DEVICE_ENABLED flag missing from it, or is the BASS_MIDI_InInit call failing? If you are re-enumerating the MIDI devices, how long are you waiting between each enumeration cycle? BASSMIDI will only re-enumerate the MIDI devices up to once per second, so you would need to have at least a 1 second gap to see different results.

Are you only having the problem with BASSMIDI, never with any other apps?

AldoIlsant

The device is missing from the BASS_MIDI_InGetDeviceInfo list (no devices are listed).

I am continuously checking for devices every 200ms (checking if new devices are in, checking if old devices are disabled, etc.). Good to know that the reenumeration happens once per second.

I am developing a single app that makes extensive use of BASSMIDI, so I cannot tell if the problem happens with other apps.

Some more info:

1. It seems that if you plug in the keyboard BEFORE starting the app, then it will always be enumerated.
2. I have seen this ill behaviour in iPad Pro only, while not in an old 32-bit iPad (both are running iOS 10.3.3)

Thanks

Ian @ un4seen

Google suggests that this may be a bug in the OS, where it is apparently caching the initially detected MIDI devices and not refreshing that information until the app is reloaded. Strange though that you're having the problem with one device and not another with the same iOS version installed. What do you see if you poll MIDIGetNumberOfDevices and MIDIGetNumberOfSources when adding/removing a MIDI input device? One suggestion I saw was making sure the enumeration calls are done in the main thread (not a worker thread), so you could try that if you aren't already.

AldoIlsant

When the problem happens, I see:

BASS_MIDI_InGetDeviceInfo count: 0
MIDIGetNumberOfDevices: 3
MIDIGetNumberOfSources: 0

And this does not change no matter how many times you plug or unplug.

I am already making all the calls in the main thread.

Does this help?

Thanks

Ian @ un4seen

If the numbers are never changing when (un)plugging the MIDI device, that would seem to confirm that the MIDI devices are only being enumerated once by iOS. I guess the numbers above were from when the MIDI device was not plugged in beforehand? What do you see if it is plugged in? Do you see the numbers changing on the old iPad?

Can you try some MIDI apps from the app store and see if you have the same problem with them?

AldoIlsant

Yes, the numbers above are from when the MIDI device was NOT plugged in beforehand.

I see, when the keyboard is plugged in beforehand:

BASS_MIDI_InGetDeviceInfo count: 1
MIDIGetNumberOfDevices: 3
MIDIGetNumberOfSources: 1

which makes sense.

I see the numbers changing if (un)plugging the device. Namely, MidiGetNumberOfSources changes from 1 to 0 and back to 1 (as expected I guess).

This also happens in the old iPad.

However, I have tried GarageBand and Home Concert and they DO NOT have this problem. The device is always detected even if plugged in after starting the app. This happens on both iPads.

So... there is something fishy here.

Thanks

Ian @ un4seen

Quote from: AldoIlsantYes, the numbers above are from when the MIDI device was NOT plugged in beforehand.

I see, when the keyboard is plugged in beforehand:

BASS_MIDI_InGetDeviceInfo count: 1
MIDIGetNumberOfDevices: 3
MIDIGetNumberOfSources: 1

which makes sense.

I see the numbers changing if (un)plugging the device. Namely, MidiGetNumberOfSources changes from 1 to 0 and back to 1 (as expected I guess).

This also happens in the old iPad.

OK. So MIDI device enumeration works fine on both of your iPads so long as the MIDI device is plugged in before starting the app, and it works fine on the old iPad even if the MIDI device isn't plugged in first?

Quote from: AldoIlsantHowever, I have tried GarageBand and Home Concert and they DO NOT have this problem. The device is always detected even if plugged in after starting the app. This happens on both iPads.

So... there is something fishy here.

That's strange. Perhaps they are enumerating MIDI devices in a different way (I'll try to find out if there is another way), or perhaps the device enumeration is just delayed? Do they detect when the MIDI device is unplugged (after it has been detected) and another one is plugged in?

AldoIlsant

"OK. So MIDI device enumeration works fine on both of your iPads so long as the MIDI device is plugged in before starting the app, and it works fine on the old iPad even if the MIDI device isn't plugged in first?"

That is correct

"That's strange. Perhaps they are enumerating MIDI devices in a different way (I'll try to find out if there is another way), or perhaps the device enumeration is just delayed? Do they detect when the MIDI device is unplugged (after it has been detected) and another one is plugged in?"

Right now, I cannot test with different devices. I only have one keyboard here. But I can tell you about this on Tuesday.

Thanks

AldoIlsant

UPDATE: it seems the issue IS FIXED if the following conditions meet:

1. You call Bass_Init on the main thread (I was missing this part, I was calling it from a global queue).
2. You call all the enumeration methods on the main thread (as you suggested).

Thanks! This is a great relief. But please add to the documentation!