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

Ryota

  • Posts: 17
Re: BASS for iOS (iPhone/iPad)
« Reply #1150 on: 13 Aug '16 - 06:59 »
To test on OSX, you could use the CONTEST example that's included in the BASSenc package (build it and run "./contest <filename> 5" in a Terminal window).

Thank you, I'll try this.

Is that the only time it happens? The tempo processing shouldn't have any effect on the encoding except to change the length, so that's what makes me think the issue may be length dependent. Do you get the problem even with short files? Do you never get the problem without the tempo processing? Also, what iOS version(s) are you testing on?

I'm testing on iOS 9.3.4.

Test results for each of the output file length.
* "OK" means the "moov" atom comes before the "mdat" atom. and "NG" means the "mdat" atom comes before the "moov" atom.

OK: 2sec ( input: 1sec -> output: 2sec, tempo: 50% )
OK: 120sec ( input: 60sec -> output: 120sec, tempo: 50% )
OK: 240sec ( input: 120sec -> output: 240sec, tempo: 50% )
OK: 242sec ( input: 206sec -> output: 242sec, tempo: 85% )
OK: 294sec ( input: 206sec -> output: 294sec, tempo: 70% )
OK: 307sec ( input: 206sec -> output: 307sec, tempo: 67% )
OK: 312sec ( input: 206sec -> output: 312sec, tempo: 66% )
OK: 313sec ( input: 206sec -> output: 313sec, tempo: 65.9% )
NG: 314sec ( input: 206sec -> output: 314sec, tempo: 65.7% )
NG: 315sec ( input: 206sec -> output: 315sec, tempo: 65.5% )
NG: 317sec ( input: 206sec -> output: 317sec, tempo: 65% )
NG: 343sec ( input: 206sec -> output: 343sec, tempo: 60% )
NG: 412sec ( input: 206sec -> output: 412sec, tempo: 50% )
NG: 597sec ( input: 299sec -> output: 597sec, tempo: 50% )

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for iOS (iPhone/iPad)
« Reply #1151 on: 15 Aug '16 - 17:49 »
I see what's going on now. By default, the CoreAudio AAC/MP4 encoder is reserving 57KB at the start of the file for the "moov" atom, and when it exceeds that size, it's moved to the end of the file. It is possible to change that, but BASSenc currently can't be certain in advance how much data will be encoded. I will look into adding an option for that this week.

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for iOS (iPhone/iPad)
« Reply #1152 on: 19 Aug '16 - 16:04 »
A BASSenc update that allows greater control over the CoreAudio codec is up now in the 1st post. It adds a BASS_Encode_GetCARef function to get the encoder's ExtAudioFileRef, which can be used to configure the codec. In your case, you would want to set the kAudioFilePropertyReserveDuration property, something like this:

Code: [Select]
#include <AudioToolbox/ExtendedAudioFile.h>

...

encoder=BASS_Encode_StartCAFile(...);
ExtAudioFileRef eaf=BASS_Encode_GetCARef(encoder); // get encoder's ExtAudioFileRef
AudioFileID afid;
UInt32 s=sizeof(afid);
if (!ExtAudioFileGetProperty(eaf, kExtAudioFileProperty_AudioFile, &s, &afid)) { // get associated AudioFileID
Float64 duration=expected_duration_in_seconds;
AudioFileSetProperty(afid, kAudioFilePropertyReserveDuration, sizeof(duration), &duration); // set expected duration
}
BASS_Encode_SetPaused(encoder, FALSE); // start encoding

Note that configuration changes need to be made before any data is encoded, so the encoder should be created in a paused state (BASS_ENCODE_PAUSE) to ensure that.

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for iOS (iPhone/iPad)
« Reply #1153 on: 2 Sep '16 - 17:58 »
The iOS versions of the new BASSenc_OGG and BASSenc_OPUS add-ons are now up in the 1st post. The BASSenc add-on has also been separated from the main iOS BASS package and included with the new add-ons instead.

Rich

  • Posts: 47
