BASS for iOS (iPhone/iPad)

Started by Ian @ un4seen,

Ian @ un4seen

Great to hear that you have got it working. I was unaware of the main thread requirement myself until Google suggested it (I don't think it's mentioned anywhere in Apple's documentation). I will add a note to the BASS_MIDI_InGetDeviceInfo documentation.

Are you sure BASS_Init needs to be called in the main thread too? I wouldn't have thought that would affect MIDI device enumeration (unless they're somehow linked internally within iOS).

AldoIlsant

"Are you sure BASS_Init needs to be called in the main thread too? I wouldn't have thought that would affect MIDI device enumeration (unless they're somehow linked internally within iOS)."

I couldn't get it to work until I moved BASS_Init to the main thread. So yes, I am sure. I think you should recommend that in Bass_Init documentation as well.

Thanks

Olek

We faced with major battery drain on iOS devices. ~20% over eight hours. I'm not sure what caused the issue but one of the guesses it's mixer channel on pause while app in background mode.
Is it possible that paused mixer channel works in background and consumes power even if user doesn't use the app?

Oleg the soundman

#1203
@Olek,
 
Mixer should not consume anything when paused, as far as I know...

Are You calling BASS_Pause() when not playing? could save some 0.5 - 1 % of CPU load when paused in foreground.

But even without this - I hardly understand how it can consume something in background since in background iOS throttles down Your app once it stops playing audio, anyway.
Please make sure that Your channels are stopped/paused and BASS is paused when not playing, because it looks like iOS is thinking that the app is still playing, when, in fact, it isn't. Also check what other means may force iOS to keep the app running even though it is in background (Geolocation, Background task, e t.c.)

I've got app (player) that uses mixer too and CPU load is 0% when paused, both in background and foreground. We too had issues with battery drain but it turned out to be the problem of app organization, not related to BASS as such.

Olek

@Oleg N,

Thanks for your reply!

I use BASS_ChannelPause() but going to try BASS_Pause() .

We use Audio and Air play background mode. It's needed feature.
I'm not sure that problem caused by BASS. But we don't have any other background tasks that might cause issue.





Oleg the soundman

#1205
@Olek,

Yes, "Audio & Airplay" is for staying alive in background for playback, but as soon as You pause playback - iOS will suddenly throttle down Your app anyway.
Why You just don't look at those gears in XCode (CPU, threads) and analyze what is eating up resources in Your case? You can see everything app consumes both in foreground and in background, playing or paused.

Ian @ un4seen

The iOS version of the new BASSFLAC 2.4.4 release is up in the 1st post.

Ian @ un4seen

The iOS version of the new BASSmix 2.4.9 release is up in the 1st post.

norbert

I'm getting BASS_ERROR_FILEOPEN for PluginLoad only on real device iOS 10.2/3, on iOS Simulator it works fine (and it worked fine for over a year on real devices too!) !

Using Xamarin.iOS and the latest libbass<xy>.a:

Suddenly, after the last Xamarin.iOS update,  the bassflac,~wv,~opus plugins can't be loaded any more on my iPad:
The return code is 0 and BASS reports "BASS_ERROR_FILEOPEN".
The libbbass itself loads correctly.  And on simulator it works fine (iOS 10.2) !

Any ideas ?

Ian @ un4seen

Please confirm how you using the BASS plugin system. Note that it's a bit different on iOS due to the fact that the BASS add-on libraries are statically linked into the app rather than dynamically loaded. I'm not familiar with how it should be done with Xamarin, but in C/C++/Objective-C, it should look something like this:

extern void BASSWVplugin;
BASS_PluginLoad(BASSWVplugin, 0);

Also confirm that the add-on libraries are being linked into your app.

norbert

Yes I can confirm this. (the call is Bass.BASS_PluginLoad("BASSFLAC")  but internally  a flag BASS_UNICODE (=-2147483648) is passed as 2nd param.

Anyway, I have not changed neither the the plugin initialisation code  nor the linking for over a year, because it always worked both on device and simulator.

The strange thing is that it still works on the simulator!

norbert

Solved: The actual problem was  that my device also got updated -  from iOS 10.2 to  10.3, which is not supported by  XCode 8.2.1.
Now I'm  using some "hack" to be able to deploy to "correctly" -to iOS 10.3.
Obviously this former incomatibilty caused some kind of "partial deployment"...probably the plugin *.a files were not included or linked incorrectly...

Ian @ un4seen

The iOS version of the BASSHLS add-on is now included in the 1st post.

Wesley

When I play an AAC streaming with a preroll I get this error:

Packet with multiple raw data blocks was found - unsupported
ScanForPackets (AAC) failed

Is there any way to fix this?

I'm using these configs:

BASS_SetConfig(BASS_CONFIG_IOS_MIXAUDIO, 0);
BASS_SetConfig(BASS_CONFIG_NET_PLAYLIST, 1);
BASS_SetConfig(BASS_CONFIG_NET_PREBUF, 0);
BASS_SetConfig(BASS_CONFIG_IOS_NOCATEGORY, 0);

Ian @ un4seen

BASS doesn't parse/decode MP4/AAC itself on iOS, but rather uses the OS's parser/decoder, so that is where that error message will be coming from. Unfortunately, that means there probably isn't much that can be done about it. If you're creating the MP4 files yourself, perhaps you can change the options that you're using to avoid the problem? Are you having the problem with a particular iOS version or is it happening with all versions?

Ian @ un4seen

The iOS version of the new BASSenc_FLAC add-on is now up in the 1st post.

norbert

I'm getting BASS_ERROR_FILEOPEN for BASSWV on a real device running iOS 11:

- Only in release mode (using the submitted .ipa via Testflight)
- It loads correctly when deploying in debug mode
- BASS itself loads correctly in release mode

So it shouldn't be a bitcode issue (I've set it to disabled, and getting not errors anyway, the app works, just plugin loading fails) ?
I've also tried disabling llvm.

