BASS for iOS (iPhone/iPad)

Started by Ian @ un4seen,

Ian @ un4seen

Is your app also recording, using BASS_RecordInit/etc? In that case, an iPhone will route the output to the receiver/earpiece by default, rather than the speaker. A new BASS_CONFIG_IOS_SPEAKER config option has been added to override that (see the 1st post). Let me know if it still doesn't give the desired result.

Gurt87

Quote from: Johny MakerHi, there.
I'm developing iOS music application using BASS, it works great, but recently I've received user's feedback that on his iPhone:
QuoteSound is way to quiet and this is because it's coming out of the earpiece (what you use to hear phone calls) and not the external speakers. It's impossible for us to test until we get the notes coming out of the correct speakers at a good volume.

I initialize BASS like this:
BASS_Init(-1, 44100, BASS_DEVICE_DEFAULT, NULL, NULL);
As I read -1  is a default output device. On iPad and iPod works good.

Should I set first parameter to 1 to have sound from speakers?

Please, any help.



I have the same problem.

QuoteA new BASS_CONFIG_IOS_SPEAKER config option has been added to override that (see the 1st post).

Im try this
        BASS_Init(-1, 44100, BASS_DEVICE_DEFAULT, NULL, NULL);
        BASS_SetConfig(BASS_CONFIG_IOS_SPEAKER, 1);

But BASS_SetConfig return FALSE;

When i set another flags (for example BASS_CONFIG_IOS_MIXAUDIO) BASS_SetConfig return TRUE;

BASS_CONFIG_IOS_SPEAKER available only in last BASS version (updated: 28 Apr '11) ?????
I'm using the previous version.

Maybe problem in that???





Ian @ un4seen

Quote from: Gurt87BASS_CONFIG_IOS_SPEAKER available only in last BASS version (updated: 28 Apr '11) ?????
I'm using the previous version.

Yes, the BASS_CONFIG_IOS_SPEAKER option was added in the latest update (2.4.7.6), so you will need to be using that version for it.

Gurt87

Quote from: Ian @ un4seen
Quote from: Gurt87BASS_CONFIG_IOS_SPEAKER available only in last BASS version (updated: 28 Apr '11) ?????
I'm using the previous version.

Yes, the BASS_CONFIG_IOS_SPEAKER option was added in the latest update (2.4.7.6), so you will need to be using that version for it.

Works great! Thanks!

Gurt87

Quote from: Ian @ un4seenTo stop a note, you need another MIDI_EVENT_NOTE event for the same note but with velocity=0 (in the HIBYTE).

BASS_MIDI_StreamEvent(chan, 0, MIDI_EVENT_NOTE, MAKEWORD(60, 0));

When i use this code my preset stops immediately.
how can I know when i must set velocity = 0;

Some of presets stops after 1 sec, some after 0.5 sec, ex. some of them never stops

Maybe i can get length of preset?















Ian @ un4seen

Quote from: Gurt87When i use this code my preset stops immediately.
how can I know when i must set velocity = 0;

There isn't really a must release time, it's basically whenever you want it to be :)

As you noted, some sounds (eg. a wind or bowed string instrument) won't stop until the note is released.

Gurt87

#181
Quote from: Ian @ un4seen
Quote from: Gurt87When i use this code my preset stops immediately.
how can I know when i must set velocity = 0;

There isn't really a must release time, it's basically whenever you want it to be :)

As you noted, some sounds (eg. a wind or bowed string instrument) won't stop until the note is released.

Thanks for your help Ian.

Now im try implement  BASS_ChannelSetSync function
chan = BASS_MIDI_StreamCreate(1, BASS_MIDI_NOFX, 0);
BASS_ChannelSetSync(chan, BASS_SYNC_MIDI_EVENT, MIDI_EVENT_NOTE, &NoteSyncProc, nil);
BASS_ChannelPlay(chan,FALSE);

BASS_MIDI_StreamEvent(chan, 0, MIDI_EVENT_MASTERVOL, 16383);
BASS_MIDI_StreamEvent(chan, 0, MIDI_EVENT_VOLUME, 127);
BASS_MIDI_StreamEvent(chan, 0, MIDI_EVENT_BANK, 127);
BASS_MIDI_StreamEvent(chan, 0, MIDI_EVENT_PROGRAM, 1);
BASS_MIDI_StreamEvent(chan, 0, MIDI_EVENT_NOTE, MAKEWORD(64, 100));

void CALLBACK NoteSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
int chan=HIWORD(data); // MIDI channel number
NSLog(@"chan - %d", chan);
int note=LOBYTE(data); // note
NSLog(@"note - %d", note);
int vel=HIBYTE(data); // velocity
NSLog(@"vel - %d", vel);
// do something with that information...
}