Re: BASS for iOS (iPhone/iPad)
« Reply #1154 on: 27 Sep '16 - 09:03 »
Hi,

I've tried checking in the forum and in the zip download to spot the minimum supported iOS SDK version but came up blank.

So, um, what's the minimum supported iOS SDK version for BASS?
Is there a Bass version vs ios SDK list?

I'm looking to write an app that supports iOS5 and up.

Thanks
Rich

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for iOS (iPhone/iPad)
« Reply #1155 on: 27 Sep '16 - 14:21 »
The minimum target (for armv7 and above architectures) in the BASS build settings is currently iOS 6. I guess it could also work on iOS 5, but I don't currently have an iOS 5 device at hand to check. Have you tried that yourself?

Rich

  • Posts: 47
Re: BASS for iOS (iPhone/iPad)
« Reply #1156 on: 29 Sep '16 - 15:28 »
Hi

thanks for the info.  I'll report back when I try it.  I have an iPad 1 that I think only supports iOS5 so that's ideal.

Thanks
Rich

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for iOS (iPhone/iPad)
« Reply #1157 on: 9 Dec '16 - 17:35 »
The iOS version of the BASSMIDI 2.4.10 release is now up in the 1st post.

reb

  • Posts: 5
Re: BASS for iOS (iPhone/iPad)
« Reply #1158 on: 10 Jan '17 - 20:22 »
I'm having an issue with playing streams on 32 bit iOS devices it appears. The same code runs fine on 64 bit devices.

The dev env is Xamarin 6.1.3 on OSX 10.12 with XCode 8.2 and current Bass.NET 2.4 so that all is up to date.

This code is new to me but I think I've tracked it down to not getting a callback on end of stream.
The initialization code looks like this:
Code: [Select]
static void InitBassPlayer(int frequency)
{
// Remove next stream

ReleaseCurrentStreamChannel();

if (_mixerHandle != 0)
{
Bass.BASS_ChannelStop(_mixerHandle);
Bass.BASS_StreamFree(_mixerHandle);
}

_mixerHandle = 0;
_streamHandle = 0;

Bass.BASS_Stop();
Bass.BASS_Free();


if (Bass.BASS_Init(-1, frequency, BASSInit.BASS_DEVICE_FREQ, (IntPtr)0, Guid.Empty))
{
BASS_INFO info = new BASS_INFO();
Bass.BASS_GetInfo(info);

Bass.BASS_Start();

Debug.WriteLine(info.ToString());
Debug.WriteLine("Bass Init to frequency: " + frequency);

// create a secure timer
_updateTimer = new BASSTimer(_updateInterval);
_updateTimer.Tick += timerUpdate_Tick;

}
else {
WriteError("Bass Init failed");
}


_loadNextSuncProc = new SYNCPROC(PositionLoadStream);
_endSyncProc = new SYNCPROC(EndPosition);

BassInitialised = true;

}
On 64 bit iOS, PositionLoadStream gets called when the stream ends but on 32 bit iOS (8.4 and 10.2) it never gets called and after 8 seconds or so the app crashes thusly:

