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

Ian @ un4seen

  • Administrator
  • Posts: 21861
Re: BASS for iOS (iPhone/iPad)
« Reply #950 on: 22 Dec '14 - 16:33 »
The iOS version of BASS 2.4.11 is now up in the 1st post.

mits

  • Posts: 8
Re: BASS for iOS (iPhone/iPad)
« Reply #951 on: 23 Dec '14 - 16:58 »
Hello,

I am using BASS for audio player app.
When I use BASS_ChannelPause or BASS_ChannelStop, click noise occurs with high probability.
This noise is conspicuous in quiet music such as the piano music.
How can I reduce this noise?


The device and software version is as follows:

Device: iPhone 6 / iPhone 5 / iPhone 4
iOS: 8.1.1 / 8.0 / 7.1.2
BASS: 2.4.10
Xcode: 6.1.1
File: AAC, MP3


Thanks in advance.

Ian @ un4seen

  • Administrator
  • Posts: 21861
Re: BASS for iOS (iPhone/iPad)
« Reply #952 on: 23 Dec '14 - 18:05 »
One thing you could try is using BASS_ChannelSlideAttribute to fade-out and stop, like this...

Code: [Select]
BASS_ChannelSlideAttribute(handle, BASS_ATTRIB_VOL, -1, 200); // fade-out over 200ms and stop

Before resuming playback, you would need to reset the volume level via BASS_ChannelSetAttribute, or use BASS_ChannelSlideAttribute again to fade-in.

mits

  • Posts: 8
Re: BASS for iOS (iPhone/iPad)
« Reply #953 on: 24 Dec '14 - 14:34 »
One thing you could try is using BASS_ChannelSlideAttribute to fade-out and stop, like this...

Code: [Select]
BASS_ChannelSlideAttribute(handle, BASS_ATTRIB_VOL, -1, 200); // fade-out over 200ms and stop

Before resuming playback, you would need to reset the volume level via BASS_ChannelSetAttribute, or use BASS_ChannelSlideAttribute again to fade-in.


It works great!

Thank you for your quick reply.

fortinbras

  • Guest
Re: BASS for iOS (iPhone/iPad)
« Reply #954 on: 5 Jan '15 - 01:58 »
When I ran this line on the Iphone6 Simulator,

handle = BASS_FX_TempoCreate(handle, BASS_FX_FREESOURCE);

I got the EXEC_BAD_ACCESS error. But I switch Simulator to Iphone5, it's ok.