CALLBACK is never called.. why? Maybe error in BASS_ChannelSetSync params ???



Ian @ un4seen

BASS_SYNC_MIDI_EVENT syncs don't get triggered by BASS_MIDI_StreamEvent calls. They are only triggered by events played in a MIDI file, and optionally by BASS_MIDI_StreamEvents. So, if you want the syncs to be triggered by custom events, you can use BASS_MIDI_StreamEvents instead of BASS_MIDI_StreamEvent.

Od1n

Think we have a bug, related to something fixed last build.
Previously, the mute switch didn't respond after task switching. That's now fixed in the latest Basslib

It seems there's a related bug, that the Mute Switch is being ignored when headphones are plugged in.

Allan

Ian @ un4seen

There haven't been any BASS changes relating to the mute switch behaviour, at least nothing intentional :)

Are you sure the change happened due to a BASS update, not an iOS update? Is the switch behaving differently with other apps?

Evgeniy

Hi everyone!

I want to develop iPhone application that will be able to play mp3 file and display equalizer
EQ - the main feature
it must be look like



I know how to play mp3 file with BASS
Is it possible to obtain data in real-time for equalizer??

If yes, what functions BASS i must use?

Ian @ un4seen

BASS_ChannelGetData is the function you're looking for. It can provide FFT data (see the documentation for details), which can be used to produce a spectrum display. You can find an example of doing that in the SPECTRUM example; there isn't an iOS version of that currently, but the BASS calls will be the same on all platforms, so you can look at the example on one of the other supported platforms. From your screenshot, you would want to look at the "specmode=1" code (you can change the "BANDS" constant as needed).

kevinpk

Hi All,

I'm trying to use the following function BASS_ChannelSlideAttribute (with attrib BASS_ATTRIB_MUSIC_SPEED) to gradually slow down the MP3 song playback over a span of 5 seconds till it stops completely (i.e. vinyl stop).  Unfortunately, it doesn't seem to work.  Can anyone suggest some hints/ alternatives on how to get this working on the iOS platform?

Thanks.

Ian @ un4seen

BASS_ATTRIB_MUSIC_SPEED only applies to MOD music (HMUSIC handles). BASS_ATTRIB_FREQ is what you want :)

Evgeniy

Quote from: Ian @ un4seenBASS_ChannelGetData is the function you're looking for. It can provide FFT data (see the documentation for details), which can be used to produce a spectrum display. You can find an example of doing that in the SPECTRUM example; there isn't an iOS version of that currently, but the BASS calls will be the same on all platforms, so you can look at the example on one of the other supported platforms. From your screenshot, you would want to look at the "specmode=1" code (you can change the "BANDS" constant as needed).

Thanks for help!

Gurt87

Hi!

I developed application which play different sounds...

