Author Topic: BASS for iOS (iPhone/iPad)  (Read 774221 times)

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: BASS for iOS (iPhone/iPad)
« Reply #1450 on: 27 Jul '21 - 12:11 »
I initially tried to set BASS_CONFIG_IOS_SESSION to 0 for configuring audio session category to AVAudioSessionCategoryPlayback, and it didn't worked. Then I tried to set it to different values (e.g., BASS_IOS_SESSION_MIX, BASS_IOS_SESSION_DISABLE, etc.), but none of them worked.

For your information, I tried to make a new project, configured all required frameworks (Accelerate, AudioToolbox, AVFoundation, CFNetwork, SystemConfiguration), added libbass.xcframework (with setting "Embed & Sign" on the project setting panel), and added some codes in AppDelegate.swift (or AppDelegate.m for Objective-C) like this:
Code: [Select]
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  print(BASS_GetVersion())
  BASS_SetConfig(DWORD(BASS_CONFIG_IOS_SESSION), DWORD(BASS_IOS_SESSION_DISABLE))
 
  return true
}

BASS_GetVersion() worked well (i.e., the BASS library is loaded), but calling BASS_SetConfig throws an error "EXC_BAD_ACCESS (code=1, address=0x0)". The test was proceeded on the iPhone with the latest iOS (iOS 14.7) and Simulator. The latest Xcode (12.5.1) was used. Please let me know if I can provide any further information. Thanks.

Ah! I see now there is indeed a problem when trying to set BASS_CONFIG_IOS_SESSION before either BASS_Init or BASS_GetDeviceInfo/RecordGetDeviceInfo has been called. An update to fix that is up now in the first post. Please try that and let me know if you still have the problem with it.

Is there bass_midi.h file like bass.h?

I am trying to call BASS_MIDI_FontInit(...) to start with.

The C/C++ headers are the same on all platforms, so you can take the BASSMIDI.H file from one of the Win32/Linux/macOS BASSMIDI packages on the BASS webpage. The documentation can also be taken from those packages.

jnyang

  • Guest
Re: BASS for iOS (iPhone/iPad)
« Reply #1451 on: 27 Jul '21 - 13:51 »
Ah! I see now there is indeed a problem when trying to set BASS_CONFIG_IOS_SESSION before either BASS_Init or BASS_GetDeviceInfo/RecordGetDeviceInfo has been called. An update to fix that is up now in the first post. Please try that and let me know if you still have the problem with it.

The latest update works well when I try to set BASS_CONFIG_IOS_SESSION before calling BASS_Init. Thanks for your quick fix! :D

Anthony Y

  • Posts: 11
BASSMIDI.H
« Reply #1452 on: 28 Jul '21 - 01:01 »
Regarding your reply:
The C/C++ headers are the same on all platforms, so you can take the BASSMIDI.H file from one of the Win32/Linux/macOS BASSMIDI packages on the BASS webpage. The documentation can also be taken from those packages.

-----

I have downloaded bass24-osx and found bass.h but I can't find bassmidi.h anywhere. Not in bass24-ios.zip too.
Can you please provide me a link where I can download the header files? I need enc, enc_mp3 as well.

jnyang

  • Guest
Re: BASSMIDI.H
« Reply #1453 on: 28 Jul '21 - 10:53 »
I have downloaded bass24-osx and found bass.h but I can't find bassmidi.h anywhere. Not in bass24-ios.zip too.
Can you please provide me a link where I can download the header files? I need enc, enc_mp3 as well.

You can find it on the "add-ons" section of the BASS library page.
http://www.un4seen.com/bass.html#addons

Anthony Y

  • Posts: 11
Re: BASSMIDI.H
« Reply #1454 on: 28 Jul '21 - 11:58 »
I have downloaded bass24-osx and found bass.h but I can't find bassmidi.h anywhere. Not in bass24-ios.zip too.
Can you please provide me a link where I can download the header files? I need enc, enc_mp3 as well.

You can find it on the "add-ons" section of the BASS library page.
http://www.un4seen.com/bass.html#addons

Holy Moly! why didn't I see that. Thank you so much.

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: BASS for iOS (iPhone/iPad)
« Reply #1455 on: 30 Jul '21 - 17:38 »
The iOS version of the BASSHLS 2.4.3 release is up in the 1st post.

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: BASS for iOS (iPhone/iPad)
« Reply #1456 on: 23 Sep '21 - 15:14 »
The iOS version of the BASSmix 2.4.11 release is up in the 1st post.

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: BASS for iOS (iPhone/iPad)
« Reply #1457 on: 17 Nov '21 - 16:45 »
The iOS versions of BASS and the add-ons have now been moved from this thread to the BASS webpage (alongside the Win32/Linux/macOS packages), so new releases will no longer be posted in this thread (betas may still be).

jnyang

  • Guest
Re: BASS for iOS (iPhone/iPad)
« Reply #1458 on: 12 Jan '22 - 13:54 »
The iOS versions of BASS and the add-ons have now been moved from this thread to the BASS webpage (alongside the Win32/Linux/macOS packages), so new releases will no longer be posted in this thread (betas may still be).