Code: [Select]
2017-01-10 14:06:23.937 JRemote[3943:669072] critical: 0   libmonosgen-2.0.dylib               0x006a234d mono_handle_native_sigsegv + 240
2017-01-10 14:06:23.938 JRemote[3943:669072] critical: 1   libmonosgen-2.0.dylib               0x006aab05 mono_sigsegv_signal_handler + 150
2017-01-10 14:06:23.939 JRemote[3943:669072] critical: 2   libsystem_platform.dylib            0x37da40a3 _sigtramp + 42
2017-01-10 14:06:23.940 JRemote[3943:669072] critical: 3   libmscorlib.dll.dylib               0x018b3000 generic_trampoline_aot_plt + 48
2017-01-10 14:06:23.941 JRemote[3943:669072] critical: 4   JRemote                             0x0024228d BASS_PluginGetInfo + 6348
2017-01-10 14:06:23.942 JRemote[3943:669072] critical: 5   JRemote                             0x00235abb BASS_ChannelGetLength + 1822
2017-01-10 14:06:23.943 JRemote[3943:669072] critical: 6   JRemote                             0x00242d01 BASS_PluginGetInfo + 9024
2017-01-10 14:06:23.943 JRemote[3943:669072] critical: 7   JRemote                             0x0023510b BASS_Update + 326
2017-01-10 14:06:23.944 JRemote[3943:669072] critical: 8   JRemote                             0x002429b5 BASS_PluginGetInfo + 8180
2017-01-10 14:06:23.945 JRemote[3943:669072] critical: 9   libsystem_pthread.dylib             0x37da8ddf <redacted> + 138
2017-01-10 14:06:23.945 JRemote[3943:669072] critical: 10  libsystem_pthread.dylib             0x37da8d53 _pthread_start + 118
2017-01-10 14:06:23.946 JRemote[3943:669072] critical: 11  libsystem_pthread.dylib             0x37da6afc thread_start + 8

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for iOS (iPhone/iPad)
« Reply #1159 on: 11 Jan '17 - 15:31 »
Is the crash happening in a function call, or is it happening by itself during playback? If the latter, does "8 seconds or so" happen to be the position of a sync that you have set, ie. it is crashing at the point that you would expect to receive a callback? Please also show how you are setting the syncs. And also try this latest BASS library build just in case it's something that has already been fixed:

   www.un4seen.com/stuff/libbass.a

reb

  • Posts: 5
Re: BASS for iOS (iPhone/iPad)
« Reply #1160 on: 12 Jan '17 - 22:50 »
Is the crash happening in a function call, or is it happening by itself during playback? If the latter, does "8 seconds or so" happen to be the position of a sync that you have set, ie. it is crashing at the point that you would expect to receive a callback? Please also show how you are setting the syncs. And also try this latest BASS library build just in case it's something that has already been fixed:

   www.un4seen.com/stuff/libbass.a
I tried the libbass.a above without change.

It's happening by itself during playback. When it crashes, the app just stops running in Xamarin debug to the actual device without an indication to where it crashed.

Here are the places sync is set:

Code: [Select]
static void CreateMixer(int frequency)
{

Debug.WriteLine("Creating new mixer with frequency:" + frequency);

// Create mixer stream
_mixerHandle = BassMix.BASS_Mixer_StreamCreate(frequency, 2, BASSFlag.BASS_MIXER_END); // create mixer

// Set sync behaviour
_mixerSync = Bass.BASS_ChannelSetSync(_mixerHandle,  BASSSync.BASS_SYNC_END | BASSSync.BASS_SYNC_MIXTIME, 0, _endSyncProc, IntPtr.Zero);
}


static void RegisterPlaybackEvents()
{
var subLength = 8;
if (AppDelegate.Settings.UseTranscoding)
subLength = 10;

var lenByte = Bass.BASS_ChannelGetLength(_streamHandle);
var len = Bass.BASS_ChannelBytes2Seconds(_streamHandle, lenByte) - subLength;
var syncPosByte = Bass.BASS_ChannelSeconds2Bytes(_streamHandle, len);


_loadNextHandle = Bass.BASS_ChannelSetSync(_streamHandle, BASSSync.BASS_SYNC_POS, syncPosByte, _loadNextSuncProc, IntPtr.Zero);
}


static void SetPosition(long position)
{

if (!BassInitialised)
return;

Bass.BASS_ChannelLock(_mixerHandle, true);

if (BassMix.BASS_Mixer_ChannelSetPosition(_streamHandle, position))
{
long streamLen = Bass.BASS_ChannelGetLength(_streamHandle);
double streamtime = Bass.BASS_ChannelBytes2Seconds(_streamHandle, streamLen);

Bass.BASS_ChannelSetPosition(_mixerHandle, 0); // reset the mixer
long mixerPos = 0;
long syncPos = mixerPos + Bass.BASS_ChannelSeconds2Bytes(_mixerHandle, streamtime - position);

Bass.BASS_ChannelRemoveSync(_mixerHandle, _mixerSync); // remove old sync
_mixerSync = Bass.BASS_ChannelSetSync(_mixerHandle, BASSSync.BASS_SYNC_END | BASSSync.BASS_SYNC_MIXTIME, syncPos, _endSyncProc, IntPtr.Zero);
}
Bass.BASS_ChannelLock(_mixerHandle, false); // resume mixer processing
}