I used the latest package build for Standard architectures. (updated: 22 Dec '14)
BASS 2.4.11.1
BASS_FX 2.4.11.1
XCODE 6.1.1

Thank you very much.

Ian @ un4seen

  • Administrator
  • Posts: 21861
Re: BASS for iOS (iPhone/iPad)
« Reply #955 on: 5 Jan '15 - 14:50 »
Please post a crash log, to confirm (hopefully) where the crash occurred.

foritinbras

  • Posts: 6
Re: BASS for iOS (iPhone/iPad)
« Reply #956 on: 6 Jan '15 - 01:34 »
Please post a crash log, to confirm (hopefully) where the crash occurred.

This is my code :
Code: [Select]
    ret = BASS_Init(-1, 44100, 0,0,0);
    if (ret == FALSE)
    {
        int err = BASS_ErrorGetCode();
        LOGD("BASS_Init failed! err %d", err);
        return;
    }
   
   
    stream = BASS_StreamCreateFile(FALSE, filename, 0, 0, BASS_STREAM_PRESCAN|BASS_STREAM_DECODE);
    if (stream == FALSE)
    {
        int err = BASS_ErrorGetCode();
        LOGD("BASS_StreamCreateFile err %d", err);
        return;
    }
   
    stream = BASS_FX_TempoCreate(stream, BASS_FX_FREESOURCE);  <-- Crashed

crash log:
Code: [Select]
Code Type:             X86-64 (Native)
Parent Process:        launchd_sim [733]
Responsible:           launchd_sim [733]
User ID:               501

Date/Time:             2015-01-06 09:25:41.801 +0800
OS Version:            Mac OS X 10.10 (14A389)
Report Version:        11

Crashed Thread:        3  Dispatch queue: com.apple.root.default-qos

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000000

Application Specific Information:
CoreSimulator 110.4 - Device: iPhone 6 - Runtime: iOS 8.1 (12B411) - DeviceType: iPhone 6

Thread 3 Crashed:: Dispatch queue: com.apple.root.default-qos
0   TES.Tiger                      0x000000010100bc63 BASS_FX_ReverseGetSource + 3051

Ian @ un4seen

  • Administrator
  • Posts: 21861
Re: BASS for iOS (iPhone/iPad)
« Reply #957 on: 6 Jan '15 - 17:40 »
Are there any more frames in the crashed thread's call stack? Please also check whether you get the crash if you call BASS_FX_TempoGetSource instead of BASS_FX_TempoCreate.

foritinbras

  • Posts: 6
Re: BASS for iOS (iPhone/iPad)
« Reply #958 on: 7 Jan '15 - 01:36 »
Are there any more frames in the crashed thread's call stack? Please also check whether you get the crash if you call BASS_FX_TempoGetSource instead of BASS_FX_TempoCreate.

I tried BASS_FX_TempoGetSource instead of BASS_FX_TempoCreate no crash got.

I also tried to call BASS_FX_TempoCreate in the main thread, it crashed again. There is only one line in the crashed thread's call stack.

Code: [Select]
Process:               Tiger [1765]
Path:                  /Users/USER/Library/Developer/CoreSimulator/Devices/EA79A282-F5E0-4400-A807-CB8FD9C2D1D0/data/Containers/Bundle/Application/A95306F3-8197-499F-9AD7-073FD62EE83D/Tiger.app/Tiger
Identifier:            Tiger
Version:               1.0 (1)
Code Type:             X86-64 (Native)
Parent Process:        launchd_sim [1087]
Responsible:           launchd_sim [1087]
User ID:               501

Date/Time:             2015-01-07 09:16:35.505 +0800
OS Version:            Mac OS X 10.10 (14A389)
Report Version:        11
Anonymous UUID:        A4D91044-EF9C-E871-ABE6-187595CFC855


Time Awake Since Boot: 2100 seconds

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000000

VM Regions Near 0:
-->
    __TEXT                 00000001091f4000-000000010923a000 [  280K] r-x/r-x SM=COW  /Users/USER/Library/Developer/CoreSimulator/Devices/EA79A282-F5E0-4400-A807-CB8FD9C2D1D0/data/Containers/Bundle/Application/A95306F3-8197-499F-9AD7-073FD62EE83D/Tiger.app/Tiger

Application Specific Information:
CoreSimulator 110.4 - Device: iPhone 6 - Runtime: iOS 8.1 (12B411) - DeviceType: iPhone 6

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   TES.Tiger                     0x000000010922a1cf BASS_FX_ReverseGetSource + 3051

Thread 1:: Dispatch queue: com.apple.libdispatch-manager
0   libsystem_kernel.dylib         0x000000010bf5d22e kevent64 + 10
1   libdispatch.dylib             0x000000010bbfe304 _dispatch_mgr_thread + 54

Thread 2:
0   libsystem_kernel.dylib         0x000000010bf5c946 __workq_kernreturn + 10
1   libsystem_pthread.dylib       0x000000010bf8b4a1 start_wqthread + 13

Thread 3:
0   libsystem_kernel.dylib         0x000000010bf5c946 __workq_kernreturn + 10
1   libsystem_pthread.dylib       0x000000010bf8b4a1 start_wqthread + 13

Thread 4:
0   libsystem_kernel.dylib         0x000000010bf5c946 __workq_kernreturn + 10
1   libsystem_pthread.dylib       0x000000010bf8b4a1 start_wqthread + 13

Thread 5:
0   libsystem_kernel.dylib         0x000000010bf57582 semaphore_timedwait_trap + 10
1   libdispatch.dylib             0x000000010bbfb66e _dispatch_semaphore_wait_slow + 143
2   libdispatch.dylib             0x000000010bbfa19b _dispatch_worker_thread + 122
3   libsystem_pthread.dylib       0x000000010bf8d2fc _pthread_body + 131
4   libsystem_pthread.dylib       0x000000010bf8d279 _pthread_start + 176
5   libsystem_pthread.dylib       0x000000010bf8b4b1 thread_start + 13

Thread 6:: com.apple.audio.IOThread.client
0   libsystem_kernel.dylib         0x000000010bf5752e mach_msg_trap + 10
1   libsystem_kernel.dylib         0x000000010bf5669f mach_msg + 55
2   com.apple.audio.CoreAudio     0x000000010c22198c HALB_MachPort::SendMessageWithReply(unsigned int, unsigned int, unsigned int, unsigned int, mach_msg_header_t*, bool, unsigned int) + 98
3   com.apple.audio.CoreAudio     0x000000010c22191a HALB_MachPort::SendSimpleMessageWithSimpleReply(unsigned int, unsigned int, int, int&, bool, unsigned int) + 42
4   com.apple.audio.CoreAudio     0x000000010c21fe93 HALC_ProxyIOContext::IOWorkLoop() + 945
5   com.apple.audio.CoreAudio     0x000000010c21fa48 HALC_ProxyIOContext::IOThreadEntry(void*) + 88
6   com.apple.audio.CoreAudio     0x000000010c21f925 HALB_IOThread::Entry(void*) + 157
7   libsystem_pthread.dylib       0x000000010bf8d2fc _pthread_body + 131
8   libsystem_pthread.dylib       0x000000010bf8d279 _pthread_start + 176
9   libsystem_pthread.dylib       0x000000010bf8b4b1 thread_start + 13

Thread 7:: AURemoteIO::IOThread
0   libsystem_kernel.dylib         0x000000010bf5752e mach_msg_trap + 10
1   libsystem_kernel.dylib         0x000000010bf5669f mach_msg + 55
2   com.apple.audio.toolbox.AudioToolbox 0x00000001094662c0 AURemoteIO::IOThread::Run() + 160
3   com.apple.audio.toolbox.AudioToolbox 0x000000010946a229 AURemoteIO::IOThread::Entry(void*) + 9
4   com.apple.audio.toolbox.AudioToolbox 0x00000001093c8b9f CAPThread::Entry(CAPThread*) + 143
5   libsystem_pthread.dylib       0x000000010bf8d2fc _pthread_body + 131
6   libsystem_pthread.dylib       0x000000010bf8d279 _pthread_start + 176
7   libsystem_pthread.dylib       0x000000010bf8b4b1 thread_start + 13

Thread 8:
0   libsystem_kernel.dylib         0x000000010bf5c132 __psynch_cvwait + 10
1   TES.Tiger                     0x00000001091f659b main + 843

Thread 9:
0   libsystem_kernel.dylib         0x000000010bf5c132 __psynch_cvwait + 10
1   TES.Tiger                     0x00000001091f65a5 main + 853

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x00007fb2b0d801e0  rbx: 0x0000000000000000  rcx: 0x000000010923af00  rdx: 0x00007fb2b0d801c0
  rdi: 0x00000001149eca00  rsi: 0x00007fb2b0d00000  rbp: 0x0000000000000040  rsp: 0x00007fff56a08f50
   r8: 0x0000000000000002   r9: 0x00000000fffffffe  r10: 0x0000000000000003  r11: 0x00007fb2b0d00000
  r12: 0x0000000000010000  r13: 0x0000000000000008  r14: 0x0000000000000001  r15: 0x0000000080000001
  rip: 0x000000010922a1cf  rfl: 0x0000000000010206  cr2: 0x0000000000000000
  
Logical CPU:     0
Error Code:      0x00000006
Trap Number:     14

Ian @ un4seen

  • Administrator
  • Posts: 21861
Re: BASS for iOS (iPhone/iPad)
« Reply #959 on: 7 Jan '15 - 17:48 »
I tried BASS_FX_TempoGetSource instead of BASS_FX_TempoCreate no crash got.

OK. That narrows it down a bit, ie. it isn't crashing in checking whether tempo processing is already enabled on the provided channel. The next thing to check is have you included "-lstdc++" in your project's "Other Linker Flags" setting?

foritinbras

  • Posts: 6
Re: BASS for iOS (iPhone/iPad)
« Reply #960 on: 8 Jan '15 - 01:14 »

OK. That narrows it down a bit, ie. it isn't crashing in checking whether tempo processing is already enabled on the provided channel. The next thing to check is have you included "-lstdc++" in your project's "Other Linker Flags" setting?
Yes, I both included "-lstdc++" in project's setting and targets' setting.
If not included the flag, the project building will produce linker error.

Ian @ un4seen

  • Administrator
  • Posts: 21861
Re: BASS for iOS (iPhone/iPad)
« Reply #961 on: 8 Jan '15 - 17:43 »
OK. Looking at the assembly code at the crash location, it appears to be in a "new" call, so that's why I thought it may be a libstdc++ issue. I'll check with the BASS_FX developer to see if we can find out more about it. To confirm what you're experiencing, does the crash only happen when running 64-bit (x64_86) code in the iPhone 6 simulator, and not when running 32-bit (set the simulator architecture to i386 as shown: here) code in the same simulator or when running either architecture in the iPhone 5 simulator?

foritinbras

  • Posts: 6
Re: BASS for iOS (iPhone/iPad)
« Reply #962 on: 9 Jan '15 - 01:45 »
OK. Looking at the assembly code at the crash location, it appears to be in a "new" call, so that's why I thought it may be a libstdc++ issue. I'll check with the BASS_FX developer to see if we can find out more about it. To confirm what you're experiencing, does the crash only happen when running 64-bit (x64_86) code in the iPhone 6 simulator, and not when running 32-bit (set the simulator architecture to i386 as shown: here) code in the same simulator or when running either architecture in the iPhone 5 simulator?
In the Xcode 6.1.1, I couldn't find the setting "Any iOS Simulator SDK" and "i386" drop down in the link(here) shown. Then I found the solution  (here), and when compiled to 32-bit application and running in the iPhone 6 simulator, everything work fine.

I tested the iPhone 5s Simulator, it also crashed when running 64-bit code, and it work fine when running 32-bit code.

In the iPhone5 Simulator, it not crashed in either compiling situation, the CPU in iPhone5 is Apple A6, which is a 32-bit ARM CPU. Maybe the iPhone5 Simulator only choose the 32-bit code to run.

Thanks for your attention.

Oleg the soundman

  • Posts: 97
Re: BASS for iOS (iPhone/iPad)
« Reply #963 on: 9 Jan '15 - 14:59 »
Friends,

I need to play internet file (finite) stream and to draw the level histogram of the track, but I need to scan levels as they are downloaded, not as they are played, so levels are known as new data appears available.

Is this possible using BASS?

I thought of a solution using BASS_StreamCreateURL with DOWNPROC and additional custom stream that would be seek-able and I could use BASS_ChannelSetPosition() and BASS_ChannelGetLevel() on it, but can't seem to find the right solution altogether.

Maybe someone has easy/ available solution for creating a custom stream from URL stream at download time? Any info is appreciated.

Ian @ un4seen

  • Administrator
  • Posts: 21861
Re: BASS for iOS (iPhone/iPad)
« Reply #964 on: 9 Jan '15 - 16:40 »
Yep, you could use a DOWNLOADPROC callback to receive the downloaded data, and create a user file stream via BASS_StreamCreateFileUser to scan the levels from that. It doesn't sound like you would need to seek, ie. just scan through the downloaded data from start to end? You could indeed use BASS_ChannelGetLevel or BASS_ChannelGetLevelEx to scan the levels. You could have a look at the CUSTLOOP example that's included in the Win32/OSX/Linux BASS packages for a demonstration of doing that sort of thing.

Oleg the soundman

  • Posts: 97
Re: BASS for iOS (iPhone/iPad)
« Reply #965 on: 9 Jan '15 - 17:33 »
Yes, that's what I am trying to do, but since I need to scan really quickly I have to do it with interval, so I thought of seeking to a required position. The problem is it's not easy to organise FileSeekProc in that case. And I wanted to avoid creating one more full-sized buffer or using one more buffered stream.

Ckouta

  • Posts: 35
Re: BASS for iOS (iPhone/iPad)
« Reply #966 on: 12 Jan '15 - 09:06 »
Hello,

Just to know,  is there a way to have the headers file of Bass's libraries?

Thanks for your attention.
« Last Edit: 12 Jan '15 - 15:58 by Ckouta »

Ian @ un4seen

  • Administrator
  • Posts: 21861
Re: BASS for iOS (iPhone/iPad)
« Reply #967 on: 13 Jan '15 - 13:04 »
Yes, that's what I am trying to do, but since I need to scan really quickly I have to do it with interval, so I thought of seeking to a required position. The problem is it's not easy to organise FileSeekProc in that case. And I wanted to avoid creating one more full-sized buffer or using one more buffered stream.

Unless the interval is large, it may be faster to just process the entire file straight through without seeking, as the process of seeking will have some overhead (with some file formats more than others). You don't need to bother implementing a FileSeekProc then, eg. use the STREAMFILE_BUFFER file system (with the BASS_STREAM_BLOCK flag to avoid BASS keeping very much of the file buffered). You will need to have some buffering to get the data from the DOWNLOADPROC to the FILEREADPROC, but you could remove the data from the buffer straight after it has been used, eg. some sort of dynamic FIFO buffer. If you don't have any FIFIO buffer code to hand, it could be implemented with a BASS "push" stream, something like this...

Code: [Select]
fifo=BASS_StreamCreate(1000, 1, BASS_SAMPLE_8BITS|BASS_STREAM_DECODE, STREAMPROC_PUSH, 0); // create mono 8-bit push stream for FIFO buffer

...

void CALLBACK DownloadProc(const void *buffer, DWORD length, void *user)
{
DWORD fifo=(DWORD)user; // push stream handle
if (!buffer) BASS_StreamPutData(fifo, 0, BASS_STREAMPROC_END); // signal EOF
else BASS_StreamPutData(fifo, buffer, length); // write/add data
}

DWORD CALLBACK FileReadProc(void *buffer, DWORD length, void *user)
{
DWORD fifo=(DWORD)user; // push stream handle
while (1) {
DWORD r=BASS_ChannelGetData(fifo, buffer, length); // read/remove data
if (r) return r; // got some data or error/EOF
Sleep(50); // wait for more data to arrive (could use an event instead)
}
}

Just to know,  is there a way to have the headers file of Bass's libraries?

The BASS headers are the same on all platforms, so you can take them from the Win32/OSX/Linux packages on the BASS webpage.

fxfletch

  • Posts: 26
Re: BASS for iOS (iPhone/iPad)
« Reply #968 on: 15 Jan '15 - 11:52 »
Hi Ian,

I am working on a new project where I am mixing music with the mic on the iPad and then record the results, fairly straight forward but I am running into the issue of latency when monitoring on headphones. Its just enough to make you sound drunk  :-[

I have read lots of posts on this issue and tried to distill them down to this:
    BASS_SetConfig(BASS_CONFIG_MIXER_BUFFER,1);
   
    MixerStream = BASS_Mixer_StreamCreate(44100,2,BASS_SAMPLE_FLOAT | BASS_MIXER_NONSTOP );
    BASS_ChannelSetAttribute(MixerStream, BASS_ATTRIB_NOBUFFER, 1);
    BASS_ChannelPlay(MixerStream,true );
    BASS_RecordInit(0);
    BASS_RecordSetDevice(0);
    BASS_RecordSetInput(-1, BASS_INPUT_ON, 1.0f);
   
    micStream = BASS_RecordStart(info.freq, 2, MAKELONG(0, 10), NULL, NULL);
    BASS_Mixer_StreamAddChannel(MixerStream, micStream, BASS_MIXER_LIMIT);

Is this the best I am going to get? or did I miss something?

Assuming this is as good as its going to get can you think of a way I can monitor the mic directly without the mixer but then combine it with the mixed music before its written into the recording stream?

Thanks as always Ian

Ian @ un4seen

  • Administrator
  • Posts: 21861
Re: BASS for iOS (iPhone/iPad)
« Reply #969 on: 15 Jan '15 - 18:06 »
One thing you could try is lowering the device buffer length via BASS_CONFIG_DEV_BUFFER, eg. to something like 5ms. You can check what buffer length is being used via BASS_GetInfo ("minbuf" value). It is possible to change the device buffer length at any time on iOS (it doesn't have to be before calling BASS_Init as on other platforms), but it could be a few milliseconds before the change takes effect.

The BASS_CONFIG_MIXER_BUFFER setting won't be having any effect (it only affects BASS_Mixer_ChannelGetData/Level calls), so you can remove that.

fxfletch

  • Posts: 26
Re: BASS for iOS (iPhone/iPad)
« Reply #970 on: 15 Jan '15 - 18:19 »
YES!  ;D that's perfect, very tiny delay completely useable.

Thanks
Ian

fxfletch

  • Posts: 26
Re: BASS for iOS (iPhone/iPad)
« Reply #971 on: 16 Jan '15 - 09:36 »
The latest version (2.4.12) of the BASSenc add-on is now up in the 1st post, adding support for user-provided encoders, eg. it is now possible to use the LAME library instead of the standalone LAME executable (which isn't available on iOS).

Is there anything I need to do this other than have the latest version installed? I am currently trying to use the following example from the CastInit() documentation:

Code: [Select]
txStream = BASS_Encode_Start(MixerStream, "lame -r -s 44100 -b 128 -", BASS_ENCODE_NOHEAD, NULL, 0); // setup the encoder

But I get a not available error (37)

Ian

Ian @ un4seen

  • Administrator
  • Posts: 21861
Re: BASS for iOS (iPhone/iPad)
« Reply #972 on: 16 Jan '15 - 13:16 »
YES!  ;D that's perfect, very tiny delay completely useable.

Great!

The latest version (2.4.12) of the BASSenc add-on is now up in the 1st post, adding support for user-provided encoders, eg. it is now possible to use the LAME library instead of the standalone LAME executable (which isn't available on iOS).

Is there anything I need to do this other than have the latest version installed? I am currently trying to use the following example from the CastInit() documentation:

Code: [Select]
txStream = BASS_Encode_Start(MixerStream, "lame -r -s 44100 -b 128 -", BASS_ENCODE_NOHEAD, NULL, 0); // setup the encoder

But I get a not available error (37)

Standalone command-line encoders aren't available on iOS, so BASS_Encode_Start only supports WAV file writing there, and a BASS_ERROR_NOTAVAIL error is the result otherwise. You can instead have an encoder built into your app, and use that via BASS_Encode_StartUser and an ENCODERPROC callback function. An example ENCODERPROC function for use with the LAME library can be found in the ENCODERPROC documentation.

If you don't specifically need MP3, then AAC and ALAC encoding is available without any additional libraries, via BASS_Encode_StartCA.

fxfletch

  • Posts: 26
Re: BASS for iOS (iPhone/iPad)
« Reply #973 on: 16 Jan '15 - 13:37 »
Thanks, I am trying to feed caster.fm so I think that has to be lame. I will have a look at how I can get a lame encoder into my app.

fxfletch

  • Posts: 26
Re: BASS for iOS (iPhone/iPad)
« Reply #974 on: 16 Jan '15 - 18:04 »
Actually I have realised I can feed aac so all working now.  :)