What else could be the problem ? (I'm using Xamarin.iOS) ? The mtouch arguments are the same for debug and release buid, assembly linking is always set to "all".

Ian @ un4seen

I assume you're getting the BASS_ERROR_FILEOPEN error from BASS_PluginLoad. Are you having that problem only with the BASSWV add-on, or all add-ons? If it's fine in debug mode but not release mode, perhaps the linker is optimizing the BASSWV library out because you're not directly calling any functions in it? If that is the case, perhaps there is a linker option to tell it not to do that with specific libraries? If there isn't such an option, you could try adding a BASS_WV_StreamCreateFile call with an empty filename during initialization.

norbert

Yes all plugins fail to load. And I already did the trick with "BASS_WV_StreamCreateFile call with an empty filename".

But I just found that if I un-check "Strip native debugging symbols", the plugins are loaded. But normally you don't want to have debugging stuff in a relase build...and the ipa file becomes larger (about 30%)

Ian @ un4seen

That sounds like the "Strip native debugging symbols" option is removing the "BASSWVplugin" symbol, which BASS_PluginLoad will look for when you pass it "BASSWV". Perhaps you can tell the linker to keep that particular symbol?

On iOS, there are 2 ways to load plugins with BASS_PluginLoad. You can either pass the add-on's name like on other platforms, or you can pass its plugin symbol. The latter method should prevent the symbol being removed. I'm not sure how you would do it with Xamarin, but in C/C++, it can be used like this:

extern void BASSWVplugin;
BASS_PluginLoad(&BASSWVplugin, 0);

For other add-ons, you would simply replace the "BASSWV" part.

norbert

#1220
At least there is no other way of loading a plugin in the C# Wrapper library, only the one with "string filename".
However I'm also calling BassWv.BASS_WV_StreamCreateFile("", 0, 0, BASSFlag.BASS_STREAM_DECODE) after BAss.BASS_PluginLoad, so the linker sees that the type BassWv is used and it does not strip it (otherwise it would need to remove the call BassWv.BASS_WV_StreamCreateFile, too). But somehow the libbasswv.a is not included/loaded.

There is an option to tell the linker whether the native reference contains C++ code. Is there any ?

Ian @ un4seen

I'm not a .Net or Xamarin user myself, so I don't know if this is possible, but perhaps you can let it know about the plugin symbol with DllImport?

[DllImport("__Internal")]
public static extern void BASSWVplugin();

And then use that symbol somehow (don't call it - it isn't a function) to stop it being stripped.

norbert

Thanks - that did the trick ! I just put this declaration into the BassWv class. Interesting: I did not do this with the other plugins (flac, opus, I guess it would be BASSFLACplugin() ?) but suddenly they also load correctly - as if the one plugin would pull the others with it...

Ian @ un4seen

The iOS version of the new BASS 2.4.13 release is up in the 1st post.

mbh

#1224
Hi,

I'm looking into making the output frequency of an iOS streaming app user-configurable.
The app is playing through a mixer, ie. :
 
    input_stream(s) => mixer => output

the input_stream(s) will have varying sample rates.

The player pipeline has been setup for 44100:
    self.didInitBassLib = BASS_Init(-1, 44100, 0, NULL, NULL);
    self.mixer = BASS_Mixer_StreamCreate(44100, 2, BASS_MIXER_END);

As far as I can tell, I can change the outputs sample rate by using:
    -[AVAudioSession setPreferredSampleRate:error]

But what about the mixer?
Is it possible to change the mixer frequency without tearing it down, and creating a new one with the desired frequency ?

Ideally I would like to reconfigure the player while it's playing, and of course without audible artefacts.

Is this possible, or should I go for something like this ?:

    Fade out => Stop playback => reconfigure sample rate(s) => Start playback => Fade in.

Thanks
Michael.