Just a minor finding: the zipped file of BASSOPUS for iOS contains bassopus.dll instead of bassopus.h.

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: BASS for iOS (iPhone/iPad)
« Reply #1459 on: 12 Jan '22 - 14:26 »
Oops! That has been corrected now, thanks.

Ryota

  • Posts: 28
Re: BASS for iOS (iPhone/iPad)
« Reply #1460 on: 10 Feb '22 - 10:24 »
Hi Ian,

The URL obtained by getTemporaryLink of Dropbox API could be used for streaming play by BASS_StreamCreateURL.

Recently, as shown in the URL below, the Content length is no longer returned due to a specification change on the Dropbox side, so streaming play has become impossible.

https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-stopped-returning-Content-length-in-the-response-headers/td-p/575948

Is there any solution for streaming the Dropbox URL?

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: BASS for iOS (iPhone/iPad)
« Reply #1461 on: 10 Feb '22 - 17:10 »
BASS_StreamCreateURL should be able to handle streaming files without a "Content-Length" header. It will automatically apply the BASS_STREAM_BLOCK flag then, like with a Shoutcast/Icecast stream. Please PM me an example problematic URL and I'll check what's happening.

Piero

  • Guest
Re: BASS for iOS (iPhone/iPad)
« Reply #1462 on: 7 Mar '22 - 11:07 »
Hi Ian,
I have a problem using BASS in my iOS app.
The target set in the project is from iOS 11. The version of BASS used is the last available inserted according to guide.
When I run on a device with iOS 11 or 12, the app crashes in BASS_ChannelPlay, while on iOS 13 everything is ok.

I ran various tests and tried on an empty project.
This is the code:

BASS_Init(-1, 44100, 0, nil, nil);
let channel = BASS_StreamCreateURL(streamURL, 0, 0, nil, nil);
BASS_ChannelPlay(channel, false)


If I run BASS_ErrorGetCode() after each line, the error returned is always 0.

Is there any BASS compatibility issue with iOS older than 13?

Thanks

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: BASS for iOS (iPhone/iPad)
« Reply #1463 on: 7 Mar '22 - 13:29 »
Please post or send me the crash log from the device to have a look at. Also, is the problem only happening with a specific URL or file format, or all of them? Does it happen if you use BASS_StreamCreateFile to play a local file instead? If it is only happening with a private URL, you can PM it to me.

mdaskal

  • Posts: 7
Re: BASS for iOS (iPhone/iPad)
« Reply #1464 on: 9 Mar '22 - 15:03 »
Hi,
I am trying to implement a custom Instrument AudioUnit to encapsulate the BASS Midi library.
It would basically behave as a sampler, receiving midi events and throwing the sample data (BASS_ChannelGetData) to the AudioUnit's output.

Here is the basic BASS implementation I did:
Code: [Select]
BASS_Init(-1, 44100, 0, 0, NULL);
stream = BASS_MIDI_StreamCreate(1, BASS_SAMPLE_FLOAT | BASS_STREAM_DECODE, 1);
BASS_ChannelSetAttribute(_bassMidi.stream, BASS_ATTRIB_NOBUFFER, 1)

However, I get a BASS_ERROR_NOTAVAIL error when BASS_ChannelSetAttribute is called.
What have I done wrong ?

Thanks for your help !

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: BASS for iOS (iPhone/iPad)
« Reply #1465 on: 9 Mar '22 - 16:09 »
Decoding channels (with BASS_STREAM_DECODE set) don't have a playback buffer, so the BASS_ATTRIB_NOBUFFER option doesn't apply and isn't required.

mdaskal

  • Posts: 7
Re: BASS for iOS (iPhone/iPad)
« Reply #1466 on: 10 Mar '22 - 14:39 »
Thanks a lot Ian !

I have another question.
I want to copy the sample data from the BASS decoding channel to my Audio Unit output.
Here is my code :
Code: [Select]
float* data = new float[frameCount];
QWORD length = BASS_ChannelGetData(_bassMidi.stream, data, DWORD(frameCount) | BASS_DATA_FLOAT);

for (int channel = 0; channel < chanCount; ++channel) {
    // Get pointer to mutable output buffer
    float* out = (float*)outBufferListPtr->mBuffers[channel].mData;
   
    for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) {
        const int frameOffset = int(frameIndex + bufferOffset);
        out[frameOffset] = data[frameIndex];
    }
}

It doesn't seem to work, as I hear click noises instead of the midi sequence it is supposed to play...
What am I missing here ?

Thanks !
« Last Edit: 10 Mar '22 - 17:16 by mdaskal »

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: BASS for iOS (iPhone/iPad)
« Reply #1467 on: 10 Mar '22 - 17:25 »
BASS_ChannelGetData "length" parameter is in bytes, so you need to multiply by 4 (the size of a "float") in that call. It looks like you should also multiply both that and the "data" array by "chanCount". So this:

Code: [Select]
float* data = new float[frameCount * chanCount];
DWORD length = BASS_ChannelGetData(_bassMidi.stream, data, frameCount * chanCount * sizeof(float));

