BASS for iOS (iPhone/iPad)

Started by Ian @ un4seen,

Fischert

Hi mdaskal,

That sounds very interesting! Pls. keep me informed!!

Best regards
Thomas

mdaskal

Quote from: FischertHi mdaskal,

That sounds very interesting! Pls. keep me informed!!

Best regards
Thomas

Hi Thomas,
We could finalize the integration of the BASSMIDI library into an AUv3, and it works perfectly well!
Best wishes
 

Fischert

Hi mdaskal,

Congratulations!!

Is it possible to get that AUv3?

Best regards
Thomas

Dorian

Can't access the sample app and I can't seem to #import or #include the bass.h file into an iOS objective c code.


Quote from: DrummerBOkay, here is a sample app, demonstrating how to make BASS play back music in the background, and control playback with the multitask bar controls. Actually the app can also be remote controlled with some 3rd party iPhone accessories and speakers.

http://cl.ly/4513342M223M3v0s2Y3T

ECSalute

Additional setup steps (may be useful for other people)
> Drag bass.h into your project
> OPTIONAL : create a Header.h file and #include bass.h
> Link your header file with your project (Objective C bridging Header)
> Build
> OPTIONAL : Abilitate "Allow Arbitrary Loads" in "App transport security settings"

With this bass works with my project

mdaskal

Quote from: FischertHi mdaskal,

Congratulations!!

Is it possible to get that AUv3?

Best regards
Thomas

Hi Thomas,

We finally could take the time to publish a repository on Github with our AUv3 Audio Unit embedding the BASSMIDI player.
For those interested you can find it here:
https://github.com/newzik/BassMidiAudioUnit

Any suggestions or feedback are welcome !
Best,

rrhh_fx

Hi,

I am trying to integrate the Bass 2.4 library in a Swift iOS project in Xcode 14.1 with a MacBook Air M1 with no success. The steps are next:

1) In General -> Frameworks, libraries and Embedded Content, click on the "+" button and add the Bass xcframework library (plus the rest of required frameworks indicated in the OP)
2) In Build Phases -> Link binary with libraries -> Status required
3) In Build Settings -> Enable bitcode -> "No"

If trying to use the lib in a Swift file using "import BASS" sentence at the top, always the "not such module 'BASS'" is showing.

Any help is appreciated

Ian @ un4seen

I'm not a Swift user myself, so I'm not sure if there's a better way to do it, but I believe you need to create a "bridging header" to use C framework/library headers. For example, create a "bridging-header.h" file containing this:

#include "bass.h"
// #include any add-on headers here too...

And then set "Objective-C Bridging Header" to "bridging-header.h" in your project's settings. The BASS header(s) should be placed alongside it (or somewhere in the header search path).

Btw, with the switch to dynamic libraries in BASS 2.4.17, any dependency frameworks can be (and are) specified in the BASS libraries themselves, so there's no need to include them to your project's settings any more.

rrhh_fx

Quote from: Ian @ un4seenI'm not a Swift user myself, so I'm not sure if there's a better way to do it, but I believe you need to create a "bridging header" to use C framework/library headers. For example, create a "bridging-header.h" file containing this:

#include "bass.h"
// #include any add-on headers here too...

And then set "Objective-C Bridging Header" to "bridging-header.h" in your project's settings. The BASS header(s) should be placed alongside it (or somewhere in the header search path).

Btw, with the switch to dynamic libraries in BASS 2.4.17, any dependency frameworks can be (and are) specified in the BASS libraries themselves, so there's no need to include them to your project's settings any more.

Thank you Ian. The bridging header works nice


reb

I'm getting an exception that I can't figure out how to handle. It's in an app that we've been distributing for years.
Here is the trace (attached png)

I tried catching the exception but it doesn't appear to be working:

Debug.WriteLine("pause called");
try
{
   Bass.BASS_Pause();
}
catch (Exception ex)
{
   Debug.WriteLine(ex.Message);
}

Ian @ un4seen