When i have incoming call in my iPhone, application go to background,
then restored..and BASS not playing....
Im trying re initialize BASS, not helped (((

Any suggestions...?

Ian @ un4seen

That's strange, it should resume after an interruption. I will send you a debug version to find out what is happening.

Ian @ un4seen

It turns out the above non-resumption following an incoming call issue was introduced in the recent 2.4.7.5 update. Another update to correct that is now up in the 1st post. This update also adds support for "ducking" (lowering the volume of other audio while your app is playing), which is enabled by setting the BASS_CONFIG_IOS_MIXAUDIO option to 2.

Evgeniy

Hi Ian!

I download bass midi example and run "miditest".
I choose soundfont (with 127 instruments). Then choose midi file.
Sound started play!

Midi file playing and use different instruments from soundfont

I have a question:
Can i play this file using only one instrument from this soundfont?
For example play with preset number 10 (piano);

I think it can be configure in this code:
HSOUNDFONT newfont;
char file[256];
FSRefMakePath(&fr,(BYTE*)file,sizeof(file));
if ((newfont=BASS_MIDI_FontInit(file,0)) && newfont!=font) {
BASS_MIDI_FONT sf;
sf.font=newfont;
sf.preset=-1; // use all presets
sf.bank=0; // use default bank(s)
BASS_MIDI_StreamSetFonts(0,&sf,1); // set default soundfont
BASS_MIDI_StreamSetFonts(chan,&sf,1); // set for current stream too
BASS_MIDI_FontFree(font); // free old soundfont
font=newfont;
}

But if i set  sf.preset=10;

Sound not play.

Thanks!
(sorry for my English)

Ian @ un4seen

What you could do is use a "mixtime" BASS_SYNC_MIDI_EVENT sync to override the MIDI file's MIDI_EVENT_PROGRAM events, so that it always uses the preset that you want. That could be done something like this...

BASS_ChannelSetSync(stream, BASS_SYNC_MIDI_EVENT|BASS_SYNC_MIXTIME, MIDI_EVENT_PROGRAM, ProgramSyncProc, 0); // set sync on PROGRAM events

...

void CALLBACK ProgramSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
DWORD midichan=HIWORD(data); // MIDI channel number
BASS_MIDI_StreamEvent(channel, midichan, MIDI_EVENT_PROGRAM, 10); // set PROGRAM to 10
}

Evgeniy

Quote from: Ian @ un4seenWhat you could do is use a "mixtime" BASS_SYNC_MIDI_EVENT sync to override the MIDI file's MIDI_EVENT_PROGRAM events, so that it always uses the preset that you want. That could be done something like this...

BASS_ChannelSetSync(stream, BASS_SYNC_MIDI_EVENT|BASS_SYNC_MIXTIME, MIDI_EVENT_PROGRAM, ProgramSyncProc, 0); // set sync on PROGRAM events

...

void CALLBACK ProgramSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
DWORD midichan=HIWORD(data); // MIDI channel number
BASS_MIDI_StreamEvent(channel, midichan, MIDI_EVENT_PROGRAM, 10); // set PROGRAM to 10
}

Thank you! It works!

One more question:
Is it possible to get a note that plays in a given time and how long it sound?
Perhaps there is some BASS_ChannelSetSync procedure?

Ian @ un4seen

You can also use a BASS_SYNC_MIDI_EVENT sync, with param=MIDI_EVENT_NOTE instead of MIDI_EVENT_PROGRAM, to be informed of notes being pressed or released...

void CALLBACK NoteSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
DWORD midichan=HIWORD(data); // MIDI channel number
DWORD key=LOBYTE(data);
DWORD velocity=HIBYTE(data);
...
}

Evgeniy

Quote from: Ian @ un4seenYou can also use a BASS_SYNC_MIDI_EVENT sync, with param=MIDI_EVENT_NOTE instead of MIDI_EVENT_PROGRAM, to be informed of notes being pressed or released...

void CALLBACK NoteSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
DWORD midichan=HIWORD(data); // MIDI channel number
DWORD key=LOBYTE(data);
DWORD velocity=HIBYTE(data);
...
}

Thank you Ian! Works perfect!

John Doe

Hi, Ian.

Please help in problem.
I'm developing application to play and record sound and I'm almost done.
While recording I have slider-control to up and down playing sound in realtime:
    //vol and recordedVol is [0..1]
    BASS_ChannelSetAttribute(playedChannel, BASS_ATTRIB_VOL, vol);
    BASS_ChannelSetAttribute(recordedChannel, BASS_ATTRIB_VOL, recorderVol);
Sounds good, but after decoding:
    NSString *fileName = [DOCUMENTS_FOLDER stringByAppendingFormat:@"/%@.mp4", file];
       
    //Encode file to mp4
    BASS_Encode_StartCAFile(mixer, 'mp4f', 'aac ', 0, 128000, [fileName cStringUsingEncoding:NSUTF8StringEncoding]);
   
    BASS_ChannelPlay(mixer, 0); // start the channel playing & encoding
    ...
//Stop decoding after done
mp4 file sounds good but without "realtime sound changes", only static volume value.

How can I get such recording-effect? Please, any help.

P.S. Hope I was clear:)

Ian @ un4seen

Are you wanting to change the level of the recording/encoding, or just the playback of it? The latter shouldn't be a problem, but I'm afraid the FREQ/PAN/VOL attributes will have no effect on the recording/encoding, as they are only applied to channels that are playing (when the output mix is generated). The encoder will receive the recorded sample data, with any active DSP/FX (with a "priority" higher than BASS_CONFIG_ENCODE_PRIORITY) applied to it. So you could use a DSP function to change the level of the recorded data, or more simply, use BASS_FX's BASS_FX_BFX_VOLUME effect.