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

Started by sashakozlovskiy,

Ian @ un4seen

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

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

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

Hello again. method BASS_ChannelGetLevelEx returns false.
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

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

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

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

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

Quote from: sashakozlovskiyCan i do the same for hmusic.

Yes, BASS_ChannelGetLevelEx works with HMUSIC handles too.

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

Quote from: sashakozlovskiyPlease,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

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

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

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

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

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

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

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

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

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

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?

sashakozlovskiy

I mean,may be it possible to play this track without 3d flag? May be bass not support fully panning for this types of track?

Ian @ un4seen

Are you currently using the BASS_SAMPLE_3D and/or BASS_SAMPLE_MONO flag on the file? If so, you will need to remove those flags for stereo playback. If it still isn't sounding right in your app then please try playing it with one of the pre-compiled examples included in the BASS package (C\BIN folder) for comparison.

sashakozlovskiy

I not use bas_sample_3d flag
//init device
   if (BASS_Init(-1, 48000, BASS_DEVICE_DEFAULT | BASS_DEVICE_FREQ, 0, NULL) == 0) {
      gBassInit = 0;
   }
//load sample (other part of code)
      *sam = BASS_SampleLoad(FALSE, mus, 0, 0, 1, loop_flag);

I tryed to use stereo flag,when i init device,but i haven't any efect. Whether you listened track,which i sent? Whether you noticed,what it have panning,but via bass we haven't it?

Ian @ un4seen

Please clarify what exactly the problem is, eg. what you mean by "haven't panning". I assumed you meant the file sounds mono instead of stereo, but is that not the case? Please do also check if you can reproduce the problem with the pre-compiled BASS examples.

sashakozlovskiy

How i can clarify,if you not listen track,which i sent? you should listen,and only in this case you will understand difference between playing in winamp and in bass. In winamp or vlc we have two channels: left and right,and it move from left to right and from right to left. In bass it almost not notice. Why you dont want to listen this track? May be it bass issue,which should be fixed?

Ian @ un4seen

I have tried playing the file and it sounds fine. That's why I asked you to explain what problem you're hearing, and to try to reproduce it with the pre-compiled BASS examples.

sashakozlovskiy

As we understand with my friend,bass convert stereo sound in mono even without mono flag. Yes,i can add stereo flag during initialization of bass,but in bass doc we have,what this flag limit features of track to stereo,so if track will be more than stereo,it will convert to stereo. Also we have noticed other problem: In xm files,when first part of music was finished and we have silence,second part of music is not playing. Probably it calls my callback,which free channel after playing,but i not debugged it yet.

sashakozlovskiy

deleting BASS_DEVICE_DEFAULT flag fixed first problem,so for now i use only BASS_DEVICE_FREQ flag,i.e now it plays almost as in vlc player. But i thought,what via this flag bass will play all via default device in system without any conversion to mono. It very interesting,if i will disconnect my device and reconect it again,whether bass continue play tracks via this device,orr no. If i will disconnect my device,whether playing will continue on other device,i.e via speakers instead of headsets,as it works for most players?

sashakozlovskiy

Also my friend said,what playing of .xm files more better in open mpt,than in bass. How i can improve quality of playing .xm files in bass? I tryed use /*BASS_SAMPLE_FLOAT | */BASS_MUSIC_SINCINTER| BASS_MUSIC_FT2MOD| BASS_MUSIC_FT2PAN flags and i hope ,what quality of playing .xm files will be improved,but may be i can do something else? I saw flags,which allows to apply surround and surround 2 modes. What difference between this modes? Also whether can be situation,when flag BASS_SAMPLE_FLOAT or any other flags decrease quality of sound,instead of increasing of it,especially i doubt about BASS_SAMPLE_FLOAT flag?

Ian @ un4seen

Quote from: sashakozlovskiydeleting BASS_DEVICE_DEFAULT flag fixed first problem

Oh yes, I see now that BASS_DEVICE_DEFAULT was included in the "flags" parameters of the BASS_Init call that you posted earlier. Please note that BASS_DEVICE_DEFAULT is not a valid BASS_Init flag (valid flags are listed in the BASS_Init documentation), and its value is 2, which is the same as BASS_DEVICE_MONO, so you were effectively using the BASS_DEVICE_MONO flag in your BASS_Init call.

Quote from: sashakozlovskiyIt very interesting,if i will disconnect my device and reconect it again,whether bass continue play tracks via this device,orr no. If i will disconnect my device,whether playing will continue on other device,i.e via speakers instead of headsets,as it works for most players?

If you use the "Default" BASS device then it will do, assuming that the system's default device setting is automatically switching back to the reconnected device.

Quote from: sashakozlovskiyAlso my friend said,what playing of .xm files more better in open mpt,than in bass. How i can improve quality of playing .xm files in bass? I tryed use /*BASS_SAMPLE_FLOAT | */BASS_MUSIC_SINCINTER| BASS_MUSIC_FT2MOD| BASS_MUSIC_FT2PAN flags and i hope ,what quality of playing .xm files will be improved,but may be i can do something else? I saw flags,which allows to apply surround and surround 2 modes. What difference between this modes? Also whether can be situation,when flag BASS_SAMPLE_FLOAT or any other flags decrease quality of sound,instead of increasing of it,especially i doubt about BASS_SAMPLE_FLOAT flag?

BASS_MUSIC_SINCINTER and BASS_SAMPLE_FLOAT will improve sound quality (assuming you want to reduce aliasing/distortion). BASS_MUSIC_FT2MOD and BASS_MUSIC_FT2PAN won't affect sound quality. Please see the BASS_MusicLoad documentation for descriptions of what these flags do.