That's strange. To get more info on the problem, is it possible to disable Mono/Xamarin's exception handling and let the OS catch the crash instead to generate a native crash report? Please also confirm what BASS version you're using (with BASS_GetVersion), and try upgrading if it isn't the latest.

reb

Quote from: Ian @ un4seenThat's strange. To get more info on the problem, is it possible to disable Mono/Xamarin's exception handling and let the OS catch the crash instead to generate a native crash report? Please also confirm what BASS version you're using (with BASS_GetVersion), and try upgrading if it isn't the latest.
GetVersion returns:
33820417

I don't see in Visual Studio for Mac where to disable Xamarin's exception handling.
I'm going to try generating a beta with full symbols. I can't get the crash to happen in a simulator, only on a real device with CarPlay when there is that route change it appears.


Ian @ un4seen

33820417 is 2.4.15.1, which is quite old. So please do also try upgrading to the latest BASS version and see if you still have the problem then.

reb

Quote from: Ian @ un4seen33820417 is 2.4.15.1, which is quite old. So please do also try upgrading to the latest BASS version and see if you still have the problem then.
From what I can tell the current releases use dynamic libs instead of static libs. Is that the case?
If so, is there somewhere you can point me to with regards to how to implement those?

Ian @ un4seen

Yes, the iOS BASS libraries are now dynamic (in an XCFramework) rather than static. First remove the old static library(s) from your Xcode project's "Frameworks, Libraries, and Embedded Content" section (also check the "Build Phases" to be sure), and then add the new XCFramework(s) and set it to "Embed & Sign".

reb

#1490
Quote from: Ian @ un4seenYes, the iOS BASS libraries are now dynamic (in an XCFramework) rather than static. First remove the old static library(s) from your Xcode project's "Frameworks, Libraries, and Embedded Content" section (also check the "Build Phases" to be sure), and then add the new XCFramework(s) and set it to "Embed & Sign".
The project is in Visual Studio for Mac using Xamarim mono. I assume it will be similar.
In the project settings under additional arguments I currently have:
-cxx -gcc_flags "-L${ProjectDir}/Bass/ -framework accelerate -framework AudioToolbox -framework CoreMIDI -force_load ${ProjectDir}/Bass/libbass.a -force_load ${ProjectDir}/Bass/libbassmix.a -force_load ${ProjectDir}/Bass/libbassflac.a -force_load ${ProjectDir}/Bass/libbass_mpc.a -force_load ${ProjectDir}/Bass/libbasswv.a -force_load ${ProjectDir}/Bass/libbassdsd.a "

Ian @ un4seen

You could try replacing those "-force_load" options with "-framework", eg. "-framework bass". And "-L${ProjectDir}/Bass/" with "-F${ProjectDir}/Bass/".

rrhh_fx

In Swift, to produce a noteOn event, next sentence is used:

BASS_MIDI_StreamEvent(stream, channel, DWORD(MIDI_EVENT_NOTE), DWORD(makeWord(midiNote, Int(speed))))
However, when trying to use the MIDI_EVENTS_NOTE_OFF using next sentence:

let a = BASS_MIDI_StreamEvent(stream, DWORD(channel), DWORD(MIDI_EVENT_NOTESOFF), DWORD(0))
the note played in first sentence is not stopped as expected. Or if used after a MIDI_EVENT_SUSTAIN On event, notes are not stopping as expected. The previous approach is working in Android with no issues, and the return of MIDI_EVENT_NOTESOFF in this case is true. Simply, notes are not stopping. What can be happening? Thanks

Ian @ un4seen