I think the problem is with the RegisterPlaybackEvents().
I played around with the subLength in there and it crashes at the number of seconds from the end sublength is set to.

The callback looks like this:

Code: [Select]

[Preserve]
[MonoPInvokeCallback(typeof(SYNCPROC))]
static void PositionLoadStream(int handle, int channel, int data, IntPtr user)
{
    Debug.WriteLine("Reached load next method");
Bass.BASS_ChannelRemoveSync(_streamHandle, _loadNextHandle);


RemoveNextItem();

_delegate.OnCurrentItemReachingEnd();

Debug.WriteLine("Loading next stream!!!!");
var nextItem = _delegate.NextItemInQueue();

if (nextItem != null)
{

var playItem = new PlaybackItem(nextItem);

if (!ItemNeedInitialisation(playItem))
{
_nextStream = new NextTrackStream(playItem);
_nextStream.Start();
}
}
}

On the 64 bit platforms, this callback is made. On 32 bits it's not.

robertr

  • Posts: 18
Re: BASS for iOS (iPhone/iPad)
« Reply #1161 on: 13 Jan '17 - 13:27 »
reb, this is the exact problem I am having. The app crashes on 32 bit devices when using MonoPInvokeCallback.
I am still not sure if this is a Xamarin or Bass issue, but I am leaning towards Xamarin.

I tried some older Bass libraries that I know worked before on 32 bit. They also crash now.

If it is a Xamarin issue it must have happened during the witch to iOS 10 I believe.

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for iOS (iPhone/iPad)
« Reply #1162 on: 13 Jan '17 - 18:17 »
It looks like this may be a known Xamarin issue:

   https://bugzilla.xamarin.com/show_bug.cgi?id=45371

According to that it has been fixed recently, but I'm not sure if the update has been released. What Xamarin version are each of you using?

reb

  • Posts: 5
Re: BASS for iOS (iPhone/iPad)
« Reply #1163 on: 13 Jan '17 - 18:47 »
It looks like this may be a known Xamarin issue:

   https://bugzilla.xamarin.com/show_bug.cgi?id=45371

According to that it has been fixed recently, but I'm not sure if the update has been released. What Xamarin version are each of you using?
Interesting. I'm using 6.1.4 build 1. I think it just came out yesterday.
Looking at the bug report though, that does sound exactly like what I'm seeing with the different iOS platforms.
« Last Edit: 13 Jan '17 - 18:52 by reb »

reb

  • Posts: 5
Re: BASS for iOS (iPhone/iPad)
« Reply #1164 on: 13 Jan '17 - 19:58 »
It looks like this may be a known Xamarin issue:

   https://bugzilla.xamarin.com/show_bug.cgi?id=45371

According to that it has been fixed recently, but I'm not sure if the update has been released. What Xamarin version are each of you using?
Interesting. I'm using 6.1.4 build 1. I think it just came out yesterday.
Looking at the bug report though, that does sound exactly like what I'm seeing with the different iOS platforms.
Just did a clean build and tried it again.
No luck.

reb

  • Posts: 5
Re: BASS for iOS (iPhone/iPad)
« Reply #1165 on: 13 Jan '17 - 21:07 »
It looks like this may be a known Xamarin issue:

   https://bugzilla.xamarin.com/show_bug.cgi?id=45371

According to that it has been fixed recently, but I'm not sure if the update has been released. What Xamarin version are each of you using?
Interesting. I'm using 6.1.4 build 1. I think it just came out yesterday.
Looking at the bug report though, that does sound exactly like what I'm seeing with the different iOS platforms.
Just did a clean build and tried it again.
No luck.
Oh man, the beta xamarin dev studio appears to fix it...

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for iOS (iPhone/iPad)
« Reply #1166 on: 26 Jan '17 - 13:58 »
The iOS versions of the recent BASSDSD/FLAC/OPUS/WV and BASSenc_OPUS add-on updates are up now in the 1st post.

