BASS for iOS (iPhone/iPad)

Started by Ian @ un4seen,

John Doe

Quote from: Ian @ un4seenAre 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.

I want to change level both or playback and recording. For playback I use
BASS_ChannelSetAttribute(playedChannel, BASS_ATTRIB_VOL, vol);

Recording:
BASS_FX_BFX_VOLUME is not working for me. It is set with ErrorCode 0, but I don't hear any changes.
So please can you show me an example of DSP procedure?
Maybe this can help.

Thanks a lot.

Ian @ un4seen

Quote from: John DoeRecording:
BASS_FX_BFX_VOLUME is not working for me. It is set with ErrorCode 0, but I don't hear any changes.

Please post the code you're using to set the FX and its parameters, to check if there are any problems with it.

John Doe

#202
Here is my code:

vol - is floating-type variable from 0 to 1.
   BASS_ChannelRemoveFX(playedChannel, volHFX);
    volHFX = BASS_ChannelSetFX(recordedChannel, BASS_FX_BFX_VOLUME, 1);
    BASS_BFX_VOLUME fx1;
    fx1.fVolume = vol;
    fx1.lChannel = BASS_BFX_CHANALL;
    BASS_FXSetParameters(volHFX, &fx1);

Thanks.

Ian @ un4seen

Are the BASS_ChannelSetFX and BASS_FXSetParameters calls reporting success, ie. not returning 0?

Also, just to be sure, is the "volH" in the BASS_FXSetParameters call just a typo and it is actually "volHFX" in your code?

John Doe

Quote from: Ian @ un4seenAre the BASS_ChannelSetFX and BASS_FXSetParameters calls reporting success, ie. not returning 0?
Both of BASS_ErrorGetCode returns 0.

QuoteAlso, just to be sure, is the "volH" in the BASS_FXSetParameters call just a typo and it is actually "volHFX" in your code?

Yeap, sorry it is just typo.

Ian @ un4seen

OK. How are you creating "recordedChannel", and what are you doing with it, eg. where is its sample data going? Please post the code for that stuff.

John Doe


//Create channel
recordedChannel=BASS_StreamCreateFile(FALSE, [respath cStringUsingEncoding: NSUTF8StringEncoding], 0, 0, BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT);
//Then add to mixer
QWORD start=BASS_ChannelSeconds2Bytes(mixer, seconds); // delay
QWORD length=BASS_ChannelSeconds2Bytes(mixer, 2); // duration
BASS_Mixer_StreamAddChannelEx(mixer, recordedChannel, 0, start, length);
//And try to change volume in realtime
    BASS_ChannelRemoveFX(chan, volHFX);
    volHFX = BASS_ChannelSetFX(chan, BASS_FX_BFX_VOLUME, 1);
    BASS_BFX_VOLUME fx1;
    fx1.fVolume = vol;
    fx1.lChannel = BASS_BFX_CHANALL;
    BASS_FXSetParameters(volHFX, &fx1);

Ian @ un4seen

OK, so "recordedChannel" is actually a stream, I guess playing a previously recorded file? In that case, it should be possible to simply use BASS_ATTRIB_VOL to change its volume level...

BASS_ChannelSetAttribute(recordedChannel, BASS_ATTRIB_VOL, vol);

Is that not working? If so, can you confirm where you're checking the level, eg. is it in the mixer output?

John Doe

#208
Quote from: Ian @ un4seenOK, so "recordedChannel" is actually a stream, I guess playing a previously recorded file? In that case, it should be possible to simply use BASS_ATTRIB_VOL to change its volume level...

BASS_ChannelSetAttribute(recordedChannel, BASS_ATTRIB_VOL, vol);

Is that not working? If so, can you confirm where you're checking the level, eg. is it in the mixer output?

I should be more clear.
From the user experience:
I play channel and while playing dragging volume-level slider using BASS_ChannelSetAttribute, so volume changes in realtime. Works great.
And I'd like the same feature for recording channel (hear the same effect after decoding and playing).