MIDI_EVENT_NOTESOFF (cc#123) releases all keys but it doesn't necessarily stop the notes. When sustain (cc#64) is switched on, the notes won't be released until that's switched off. Even when a note is released, it might not stop immediately due to its envelope in the soundfont. If you would like to immediately stop all notes then you can use MIDI_EVENT_SOUNDOFF (cc#120) instead.

If this doesn't explain what you're seeing then please provide a call/event sequence to reproduce the problem with. I tried a MIDI_EVENT_NOTE followed by a MIDI_EVENT_NOTESOFF (as above) and that seemed to be working fine, ie. the note was released and it faded-out according to its envelope.

rrhh_fx

Quote from: Ian @ un4seenMIDI_EVENT_NOTESOFF (cc#123) releases all keys but it doesn't necessarily stop the notes. When sustain (cc#64) is switched on, the notes won't be released until that's switched off. Even when a note is released, it might not stop immediately due to its envelope in the soundfont. If you would like to immediately stop all notes then you can use MIDI_EVENT_SOUNDOFF (cc#120) instead.

If this doesn't explain what you're seeing then please provide a call/event sequence to reproduce the problem with. I tried a MIDI_EVENT_NOTE followed by a MIDI_EVENT_NOTESOFF (as above) and that seemed to be working fine, ie. the note was released and it faded-out according to its envelope.

In my case, Sustain is switched on, and then a note from a SF with a sample with infinite loop is played. That sound will be played continuously. When MIDI_EVENT_SOUNDOFF is triggered, instead of follow its envelope (that also is contained) until the sound is faded out, the sound keeps playing with no changes, like if the command was not sent (and it is returning true). In Android I do the same (the same SF, and the same commands and it is working as expected). I have tried with several SF2 files.

MIDI_EVENT_SOUNDOFF is working fine, but as you say, it cuts sound and does not keep the SF curve.

BASS and BASS_MIDI versions are 2.4.17.0 and 2.4.14.1 respectively. Thanks!

Ian @ un4seen

Quote from: rrhh_fxIn my case, Sustain is switched on, and then a note from a SF with a sample with infinite loop is played. That sound will be played continuously. When MIDI_EVENT_SOUNDOFF is triggered, instead of follow its envelope (that also is contained) until the sound is faded out, the sound keeps playing with no changes, like if the command was not sent (and it is returning true). In Android I do the same (the same SF, and the same commands and it is working as expected). I have tried with several SF2 files.

I guess you meant to write MIDI_EVENT_NOTESOFF rather than MIDI_EVENT_SOUNDOFF? Are you also switching sustain off sometime after that? No notes will be released until then. Individual note-off events (MIDI_EVENT_NOTE with vel=0) don't release notes when sustain is on, and MIDI_EVENT_NOTESOFF is a note-off event for all keys.

It's strange if you're seeing different results on iOS and Android, as the processing is basically the same on all platforms. Please confirm with BASS_MIDI_GetVersion that you're using the same version in both cases.

rrhh_fx

Quote from: Ian @ un4seen
Quote from: rrhh_fxIn my case, Sustain is switched on, and then a note from a SF with a sample with infinite loop is played. That sound will be played continuously. When MIDI_EVENT_SOUNDOFF is triggered, instead of follow its envelope (that also is contained) until the sound is faded out, the sound keeps playing with no changes, like if the command was not sent (and it is returning true). In Android I do the same (the same SF, and the same commands and it is working as expected). I have tried with several SF2 files.

I guess you meant to write MIDI_EVENT_NOTESOFF rather than MIDI_EVENT_SOUNDOFF? Are you also switching sustain off sometime after that? No notes will be released until then. Individual note-off events (MIDI_EVENT_NOTE with vel=0) don't release notes when sustain is on, and MIDI_EVENT_NOTESOFF is a note-off event for all keys.

It's strange if you're seeing different results on iOS and Android, as the processing is basically the same on all platforms. Please confirm with BASS_MIDI_GetVersion that you're using the same version in both cases.

My apologies. I indeed meant to say MIDI_EVENT_NOTESOFF. If sustain is switched off after that, then the notes are released correctly. I understand your point about MIDI_EVENT_NOTESOFF, suggesting that actually the behavior on the Android version might not be working as expected. I will double-check the behavior on Android and confirm that the versions are the same before getting back to you. Thank you, Ian.