Author Topic: How to catch finishing of playing of hsample,hchannel and/or hmusic  (Read 4069 times)

sashakozlovskiy

  • Posts: 54
Thank you very much for your reply. 1. Can i get callbacks,if i will use bass_sample_(create/setdata) to have deal with buffer,or i should use stream? 2. Can i catch,when volume of hchannel become 0,i.e it will stopped after fadout or how i can autofree hsample/hchannel after fadout? 3. How i can get current position,if my callback will call for each position and how i can set feding/out in ms?

Ian @ un4seen

  • Administrator
  • Posts: 26172
Can i get callbacks,if i will use bass_sample_(create/setdata) to have deal with buffer,or i should use stream?

If you want to provide the sample data via a callback then you should use a stream and STREAMPROC (via BASS_StreamCreate) instead of a sample.

Can i catch,when volume of hchannel become 0,i.e it will stopped after fadout or how i can autofree hsample/hchannel after fadout?

You can use value=-1 in the BASS_ChannelSlideAttribute call to stop the channel at the end of the fade-out.

How i can get current position,if my callback will call for each position and how i can set feding/out in ms?

The current position is available from BASS_ChannelGetPosition. The BASS_ChannelSlideAttribute "time" parameter is in milliseconds.

Please see the documentation for details on all mentioned functions.

sashakozlovskiy

  • Posts: 54
Thank you very much for your replys. Can i catch via callback,when channel was stopped after fading,or i should set timer on n ms,which i set for fading?

Chris

  • Posts: 2217
yes
Code: [Select]
BASS_ChannelSetSync(stream, BASS_SYNC_SLIDE, 0, MySlideSyncProc, 0); // Sync when an attribute slide has ended
//  param : not used.
//  data : the attribute that has finished sliding e.G

sashakozlovskiy

  • Posts: 54
Hello again. I have several questions about fading. 1. If,for example,i have fadout 500 ms,but before end of the track left 100 ms,what callback will call firstly: callback,which announce,what track was ended,or callback,wich announce,what channel was stopped because of fadout,or both? If both,what will be first (i want to use one function for all this callbacks) and may be exist easeer way not call callback for ending of playing,if channel was stopped before finishing of playin,i.e,for example,if i hav fading 500 ms,but at the end of the track is 100 ms. Yes,i can use some algorithms,to catch this,but may be bass have easier way to do it without aditional variables. 2. How i can define reason of callback,i.e whether channel was finished,or fadout was finished. 3. in Chrises example for fading it not use bass_sync_onetime flag,so we can't free channel in callback in this case,because fading callback require mix_time flag? May be exists example of code,for example,how to fading/out hchannel at 500 ms to play it once (other playing should be without fading/fadout)?

sashakozlovskiy

  • Posts: 54
4. Some sounds are quite and bass_attrib_vol as 1.0f it sometimes not enough for me. May be exists another way how increase bass volume. In documentation i found several functions for this,but i am not sure,what they really allow increase exists volume. 5. After sliding of some attribute,for example volume,should i before playing set it to current value,or it remember value,which i set before sliding,so i can play channel after stopping of it again,not caring about attribute,which i slide,values.

Ian @ un4seen

  • Administrator
  • Posts: 26172
1. If,for example,i have fadout 500 ms,but before end of the track left 100 ms,what callback will call firstly: callback,which announce,what track was ended,or callback,wich announce,what channel was stopped because of fadout,or both? If both,what will be first (i want to use one function for all this callbacks) and may be exist easeer way not call callback for ending of playing,if channel was stopped before finishing of playin,i.e,for example,if i hav fading 500 ms,but at the end of the track is 100 ms. Yes,i can use some algorithms,to catch this,but may be bass have easier way to do it without aditional variables.

If the end occurs before the fade-out finishes then the BASS_SYNC_END sync would be called first, and then the BASS_SYNC_SLIDE sync. If you would like to check if playback has already stopped in the BASS_SYNC_SLIDE callback then you can use BASS_ChannelIsActive to do that.

2. How i can define reason of callback,i.e whether channel was finished,or fadout was finished.

You could either use a different callback function for each sync type or set the "user" parameter differently for them (and check that in the callback).

3. in Chrises example for fading it not use bass_sync_onetime flag,so we can't free channel in callback in this case,because fading callback require mix_time flag? May be exists example of code,for example,how to fading/out hchannel at 500 ms to play it once (other playing should be without fading/fadout)?

It is fine to free a channel in a BASS_SYNC_SLIDE sync callback.

