How to catch finishing of playing of hsample,hchannel and/or hmusic

Started by sashakozlovskiy,

Ian @ un4seen

Quote from: sashakozlovskiy1. If i created channel from hsample,and want to free sound,it enough call bass_channelFree (or bass_musicFree or bass_streamFree) and i shouldn't call bass_sampleFree?

Yes. If you want to free a single sample channel then you should not call BASS_SampleFree because it will all of them (from the same sample).

Quote from: sashakozlovskiy2. So,i can't get direct file path even from hstream channel? Why features of hsample so limited? Why we can't set callbacks to it,but should create stream for this,get file name from channels,created from hsample,etc. Why we can't get direct file path,which we set for specific channel?

Sample channels don't have all the features of streams because they are meant to be as lightweight as possible, ie. minimal CPU and memory usage. When the extra features (eg. syncs) are needed then you can create a stream instead by using the BASS_SAMCHAN_STREAM flag with BASS_SampleGetChannel.

sashakozlovskiy

1. But if i want fully free some hsample,whether it enough call bass_sample_free,or i should free channel too?
2. I thought,what hsample use other algorithm,than stream,so it use less cpu,but it also not contains some usefull features. Because if,for example,hsample allow to use callbacks,i shouldn't add stream flag for hchannel,so it required less RAM,than stream. In my opinion stream useful only in case,when we dynamically load new data,i.e internet stream or some bytes,i.e which we get during generation of sine wave. In other cases,in my opinion,it enough hsample.

Ian @ un4seen

BASS_SampleFree frees all of a sample's channels (HCHANNEL and HSTREAM), so there is no need to call BASS_ChannelFree then too.

sashakozlovskiy

Hello again. I have a several new questions about your library. 1. what is the param user* data in callback. Can i insert some value. I rewriting some file,which before me use sdl library,so i want to insert in it,for example,channel number (from 0 to 7 ait channels in sdl lib). But for music (because i also use sound) i want to set -1. Can i set this editional data,or no? 2. Can i dynamically load short* buff (generated array of bytes) to play it and get callback,when playing was finished? If yes,may be exists example,how to do it? Additionally i have a question,how correct send callback,to get it not only after finishing of playing,but each changing of position and how i can get this position in callback and understand,whether playing was finished? 3. In sdl we can set panning from 0 to 255 for left and right channel separately. In bass we can set only panning for one channel from -1 to 1 (1 it right). But may be exists way,to set volume for left/right channel instead of it,such as it works in sdl? 4. Whether it possible play hsample/hchannel with fading? If yes,how i can do this? Thank you very much for your help.

Ian @ un4seen

Quote from: sashakozlovskiywhat is the param user* data in callback. Can i insert some value. I rewriting some file,which before me use sdl library,so i want to insert in it,for example,channel number (from 0 to 7 ait channels in sdl lib). But for music (because i also use sound) i want to set -1. Can i set this editional data,or no?

You can set the callback's "user" parameter value in your BASS_ChannelSetSync call.

Quote from: sashakozlovskiyCan i dynamically load short* buff (generated array of bytes) to play it and get callback,when playing was finished? If yes,may be exists example,how to do it? Additionally i have a question,how correct send callback,to get it not only after finishing of playing,but each changing of position and how i can get this position in callback and understand,whether playing was finished?

If you want to stick with sample functions then you could use BASS_SampleCreate and BASS_SampleSetData (instead of BASS_SampleLoad) for custom generated data. Alternatively, you could use BASS_StreamCreate. Please see the documentation for details on those functions.

Quote from: sashakozlovskiyIn sdl we can set panning from 0 to 255 for left and right channel separately. In bass we can set only panning for one channel from -1 to 1 (1 it right). But may be exists way,to set volume for left/right channel instead of it,such as it works in sdl?

You can use a combination of BASS_ATTRIB_VOL and BASS_ATTRIB_PAN settings, as described in this thread:

   www.un4seen.com/forum/?topic=17480

Quote from: sashakozlovskiyWhether it possible play hsample/hchannel with fading? If yes,how i can do this?

You can use BASS_ChannelSlideAttribute with BASS_ATTRIB_VOL to fade-in/out. Note that if you want a fade-out to start at a specific position then you will probably need to use a stream (HSTREAM) instead of a sample channel (HCHANNEL), so that you can set a BASS_SYNC_POS sync on it.

sashakozlovskiy

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

Quote from: sashakozlovskiyCan 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.

Quote from: sashakozlovskiyCan 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.

Quote from: sashakozlovskiyHow 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

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

yes
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

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

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

Quote from: sashakozlovskiy1. 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.

Quote from: sashakozlovskiy2. 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).

Quote from: sashakozlovskiy3. 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.

Quote from: sashakozlovskiy4. 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.

Quote from: sashakozlovskiy5. 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

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

Quote from: sashakozlovskiy1. 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.

Quote from: sashakozlovskiy2. 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.

Quote from: sashakozlovskiy3. 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

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?

sashakozlovskiy

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

Quote from: sashakozlovskiy1. 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.

Quote from: sashakozlovskiy2. 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.

Quote from: sashakozlovskiy3. 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.
 
Quote from: sashakozlovskiy4. 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:

BASS_ChannelSetAttribute(handle, BASS_ATTRIB_VOL, channel_volume * global_volume);

Quote from: sashakozlovskiy5. 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:

DWORD flags = BASS_ChannelFlags(handle, 0, 0);

sashakozlovskiy

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

Quote from: sashakozlovskiy1. 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?

Quote from: sashakozlovskiy2. 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:

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.

Quote from: sashakozlovskiy3. 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

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?