DaveAE

  • Posts: 8
Re: BASS for iOS (iPhone/iPad)
« Reply #1167 on: 5 Feb '17 - 15:52 »
Is it possible to get a build with the libc++ LLVM standard C++ library? I just spent more than a week trying to figure out why the app crashed on 32-bit iPad's when deallocating a std::deque from the stack. I built the main project with libc++, but bass and bassmidi were apparently built with libstdc++, which caused problems.

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for iOS (iPhone/iPad)
« Reply #1168 on: 6 Feb '17 - 17:39 »
Are you only using BASS and BASSMIDI, and no other BASS add-ons? As far as I know, only the BASS_APE and BASS_FX add-ons currently use the C++ standard library. If you are not using either of those, then perhaps it is another library that is requiring libstdc++?

DaveAE

  • Posts: 8
Re: BASS for iOS (iPhone/iPad)
« Reply #1169 on: 9 Feb '17 - 19:28 »
Are you only using BASS and BASSMIDI, and no other BASS add-ons? As far as I know, only the BASS_APE and BASS_FX add-ons currently use the C++ standard library. If you are not using either of those, then perhaps it is another library that is requiring libstdc++?

I'm only using those two. After a std::deque on the stack, there are BASS_MIDI_ConvertEvents and BASS_MIDI_StreamEvents calls. If I don't call these, all went well. I suspect the new BASS_MIDI_ConvertEvents function. :)

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for iOS (iPhone/iPad)
« Reply #1170 on: 10 Feb '17 - 13:36 »
How many events are you passing to BASS_MIDI_StreamEvents, and are you using the BASS_MIDI_EVENTS_TIME flag? BASS_MIDI_StreamEvents has a bug in the current release (2.4.10.0) which can cause problems when you have over 512 pending events. An update will be released soon. Here's the latest build for you to try in the meantime:

   www.un4seen.com/stuff/libbassmidi.a

DaveAE

  • Posts: 8
Re: BASS for iOS (iPhone/iPad)
« Reply #1171 on: 11 Feb '17 - 11:14 »
How many events are you passing to BASS_MIDI_StreamEvents, and are you using the BASS_MIDI_EVENTS_TIME flag? BASS_MIDI_StreamEvents has a bug in the current release (2.4.10.0) which can cause problems when you have over 512 pending events. An update will be released soon. Here's the latest build for you to try in the meantime:

   www.un4seen.com/stuff/libbassmidi.a

I definitely wasn't putting out more than 512 events. But the point is moot, since XCode says that the libstdc++ library is deprecated and I'm pretty sure there was a clash in the standard C++ libraries, messing up the stack in the destructor of the deque.

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for iOS (iPhone/iPad)
« Reply #1172 on: 13 Feb '17 - 17:03 »
Neither BASS or BASSMIDI use the Standard C++ library though. Just to confirm that, I tried building them with the "C++ Standard Library" option set to "libstdc++" and "libc++", and the binary was identical in both cases (only the timestamp in the archive header changed with each rebuild).

How are you allocating the events array that's used in the BASS_MIDI_ConvertEvents call? Is it possible that the BASS_MIDI_ConvertEvents call is requesting more events than space has been allocated, resulting in it overwriting something used by the Standard C++ library? For example, perhaps the "eventc" parameter has been set to the byte size of the array instead of its element count?

Marek Ledvina

  • Guest
Re: BASS for iOS (iPhone/iPad)
« Reply #1173 on: 27 Mar '17 - 04:25 »
Hi, where can I get bass.h and bassmidi.h for iOS version?

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for iOS (iPhone/iPad)
« Reply #1174 on: 27 Mar '17 - 16:14 »
The same headers are used on all platforms, so you can take them from the Windows/OSX/Linux packages on the BASS webpage.