4. Some sounds are quite and bass_attrib_vol as 1.0f it sometimes not enough for me. May be exists another way how increase bass volume. In documentation i found several functions for this,but i am not sure,what they really allow increase exists volume.

You can set BASS_ATTRIB_VOL above 1.0 to amplify.

5. After sliding of some attribute,for example volume,should i before playing set it to current value,or it remember value,which i set before sliding,so i can play channel after stopping of it again,not caring about attribute,which i slide,values.

The attribute will be left at the slide's final value. If you want a different value then you can set that via BASS_ChannelSetAttribute (or another slide).

sashakozlovskiy

  • Posts: 54
Thank you very much for your help. 1. If i will use negative value for sliding,to stop the channel,whether BASS_ChannelIsActive will return false in callback,or it will stopped after callback. In our app user can set volume as 0.0f and i set it for current channel via bass_attrib_vol. Should i check value of volume,or even for 0.0f callback will call? 2. What is the max volume for bass_attrib_vol and can i set it as global volume,or i can set volume more than 1.0f only for channel? 3. How i can remove some flags and attributes from the channel,for example loop flag,if callback will call two times (two loops)?

Ian @ un4seen

  • Administrator
  • Posts: 26172
1. If i will use negative value for sliding,to stop the channel,whether BASS_ChannelIsActive will return false in callback,or it will stopped after callback.

It will be stopped after the BASS_SYNC_SLIDE sync callback returns.

2. What is the max volume for bass_attrib_vol and can i set it as global volume,or i can set volume more than 1.0f only for channel?

The BASS_ATTRIB_VOL value is basically unlimited. The BASS_CONFIG_GVOL_STREAM/SAMPLE options can be used for global volume control but note they don't currently support amplification.

3. How i can remove some flags and attributes from the channel,for example loop flag,if callback will call two times (two loops)?

You can change flags with BASS_ChannelFlags. Please see its documentation for an example of toggling looping.

sashakozlovskiy

  • Posts: 54
1. O,so i can check,whether bass_channel_is_active,and if it is active,i can understand a reason of callback - fading finished,or playing finished. It's a very pity,what if channel was finished before end of sliding,slide callback will call anyway,but i dont want to have this behaviour. 2. If user of our app will set volume 0.0f,and it will be fading,whether callback for sliding will call anyway? Yes,i can check it myself,but i want to be sure,what it was always work only so,or only using other way,but not else. 3. I tryed set high volume for channel,and,for example,for 255 it was some crackling of sound,and for volume,for example,32767 it was sound overload and it was need time,to sound normalize,after stopping of it (i use nvda,because i blind,and one or two second after stopping of channel and freeing of bass sound of tts was overloaded). Interesting,why? 4. Will you plan add amplification level for global volume,and if not,how i can send feature request to you about it? 5. I found example,about which you wrote,but why we can't,for example,set looping using BASS_ChannelFlags(channel, BASS_SAMPLE_LOOP,0);? Can we get current flags for channel?
« Last Edit: 17 Mar '23 - 14:43 by sashakozlovskiy »

sashakozlovskiy

  • Posts: 54
Also i noticed,what,for example,in some tracks,volume more than n,for example n=128 we have no efect,when increase volume,and,as i wrote,in big volume,e.g 255,we can hear crackling of sound. So the question about max volume is,in my opinion,very actual.

Ian @ un4seen

  • Administrator
  • Posts: 26172
1. O,so i can check,whether bass_channel_is_active,and if it is active,i can understand a reason of callback - fading finished,or playing finished. It's a very pity,what if channel was finished before end of sliding,slide callback will call anyway,but i dont want to have this behaviour.

If you don't want the BASS_SYNC_SLIDE sync to be triggered then you could remove the sync via BASS_ChannelRemoveSync.

2. If user of our app will set volume 0.0f,and it will be fading,whether callback for sliding will call anyway? Yes,i can check it myself,but i want to be sure,what it was always work only so,or only using other way,but not else.

Yes, a BASS_SYNC_SLIDE sync will be triggered at the end of any slide, even if the slide isn't actually changing the attribute value.

3. I tryed set high volume for channel,and,for example,for 255 it was some crackling of sound,and for volume,for example,32767 it was sound overload and it was need time,to sound normalize,after stopping of it (i use nvda,because i blind,and one or two second after stopping of channel and freeing of bass sound of tts was overloaded). Interesting,why?

If the volume level is set too high then the sound would usually be clipped (resulting in distortion), but Windows applies a limiter to its output by default, which will lower the level instead of clipping. But that limiter may also have internal limits to how high level it'll accept. To avoid any unexpected behaviour, you should try to avoid depending on the limiter to bring the level down, ie. don't set the volume level so high in the first place.
 
