Author Topic: 2 quick questions  (Read 20670 times)

new guy

  • Guest
2 quick questions
« on: 1 Jul '03 - 16:24 »
1. In the bass documentation it says that if you use the BASS_ChannelSetFX function without the FX flag you can turn the effects on/off dynamically (ie. you don't have to stop and restart the stream first) and I was wanting to know what do they mean by the FX flag because I cannot find any info on it in the docs other then that you can trun it on/off.


2. I know how to create a crossfader using 2 channels (slide one down while sliding the other up...) but how would I do it just using one channel in delphi ?

Irrational86

  • Posts: 960
Re: 2 quick questions
« Reply #1 on: 1 Jul '03 - 18:08 »
Quote

1. In the bass documentation it says that if you use the BASS_ChannelSetFX function without the FX flag you can turn the effects on/off dynamically (ie. you don't have to stop and restart the stream first) and I was wanting to know what do they mean by the FX flag because I cannot find any info on it in the docs other then that you can trun it on/off.
The FX flag is BASS_SAMPLE_FX, this flag you would use it when loading a Stream, Sample or Music, but its a disadvantage if you just want to dynamically change effects.

Quote

2. I know how to create a crossfader using 2 channels (slide one down while sliding the other up...) but how would I do it just using one channel in delphi ?
Well, to achieve this, set the the first stream to Auto Free, then the volume attribute of BASS_ChannelSlideAttribute set it to -2, which means Slide volume to 0, and then Stop. This if this auto free stream is Stopped, then it is fred, this way you can start sliding the channel, disregard its handle (you wont need it anymore as it will be freed) and then start your new stream.

--------------------------------
Check this thread out, maybe you'll get an idea, http://www.un4seen.com/YaBB.cgi?board=bass&action=display&num=1037047491
« Last Edit: 1 Jul '03 - 18:13 by XMinioNX »

new guy

  • Guest
Re: 2 quick questions
« Reply #2 on: 1 Jul '03 - 21:06 »
As Far as the FX flag being set I guess I had it unset all the time (ie. I did not add it when I created the stream) but I cannot add and remove effects at any time as the docs suggest.

Here is the code I am using to add/remove the effects

Code: [Select]

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if checkbox1.Checked = True then
Bass_ChannelSetFX(Stream,Bass_FX_Flanger)
else
Bass_ChannelRemoveFX(Stream,Bass_FX_Flanger);
end;



As far as the crossfader goes I don't really get it at all because how can you slide a channel that has been stopped already. I looked at the code in the link you provided and tried to do something with it but it did not do anything. Maybe it would help if I explained my situation so here goes.

When my form is created I load a directory of mp3's (about 2300) into a listbox and when I click on one of the songs in the list it plays and so on an so forth. What I want is if I click on a song while another one is playing to fade out that song while the one I just clicked on fades in at the same time (ie. crossfade) I want to do this using only one stream handle because this is just one of 6 ways I am loading and playing songs and it could get very confusing very quickly if I used more then one handle.

Anyway here is the code I tried using so you can see where my mistake could be.

Code: [Select]

procedure TForm1.ListBox1Click(Sender: TObject);
Var
Stream : HSTREAM;
begin

Bass_ChannelStop(Stream);

Stream := Bass_StreamCreateFile(FALSE,pChar(listbox1.Items.Strings[listbox1.ItemIndex]), 0, 0,BASS_STREAM_AUTOFREE);

Bass_StreamPlay(Stream, FALSE, 0);

Bass_channelslideattributes(stream,-1,-2,-101,1500);

Stream := Bass_StreamCreateFile(FALSE,pChar(listbox1.Items.Strings[listbox1.ItemIndex]), 0, 0,0);

Bass_StreamPlay(Stream, FALSE, 0);

end;

new guy

  • Guest
Re: 2 quick questions
« Reply #3 on: 2 Jul '03 - 11:11 »
So I take it from the lack of further replies that the code I am using should be working or close enough so that nobody can find any errors in it ?

If that is the case then would anyone care to guess at what the problem might be.

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: 2 quick questions
« Reply #4 on: 2 Jul '03 - 13:18 »
Try this...
Code: [Select]

procedure TForm1.ListBox1Click(Sender: TObject);
begin
// fade-out old
  BASS_ChannelSlideAttributes(Stream, -1, -2, -101, 1500);
// create new
  Stream := BASS_StreamCreateFile(FALSE, pChar(listbox1.Items.Strings[listbox1.ItemIndex]), 0, 0, BASS_STREAM_AUTOFREE);
// fade-in
  BASS_ChannelSetAttributes(Stream, -1, 0, -101);
  BASS_ChannelSlideAttributes(Stream, -1, 100, -101, 1500);
  BASS_StreamPlay(Stream, FALSE, 0);
end;

"Stream" should be a global variable... that also explains why your "SetFX" call didn't work.


DanaPaul

  • Posts: 335
Re: 2 quick questions
« Reply #5 on: 2 Jul '03 - 17:56 »

Quote

I want to do this using only one stream handle because this is just one of 6 ways I am loading and playing songs and it could get very confusing very quickly if I used more then one handle.


Along with the previous reply, you may be interested in  taking a look at multiple instance Bass, BassCD, and BassWMA header files.  All Delphi versions supported, and all Bass instances are dynamically loaded.  These header files utilise an array of (Bass) function pointers offering the developer a simple and easy to use solution for Bass multi functionality, ie: Decoding while Encoding, etc.

http://members.aol.com/wtgdana/private/Bass/



new guy

  • Guest
Re: 2 quick questions
« Reply #6 on: 2 Jul '03 - 21:01 »
Ok the crossfader worked but even after setting the handle name as a global variable the SetFX function still does not work. I made sure to remove it from where it was originally and I even went so far as to create a new test program and it still does not work.

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: 2 quick questions
« Reply #7 on: 3 Jul '03 - 13:51 »
Check the BASS_ChannelSetFX return value to see if the call failed, and if it has, use BASS_ErrorGetCode to get the reason for the failure... it'll help reduce the guessing games :)

Also, note that the "FX" functions require DX8 (or above) to be installed, so make sure you have that.

new guy

  • Guest
Re: 2 quick questions
« Reply #8 on: 3 Jul '03 - 22:47 »
Ok I did as you said and when I checked on the checckbox (enabled the FX) the error code returned was 0 which I am guessing is ok.

Unchecking the checkbox (disabled the FX) the error code returned was 5 which if I am reading things right is the BASS_ERROR_UNKNOWN so I guess that narrows it down abit :)

I have windows xp which comes with DX 8.1 so the DX version is fine.

new guy

  • Guest
Re: 2 quick questions
« Reply #9 on: 4 Jul '03 - 10:47 »
I think I made a mistake when checking for the return value of the call (am also new to delphi) so this is the new code I am using which I hope is the correct way of getting the return values of the call.

Code: [Select]

procedure TForm1.Button7Click(Sender: TObject);
begin
BASS_ChannelSetFX(song,bass_fx_flanger);
label10.Caption := inttostr(BASS_ChannelSetFX(song,bass_fx_flanger));
end;

The code to add the effect and show it's return value on a label


Code: [Select]

procedure TForm1.Button8Click(Sender: TObject);
begin
BASS_ChannelRemoveFX(song,bass_fx_flanger);
label10.Caption := booltostr(bass_channelremoveFX(song,bass_fx_flanger));
end;

The code to remove the effect and show it's return value on a label



Code: [Select]

procedure TForm1.Button9Click(Sender: TObject);
begin
label10.Caption:= inttostr(bass_errorGetCode());
end;

the code to get the last error code returned by bass and show it on a label


Here are my results...

If I click on the button to add the effect without first starting the stream the return value is 0 and the error code is 5.

If I click on the the button to add the effect when a song is streaming the return value is 3758096390 which I am assuming is the handle of the flanger effect and the error code is 0.

If I click on the button to remove the effect without first starting the stream the return value is 0 and the error code is 5 (just like when adding the effect)

If I click on the the button to remove the effect when a song is streaming the return value is 0 and the error code is 0 but the effect is never removed.

Again I hope this is the correct way of checking the return values and hope it helps finding a answer to my problem.

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: 2 quick questions
« Reply #10 on: 4 Jul '03 - 14:29 »
Ok, that looks like the BASS_ChannelSetFX call is successful. Do you not hear the effect? If not, can you hear the effects in either the FXTEST or SYNTH precompiled examples?

The reason for the BASS_ChannelRemoveFX failure is that you need to use the handle that you got from the BASS_ChannelSetFX call in the 2nd parameter, not the type of FX. (error code 5 = BASS_ERROR_HANDLE)

new guy

  • Guest
Re: 2 quick questions
« Reply #11 on: 4 Jul '03 - 19:48 »
yes I hear the effect I have always been able to hear it. It's the unsetting of the effect that does not seem to work even after doing as you said and using the returned handle for the effect as the 2nd parameter in the Bass_ChannelRemoveFX call. The effect is simply not removed.

here is the code I used to test it with I realize in the final version I will have to setup a variable to store the fx handle but for now I just wanted to test it with the hardcoded value that was returned.

Code: [Select]

procedure TForm1.Button8Click(Sender: TObject);
begin
BASS_ChannelRemoveFX(song,3758096390);
label10.Caption := booltostr(bass_channelremoveFX(song,bass_fx_flanger));
end;

new guy

  • Guest
Re: 2 quick questions
« Reply #12 on: 5 Jul '03 - 07:29 »
Am I doing this correct or is my code totally wrong. I mean if (3758096390) is the handle that is returned in the SetFX call is it not the handle I need to use when Removing the effect or is there something i'm missing here.

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: 2 quick questions
« Reply #13 on: 6 Jul '03 - 15:19 »
You just need to store the handle that BASS_ChannelSetFX returns, and use it when you call BASS_ChannelRemoveFX.

new guy

  • Guest
Re: 2 quick questions
« Reply #14 on: 6 Jul '03 - 19:01 »
Is that not what I was doing ? If not then I have no idea how to do it.

Irrational86

  • Posts: 960
Re: 2 quick questions
« Reply #15 on: 7 Jul '03 - 02:51 »
You have to have a global variable to store the handle in, the handle will change on each call to BASS_ChannelSetFX. This handle you save, is the one you pass to BASS_ChannelRemoveFX