BASS_ChannelSetAttribute works with recordedChannel, but after decoding it sounds only with last got volume value. Ex (we are playing audiofile with 10 secs lenght):
from 1 to 3 second I set
BASS_ChannelSetAttribute(recordedChannel, BASS_ATTRIB_VOL, 0.1);
then from 3 to 5 second I set
BASS_ChannelSetAttribute(recordedChannel, BASS_ATTRIB_VOL, 0.6);
then from 5 to 10 secong I set
BASS_ChannelSetAttribute(recordedChannel, BASS_ATTRIB_VOL, 0.0);

All of these lines returns error-code 0, but after decoding I hear only last attribute volume (0.0).

Maybe I do it basically wrong?


Ian @ un4seen

OK, now I'm confused! So you actually want to apply the volume change to something else, not the "recordedChannel"? Please post the relevant code to have a look at, eg. the creation of that other channel ("playedChannel"?).

John Doe

Quote from: Ian @ un4seenOK, now I'm confused! So you actually want to apply the volume change to something else, not the "recordedChannel"? Please post the relevant code to have a look at, eg. the creation of that other channel ("playedChannel"?).

Sorry, typo again. I meant recordedChannel

wiseguybec

Hello everyone,

I have spent the last couple of days trying and trying to get the iphone bass_fx lib up and running in xcode (4), but I can't get the OSX headerfile to work. At some point I found the BASS_background sample and used it's bass library and headerfile successfully to play at runtime generated wav files - but i actually want to change pitch and tempo. After fiddling around with the working headerfile and rummaging around in this forum i finally realised that only the bass_fx lib will enable changing pitch and tempo so now i am at step one again :-(((

- Can someone please please explain how to generate/program/download the appropriate header file for libbass_fx.a (or even the addons libbass_enc etc.?

Any help at all is greatly appreciated!!!!!

wiseguybec

Hi again,

importing the bass headerfile into the fx_bass header file and adding both the libbass.a as well as the libbass_fx.a only threw errors at the beat section. But still no pitch changing possible? Was this the correct way to get the iphone fx_bass up and running?
 
Is my code the problem?
   
    BASS_ChannelSetAttribute(
                             chan,
                             BASS_ATTRIB_TEMPO_PITCH,
                             2.0f
                             );
   
if(!(chan=BASS_StreamCreateFile(0, [[recordedTmpFile relativePath] cStringUsingEncoding:NSUTF8StringEncoding], 0, 0, 0))) {
NSLog(@"Can't load stream!");
} else {
       
       
BASS_ChannelPlay(chan,FALSE);

...I also tried
BASS_FX_TempoCreate(chan, BASS_ATTRIB_TEMPO_PITCH);
with no effect. In all cases the file is played, but without change in pitch.

....can anyone see the mistake? Or is it the header file?

thank you for any help!

John Doe

Have you tried to get error code from BASS_ErrorGetCode()?

wiseguybec

...sorry, the change of 2.0f was just to little - a change of 20.0f showed success!!! Volumes a wee bit low, but i had read that...will turn it up

- HURRAY!

Ian @ un4seen

Quote from: John DoeSorry, typo again. I meant recordedChannel

OK, let's start again. Please post the exact code (copy'n'paste to avoid typos :)) that you're using to create "recordedChannel" and apply volume changes, and check the error codes if any BASS calls are failing.

Quote from: wiseguybecIs my code the problem?
   
    BASS_ChannelSetAttribute(
                             chan,
                             BASS_ATTRIB_TEMPO_PITCH,
                             2.0f
                             );
   
if(!(chan=BASS_StreamCreateFile(0, [[recordedTmpFile relativePath] cStringUsingEncoding:NSUTF8StringEncoding], 0, 0, 0))) {
NSLog(@"Can't load stream!");
} else {
       
       
BASS_ChannelPlay(chan,FALSE);

...I also tried
BASS_FX_TempoCreate(chan, BASS_ATTRIB_TEMPO_PITCH);
with no effect. In all cases the file is played, but without change in pitch.

....can anyone see the mistake? Or is it the header file?

It sounds like you've already sorted it from your follow-up post, but for anyone else wondering about it, it should look something like this...

chan=BASS_StreamCreateFile(0, filename, 0, 0, BASS_STREAM_DECODE); // create a "decoding channel" from a file
chan=BASS_FX_TempoCreate(chan, BASS_FX_FREESOURCE); // create a tempo stream from it
BASS_ChannelSetAttribute(chan, BASS_ATTRIB_TEMPO_PITCH, 2.0f); // set the pitch change
BASS_ChannelPlay(chan, FALSE); // start playing

John Doe

QuoteOK, let's start again. Please post the exact code (copy'n'paste to avoid typos :)) that you're using to create "recordedChannel" and apply volume changes, and check the error codes if any BASS calls are failing.

OK:). So let starts.
Creation:
recordedChannel=BASS_StreamCreateFile(FALSE, [respath cStringUsingEncoding: NSUTF8StringEncoding], 0, 0, BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT));
Add to mixer:
...
//Mixer creation
mixer = BASS_Mixer_StreamCreate(44100, 2, BASS_SAMPLE_FLOAT);
...
 QWORD start=BASS_ChannelSeconds2Bytes(mixer, seconds); // delay
 QWORD length=BASS_ChannelSeconds2Bytes(mixer, 2); // duration                      
 BASS_Mixer_StreamAddChannelEx(mixer, recordedChannel, 0, start, length); // add the channel  

Try to floating volume (this lines call separately, not one-by-one, just you to shure ;)):
//1 to 3 secs
BASS_ChannelSetAttribute(recordedChannel, BASS_ATTRIB_VOL, 0.3);
//3 to 5 secs
BASS_ChannelSetAttribute(recordedChannel, BASS_ATTRIB_VOL, 0.6);
//5 to 10 secs
BASS_ChannelSetAttribute(recordedChannel, BASS_ATTRIB_VOL, 0.1);

Encoding:
   //Encode file to mp4
    BASS_Encode_StartCAFile(mixer, 'mp4f', 'aac ', 0, 128000, [fileName cStringUsingEncoding:NSUTF8StringEncoding]);
    BASS_ChannelPlay(mixer, 0); // start the channel playing & encoding
... some time while encoding....
   BASS_Encode_Stop(mixer);
    //Free recording mixer
    BASS_StreamFree(mixer);
Then simply open my mp4 file with any player and hear sound with 0.1 volume:((

Hope it was clear:)

Ian @ un4seen

OK. So the problem is that the BASS_ATTRIB_VOL changes aren't being applied at the time that you want them to be in the encoding? If so, please confirm how you are timing the changes to occur when you want them to, eg. after 1/3/5 seconds. One more thing... the BASS_Mixer_StreamAddChannelEx call is stating that the "recordedChannel" will only play (in the mixer) for 2 seconds, but you're making volume changes to it over 5 seconds?

Are the volume changes responding to real-time user input, or are they predetermined? If the latter, it may be better to use an envelope (see BASS_Mixer_ChannelSetEnvelope) to apply them; you don't need to be concerned about the timing of BASS_ChannelSetAttribute calls then.

wiseguybec

Hello again,

yes - the code to play a pitch shifted prerecorded works - but only on the simulator. The minute I add the BASS_STREAM_DECODE flag to stream creation, the iphone goes silent...


    DWORD chan=BASS_StreamCreateFile(0, [respath cStringUsingEncoding:
                                         NSUTF8StringEncoding], 0, 0, BASS_STREAM_DECODE);
   

Does anyone know this problem?

I have looked at
http://www.un4seen.com/forum/?topic=11377.msg79195#msg79195
and
http://www.un4seen.com/forum/?topic=2181.msg82490;hl=bass_stream_decode+iphone#msg82490

but I cannot see the answer to the problem?

thank you for any advice!

P.S. Another small question: Can pitch go negative? I'd like my recorded vocals to be lower (at same tempo), but the function didn't like negative floats...

Ian @ un4seen

Quote from: wiseguybecyes - the code to play a pitch shifted prerecorded works - but only on the simulator. The minute I add the BASS_STREAM_DECODE flag to stream creation, the iphone goes silent...


    DWORD chan=BASS_StreamCreateFile(0, [respath cStringUsingEncoding:
                                         NSUTF8StringEncoding], 0, 0, BASS_STREAM_DECODE);
   

Does anyone know this problem?

That BASS_StreamCreateFile call looks fine, so perhaps the problem is the BASS_FX_TempoCreate call. What does that look like?

Quote from: wiseguybecP.S. Another small question: Can pitch go negative? I'd like my recorded vocals to be lower (at same tempo), but the function didn't like negative floats...

A negative pitch setting should be fine (please see the BASS_FX documentation for valid parameter ranges). What function didn't like the negative values?

wiseguybec

Hi there,

- thanks for the reassurance on negative pitch floats, negative input was indeed no problem. Had obviously been meddling around with the code too much at that point and had a conflict of errors.

The iphone still won't play my pitched recording:
   
BasSample = BASS_StreamCreateFile(0, [[recordedTmpFile relativePath] cStringUsingEncoding:NSUTF8StringEncoding], 0, 0, BASS_STREAM_DECODE);
Channel = BASS_FX_TempoCreate(BasSample, BASS_STREAM_DECODE);

BASS_ChannelSetAttribute(Channel, BASS_ATTRIB_TEMPO_PITCH, -5.0);

   mixer = BASS_Mixer_StreamCreate(44100, 3, 0);
    BASS_Mixer_StreamAddChannel(mixer, Channel, 0); 
    int play = BASS_ChannelPlay(mixer, false);
    if (!play)
    {
        NSLog(@"Failed to play");
        int err = BASS_ErrorGetCode();
        NSLog(@"Failed with error code %i", err);
        return;
    }

I have asked for error codes after each line, but none appear !

thank you!

Ian @ un4seen

If you monitor (eg. in a timer) what BASS_ChannelGetPostiion says about the mixer stream ("mixer"), tempo stream ("Channel") and file stream ("BasSample"), do you see them advancing?

Btw, is the mixer there needed? If not, you could remove the BASS_STREAM_DECODE flag from the BASS_FX_TempoCreate call, and call BASS_ChannelPlay on the tempo stream ("Channel"). If you do need the mixer, is the chans=3 parameter in the BASS_Mixer_StreamCreate call intentional? That would usually be 2 for stereo, or 1 for mono.

wiseguybec

Hello,

yes - BASS_ChannelGetPosition returns ascending values when running on the simulator. When running on the device (iphone 4) 0 is returned for all channels (BassSample, mixer and Channel). If I do a BASS_ErrorGetCode after the Position call, then BASS_OK is returned? Do you have any inkling as to what might cause this? Do you think I'm doing smth really basic wrong?

Becca

P.S. Sorry about the mixer channel input. I am aiming to mix 3 pitch shifted streams, which is why I thought I needed to set a 3 - got that wrong too, I 'spose...

Ian @ un4seen

So, to confirm, the BASS_ChannelGetPosition calls are all returning 0 on the device? If you also call BASS_ChannelIsActive on each of the stream handles, what does that say?

Also, what does BASS_ChannelGetLength say when called on the file stream ("BasSample") handle? Btw, in all of these length/position calls, the "mode" parameter should be BASS_POS_BYTE.

wiseguybec

Hi again,

BASS_ChannelGetLength returns -1 on the device and nice long numbers on the simulator.

I think I wasn't able to implement BASS_ChannelIsActive correctly, since on its own it always returns null (whether device or simulator) and:
    if (HIWORD(BASS_ChannelIsActive(Channel)) == BASS_ACTIVE_PLAYING) {
NSLog(@"is playing");
return;
}

never returned anything. Any pointers on the correct implementation on the iPhone?

I always used the BASS_POS_BYTE flag.

I threw out the mixer, but it didn't help. All stays the same, simulator works fine, device is silent. :-(