4. Will you plan add amplification level for global volume,and if not,how i can send feature request to you about it?

There are no plans for that currently. One issue is that the current global config functions only deal with integers (BASS_SetConfig) or pointers (BASS_SetConfigPtr), not floating-point values. But note that you can apply a global volume setting yourself in all of your BASS_ATTRIB_VOL settings:

Code: [Select]
BASS_ChannelSetAttribute(handle, BASS_ATTRIB_VOL, channel_volume * global_volume);

5. I found example,about which you wrote,but why we can't,for example,set looping using BASS_ChannelFlags(channel, BASS_SAMPLE_LOOP,0);? Can we get current flags for channel?

BASS_ChannelFlags returns the updated flags, so you get the current flags by not changing any:

Code: [Select]
DWORD flags = BASS_ChannelFlags(handle, 0, 0);

sashakozlovskiy

  • Posts: 54
1. yes,i know,what i can remove callback,but now i should add aditional variable for each sound (because we have structure,which have information about sound). In sdl_mixer library (from which i rewrite code,because i write other quests interpreter and partially use code from Interpreter,which was written by other person and he use sdl library,in which we have callback,which will call once,if channel was stopped (manually,ended,or if fadout was finished,therefore channel was stopped. Bass library haven't this feature,so we should use different tricks,to catch this. 2. I know,what with high volume level we will have clip,but i mean,what sound clipping not constantly,but in some positions. May be exists some algorithm,how to compute max volume,which i can use for bass in windows,which guaranty will not cause clipping for any sound or may be you know this value? 3. can i unset loop flag for channel,which was loaded from hsample,via BASS_SampleLoad() function with loop flag,or for hsample i should use other way?

Ian @ un4seen

  • Administrator
  • Posts: 26172
1. yes,i know,what i can remove callback,but now i should add aditional variable for each sound (because we have structure,which have information about sound).

If you already have a structure for each sound then adding a variable/flag to it (to tell if the END sync was called) would be a simple solution?

2. I know,what with high volume level we will have clip,but i mean,what sound clipping not constantly,but in some positions. May be exists some algorithm,how to compute max volume,which i can use for bass in windows,which guaranty will not cause clipping for any sound or may be you know this value?

You can create a decoding channel (with BASS_STREAM_DECODE set) for the file and then use BASS_ChannelGetLevelEx to get its peak level. For example, like this:

Code: [Select]
HSTREAM decoder = BASS_StreamCreateFile(false, filename, 0, 0, BASS_SAMPLE_FLOAT | BASS_STREAM_DECODE); // create decoder for file
float level;
BASS_ChannelGetLevelEx(decoder, &level, 10000, BASS_LEVEL_MONO); // get peak level in "level" variable
BASS_StreamFree(decoder); // free decoder

You can replace the BASS_StreamCreateFile call with BASS_SampleGetChannel (and BASS_SAMCHAN_STREAM) if you want to get the peak level of an existing sample.

3. can i unset loop flag for channel,which was loaded from hsample,via BASS_SampleLoad() function with loop flag,or for hsample i should use other way?

You can use BASS_ChannelFlags to set/unset the BASS_SAMPLE_LOOP flag on an HCHANNEL handle. If you want to change a sample's default setting (used by BASS_SampleGetChannel) then you can do that via BASS_SampleSetInfo.

sashakozlovskiy

  • Posts: 54
I tryed to get max level,using your ideas (with flags mono and stereo),but for now i have level less than 0. How i can use this value to compute max level volume which i can set for the track? About looping,how i can set/unset loop for hsample,if looping,which i set to hchannel,which i get from hsample,will not works?

Ian @ un4seen

  • Administrator
  • Posts: 26172
I tryed to get max level,using your ideas (with flags mono and stereo),but for now i have level less than 0.

That sounds like you may be receiving the level from BASS_ChannelGetLevelEx incorrectly. Please show what that call looks like, including the "level" variable declaration. Also check the BASS_ChannelGetLevelEx return value to confirm whether it was successful.

How i can use this value to compute max level volume which i can set for the track?

maxlevel without clipping = 1.0 / level from BASS_ChannelGetLevelEx

About looping,how i can set/unset loop for hsample,if looping,which i set to hchannel,which i get from hsample,will not works?

BASS_ChannelFlags can be used on HCHANNEL handles, and BASS_SampleSetInfo on HSAMPLE handles.

sashakozlovskiy

  • Posts: 54
Hello again. method BASS_ChannelGetLevelEx returns false.
Code: [Select]
back_channel =BASS_SampleGetChannel(sam, BASS_SAMCHAN_STREAM);
float level;
BOOL success =BASS_ChannelGetLevelEx(back_channel, &level, 10000, BASS_LEVEL_MONO);
char buf[32];
snprintf(buf, sizeof(buf),L"%f", level);
MessageBoxA(0, buf, "", 0);
BASS_ChannelPlay(back_channel, FALSE);
It very interesting for me,what is the sound level. How you compute this and why 1/level it max volume of sound without clipping? I defended my diploma and part of it was generation of sound using sign wave with diferent frequences and amplitudes,so it very interesting for me,what is this level. About looping i understand,what i can't use functions for channels to sample,but i mean can i set/unset loop for channels from hsample. Sample,as i understand,not support some file extensions,therefore for not supported file extensions i use hmusic. So,can i set/unset loop flags for channels from hsample,or i should check and if i have hsample,i should set loop for hsample,and if not - for hchannel. For now i set/unset loop to channel,even if it was get from hsample,and it seems,it works.

Ian @ un4seen

  • Administrator
  • Posts: 26172
Adding the BASS_STREAM_DECODE flag to your BASS_SampleGetChannel call should allow BASS_ChannelGetLevelEx to work. Note you won't be able to play that stream - you will need to create another one without the BASS_STREAM_DECODE flag for playback.

sashakozlovskiy

  • Posts: 54
O,thank you very much. With flag BASS_STREAM_DECODE i get for one track 0.911713,and for other - value between 0.1 and 0.2. So 1/0.911713 is near 1.0. But i set volume for this track 10.0 and it wasn't any clipping. For second track i set volume 128,and it wasn't clipping. Yes,on some values when i increase volume i haven't any efect,i.e it was the same sound volume,and only in some large values we have clipping and even sound overloading,but for second track,for example,it was near 128,but 1/level_of_second_track is near 33. Can i do the same for hmusic. As i understand,to play channel after computing of max volume,i should recreate hsample and hmusic,or it enough unset flags from it? Please,reply,how you compute max level for hchannel?

Ian @ un4seen

  • Administrator
  • Posts: 26172
So 1/0.911713 is near 1.0. But i set volume for this track 10.0 and it wasn't any clipping. For second track i set volume 128,and it wasn't clipping.

If that's on Windows then it's probably Windows' limiter bringing the level back down. If you would like to check what BASS's output is, you can do so by writing it to a WAV file and loading that in a sample editor. You can write the WAV file using the BASSenc add-on like this:

Code: [Select]
devstream = BASS_StreamCreate(0, 0, 0, STREAMPROC_DEVICE, 0); // get device stream
BASS_Encode_Start(devstream, "bass.wav", BASS_ENCODE_PCM | BASS_ENCODE_AUTOFREE, 0, 0); // set WAV writer on it

Can i do the same for hmusic.

Yes, BASS_ChannelGetLevelEx works with HMUSIC handles too.

As i understand,to play channel after computing of max volume,i should recreate hsample and hmusic,or it enough unset flags from it?

It isn't possible to unset the BASS_STREAM_DECODE flag (or BASS_MUSIC_DECODE), so you will need to recreate the channel without that flag for playback.

Please,reply,how you compute max level for hchannel?

HCHANNELs and HSTREAMs from the same HSAMPLE will have the same sample data, so you can use the same code to get the level.

sashakozlovskiy

  • Posts: 54
1. Can you recommend to me,what sample editor i can use,to get max level of wave file,without windows limitations? My favourite language of programming is python,so may be exists library,which compute this level. 2. About computing of max level,i mean what formulas you use,to compute it? What name of this variable,i.e max_level to i can find info about it in wikipedia? 3. Now i noticed,playing some track in vlc,what it have panning,but bass library play it almost without panning. How can i fix it for hsample,hstream and for hmusic? 4. In some cases i need in simultaneously playing of the same sound. Should i for this create separate hsample,hchannel,hmusic or hstream. Sdl_mixer library,from which i rewrite some extension,have seperate channels (max 8) and for each channel i can set specific sound. But bass works using another way. i have structure for each sound,which have own hchannel and hsample,and i also have array with size 8,which contains structure with structure sound*. But recently i understood,what if creator of some quest will want to play two or more the same sound simultaneously,it can't do this,because i not supported this feature. So,how i can play simultaneously the same sound,and,if it need,stop some instance of this sound? Thank you very much for your help.

Ian @ un4seen

  • Administrator
  • Posts: 26172
1. Can you recommend to me,what sample editor i can use,to get max level of wave file,without windows limitations?

I think the most common/popular free sample editor is Audacity, which is available for Windows/Linux/Mac here:

      https://www.audacityteam.org/

About computing of max level,i mean what formulas you use,to compute it? What name of this variable,i.e max_level to i can find info about it in wikipedia?

BASS_ChannelGetLevelEx (without BASS_LEVEL_RMS) simply checks the decoded sample data and returns the peak/highest absolute value from it.

Now i noticed,playing some track in vlc,what it have panning,but bass library play it almost without panning. How can i fix it for hsample,hstream and for hmusic?

What format(s) is that with? It isn't really possible for pre-mixed formats like WAV/MP3/etc to have different panning (all decoders should give the same result), but with MOD formats (ie. when using BASS_MusicLoad) you can adjust the stereo separation via the BASS_ATTRIB_MUSIC_PANSEP setting.

In some cases i need in simultaneously playing of the same sound. Should i for this create separate hsample,hchannel,hmusic or hstream. Sdl_mixer library,from which i rewrite some extension,have seperate channels (max 8) and for each channel i can set specific sound. But bass works using another way. i have structure for each sound,which have own hchannel and hsample,and i also have array with size 8,which contains structure with structure sound*. But recently i understood,what if creator of some quest will want to play two or more the same sound simultaneously,it can't do this,because i not supported this feature. So,how i can play simultaneously the same sound,and,if it need,stop some instance of this sound?

If a sound will be played simultaneously and quite often, then I would suggest using the sample functions for it, eg. BASS_SampleLoad. And use BASS_SampleGetChannel to create either a HCHANNEL or HSTREAM, depending on what features you need. You can use BASS_ChannelStop/Free to stop/free any of them. Note that BASS_ChannelStop will also free a HCHANNEL (you can use BASS_ChannelPause instead if you want to resume it later).

sashakozlovskiy

  • Posts: 54
O,i dont know,what bass_channel_stop will free channel. i thought,i can reuse it later to play. It actual for hsample channel,or for hmusic too? So bass_sample_backchannel will constantly create a new hchannel? And what about hmusic,i.e how i can play several tracks at the same time? About track,it have ogg format and i play it with hsample. I tryed to use bass_sample_3d flags and directsound differently,but it not help to me. You can try to download and test track with vlc https://disk.yandex.ru/d/sS3pPQ1TK_BbyQ. The panning will be noticed almost immediately. But with hsample we almost haven't panning.

Ian @ un4seen

  • Administrator
  • Posts: 26172
O,i dont know,what bass_channel_stop will free channel. i thought,i can reuse it later to play. It actual for hsample channel,or for hmusic too? So bass_sample_backchannel will constantly create a new hchannel?

BASS_ChannelStop only frees HCHANNEL handles, not HMUSIC or HSTREAM, as mentioned in the BASS_ChannelStop documentation ;) ... Please do check the documentation of any functions that you are using for info on them, as the answers to many of your questions are in there.

Please also note that BASS_SampleGetChannel automatically recycles HCHANNELs if the BASS_SAMCHAN_NEW flag isn't specified, so there is usually no need to free/manage them yourself.

And what about hmusic,i.e how i can play several tracks at the same time?

Playing multiple HMUSIC (MOD music) simply requires calling BASS_MusicLoad and BASS_ChannelPlay/Start for each file.

About track,it have ogg format and i play it with hsample. I tryed to use bass_sample_3d flags and directsound differently,but it not help to me. You can try to download and test track with vlc https://disk.yandex.ru/d/sS3pPQ1TK_BbyQ. The panning will be noticed almost immediately. But with hsample we almost haven't panning.

Oh, are you using the BASS_SAMPLE_3D flag? If so, please note that 3D channels need to be mono, and so if the BASS_SampleLoad call is succeeding then I guess you must also be requesting mono conversion by including the BASS_SAMPLE_MONO flag, or because BASS_DEVICE_MONO was included in your BASS_Init call?

sashakozlovskiy

  • Posts: 54
O,thank you very much. I don't knew,what without setting bass_channel_new hchannel will be freed. I tryed to stop hchannel from hsample,and play it again,and it seems,it play,i.e not free,but i will check it again.About playing of several hmusic,i want to play the same file simultaneously twice or more,so i should create new instance of hmusic for this,because for sample it enough get new channel. About a 3d playing,whether you tryed to play my track. How to play it with panning?