It won't do any harm, but there's no need to include the BASS_DATA_FLOAT flag if the channel is already floating-point (has BASS_SAMPLE_FLOAT set).

mdaskal

  • Posts: 7
Re: BASS for iOS (iPhone/iPad)
« Reply #1468 on: 10 Mar '22 - 18:42 »
Great thanks Ian !!
I implemented what you suggested.

Unfortunately the decoded sample data (retrieved with BASS_ChannelGetData) are all equal to zero.

Here is my initialization sequence :

Code: [Select]
BASS_Init(-1, 44100, 0, 0, NULL);
stream = BASS_MIDI_StreamCreate(1, BASS_SAMPLE_FLOAT | BASS_STREAM_DECODE, 1);
BASS_ChannelSetAttribute(_bassMidi.stream, BASS_ATTRIB_NOBUFFER, 1)
....
Then a Midi sequence is played by the Sequencer and MIDI events are forwarded to BASS using BASS_MIDI_StreamEvents(...)

...
Finally, in the audio Callback of my Audio Unit I read the decoded sample data as explained previously :
Code: [Select]
float* data = new float[frameCount * chanCount];
DWORD length = BASS_ChannelGetData(_bassMidi.stream, data, frameCount * chanCount * sizeof(float));

Do you see any reason why there is no output?

Thanks again !

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: BASS for iOS (iPhone/iPad)
« Reply #1469 on: 11 Mar '22 - 15:13 »
It could be that there's no soundfont loaded to provide the instrument sounds. Have you set one via either BASS_MIDI_StreamSetFonts or the BASS_CONFIG_MIDI_DEFFONT option? If you don't have a soundfont, a couple can be found on the BASS webpage (next to the BASSMIDI download).

mdaskal

  • Posts: 7
Re: BASS for iOS (iPhone/iPad)
« Reply #1470 on: 11 Mar '22 - 15:32 »
Hi Ian,

Yes I forgot to mention that I first loaded a soundfont before sending midi events :
Code: [Select]
       
HSOUNDFONT newfont = BASS_MIDI_FontInit(fontPath.c_str(), 0);
if (newfont) {
  BASS_MIDI_FONT soundfont;
  soundfont.font = newfont;
  soundfont.preset = 0;
  soundfont.bank = 0;
  BASS_MIDI_StreamSetFonts(_bassMidi.stream, &soundfont, 1)
}

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: BASS for iOS (iPhone/iPad)
« Reply #1471 on: 11 Mar '22 - 16:08 »
Try setting the BASS_MIDI_FONT "preset" value to -1 (to use the soundfont for all presets). If there's still no sound, also confirm that the BASS_MIDI_StreamSetFonts call is successful, ie. returning true.

If you will always be using a single soundfont then you could try using the BASS_CONFIG_MIDI_DEFFONT option instead of BASS_MIDI_FontInit and BASS_MIDI_StreamSetFonts:

Code: [Select]
BASS_SetConfigPtr(BASS_CONFIG_MIDI_DEFFONT, fontPath.c_str());

Fischert

  • Posts: 4
Re: BASS for iOS (iPhone/iPad)
« Reply #1472 on: 15 Mar '22 - 11:34 »
I assume the bass-implementation in iOS is embedded into the AVFoundation Framework.

So is it possible to use other e.g. Apple-AudioUnits together with the Bass-Library?

Best regards
Thomas

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: BASS for iOS (iPhone/iPad)
« Reply #1473 on: 15 Mar '22 - 17:33 »
I assume the bass-implementation in iOS is embedded into the AVFoundation Framework.

I'm not entirely sure what you mean by that. BASS does use the AVFoundation framework but I wouldn't say it's embedded.

So is it possible to use other e.g. Apple-AudioUnits together with the Bass-Library?

BASS doesn't include built-in support for using AudioUnits. I think it's still possible to use them but it would need to be implemented by the user (you). I've never tried that myself, so I'm afraid I'm unable to advise on the specifics.

mdaskal

  • Posts: 7
Re: BASS for iOS (iPhone/iPad)
« Reply #1474 on: 17 Mar '22 - 10:00 »
I assume the bass-implementation in iOS is embedded into the AVFoundation Framework.

So is it possible to use other e.g. Apple-AudioUnits together with the Bass-Library?

Best regards
Thomas

Hi Thomas,
We are currently trying to integrate the BASSMIDI library into an iOS AudioUnit.
It's not fully working yet but it's sound like it will be working fine at the end.

The basic idea is to :
1- Forward the MIDI events received in input of the AudioUnit (handleMIDIEvent() method) to the BASSMIDI library
2- Copy the output of the BASSMIDI decoding channel to the AudioUnit's output (in process(AUAudioFrameCount frameCount, AUAudioFrameCount bufferOffset))
For this last step you have to make the BASSMIDI stream a "decoding channel" by setting the BASS_STREAM_DECODE flag on it. That will allow you to generate the output as needed with BASS_ChannelGetData (instead of BASS_ChannelPlay), which you can then copy to the output buffer.

Hope that it helps !