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

sashakozlovskiy

  • Posts: 54
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

  • Administrator
  • Posts: 26177
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

  • Posts: 54
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

  • Administrator
  • Posts: 26177
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

  • Posts: 54
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

  • Administrator
  • Posts: 26177
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

  • Posts: 54
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

  • Posts: 54
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

  • Posts: 54
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

  • Administrator
  • Posts: 26177
deleting 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.

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?

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.

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?

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.

sashakozlovskiy

  • Posts: 54
Thank you very mutch for your replies. Yes,i understand,what  BASS_MUSIC_FT2MOD| BASS_MUSIC_FT2PAN flags not improve quality of sound,but improve sound panning for .xm and .mod files. So to improve quality it enough use BASS_SAMPLE_FLOAT|BASS_MUSIC_SINCINTER flags,and for sample only BASS_SAMPLE_FLOAT,or i can do anything else to improve sound quality of playing .xm files? I not noticed problems with sound quality,but my friend said,what open mpt play .xm files more better,than bass,i.e bass have not so clear sound in .xm music,and he ask to me rewrite sound part,using open mpt,but i dont want to do this and hope,what in bass exists features how to improve sound quality for .xm and .mod files . As i understand,BASS_MUSIC_SINCINTER flag not improve sound quality for my friend (i not add BASS_SAMPLE_FLOAT flag,because i not sure,whether it will works ok if,for example,we have 16 bits sound,because according to documentation this flag works with 32 bits and if we wil try increase bitrate of sound,we can get distortion of sound). Also you not reply about BASS_MUSIC_SURROUND and BASS_MUSIC_SURROUND2 flags. What this modes do. What is the ramping of tracks? Also in some xm files first part of track playing with looping,but it should play also second part of track,after silence.

Ian @ un4seen

  • Administrator
  • Posts: 26177
I would generally recommend using the BASS_MUSIC_SINCINTER + BASS_MUSIC_RAMPS + BASS_SAMPLE_FLOAT flags. But note that old tracker software didn't have sinc interpolation, so if you want it to sound closer to the original then you would remove the BASS_MUSIC_SINCINTER flag. For really old .MOD files (not .XM), you may want to use BASS_MUSIC_NONINTER for no interpolation at all.

BASS_MUSIC_SURROUND and BASS_MUSIC_SURROUND2 apply the surround sound effects from XMPlay. You can try them to see if you may want to use them.

Regarding ramping, from the BASS_MusicLoad documentation:

Quote
"Ramping" does not take a lot of extra processing and improves the sound quality by removing clicks, by ramping/smoothing volume and pan changes. The start of a sample may also be ramped-in. That is always the case with XM files (or MOD files in FT2 mode) when using normal ramping, and possibly with all formats when using sensitive ramping; senstitive ramping will only ramp-in when necessary to avoid a click. Generally, normal ramping is recommended for XM files, and sensitive ramping for the other formats, but some XM files may also sound better using sensitive ramping.

sashakozlovskiy

  • Posts: 54
Ok,please,how to play this file with the best quality via bass (change extension on .xm,because page not allow to load this type of files). I also send this file,because i have more serious issue: when i try play it with looping,it play only first part of this file. But we have pause and the second part of this file. How to fix it? Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 26177
Personally, I would use BASS_MUSIC_SINCINTER + BASS_MUSIC_RAMPS + BASS_SAMPLE_FLOAT flags. But BASS_MUSIC_RAMP alone may be closer to the original FT2 sound.

Regarding the "play only first part of this file" issue, that file contains an "F00" command which means to stop. So BASS will end it at that point (and restart if BASS_SAMPLE_LOOP is set). You can make it jump to the next "order" instead with a mixtime BASS_SYNC_END sync, like this:

Code: [Select]
BASS_ChannelSetSync(hmusic, BASS_SYNC_END | BASS_SYNC_MIXTIME, 0, EndSyncProc, 0); // set mixtime END sync

...

void CALLBACK EndSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
DWORD order = LOWORD(BASS_ChannelGetPosition(channel, BASS_POS_MUSIC_ORDER | BASS_POS_DECODE)); // get current order position
BASS_ChannelSetPosition(channel, order + 1, BASS_POS_MUSIC_ORDER); // try jumping to the next order
}

If the BASS_ChannelSetPosition call succeeds then playback will continue from that position. Otherwise it will remain ended.

sashakozlovskiy

  • Posts: 54
O thank you very much. May God bless to you and may Saint Xenia of St. Petersburg always  prays for you. Now all works wonderful,i mean now it plays two parts of file. Can you please add this details in some parts of bass documentation and add flag,which allow bass play files while it will be end of file. But i not understand why for getting of position we should use BASS_POS_DECODE,and for setting we not should use this or similar flag and why it not works without BASS_SYNC_MIXTIME flag? Why you not recomended include ft2pan flag to do sound more similar to original? Thank you very much

Ian @ un4seen

  • Administrator
  • Posts: 26177
The BASS_SYNC_MIXTIME flag means the sync is called immediately when its triggered, instead of it being delayed until its position is heard (which is later due to buffering). Similarly, the BASS_POS_DECODE flag tells BASS_ChannelGetPosition to give the decoder's position instead of the playback/heard position. They are needed in this case so that the position change happens as soon as the end is reached.

Regarding the BASS_MUSIC_FT2PAN flag, you can certainly use it if you want to get closer to the original FT2 sound.

sashakozlovskiy

  • Posts: 54
Hello. In this year i noticed,what bass call crash of my app when i call bass_samplefree or bass_channelfree. This happens,when audio ducking finish callback was called,i.e when ducking was finished and if ducking ms more then track length (because it exists some cases and i not check this situation). Here is my parts of example on c++.
```
#include "bass.h"
static    HSAMPLE h;
static HCHANNEL c;
static void CALLBACK finishCallback(HSYNC handle, DWORD channel, DWORD data, void* user) {
//If we have ducking,if any of this lines will be executed,we will have crash.
   BASS_SampleFree(h);
   BASS_ChannelFree(c);
}
//init and play content
//some function
static void play() {
   if (BASS_Init(-1, 48000, BASS_DEVICE_FREQ, 0, NULL) == 0) {
//error
   }
   //Подключение плагинов
   BASS_PluginLoad("bassmidi.dll", 0);
   //Шрифт для миди
   HSOUNDFONT newfont = BASS_MIDI_FontInit("chorium.sf2", 0);
   if (newfont) {
      BASS_MIDI_FONT sf;
      sf.font = newfont;
      sf.preset = -1; // use all presets
      sf.bank = 0; // use default bank(s)
      BASS_MIDI_StreamSetFonts(0, &sf, 1);    // set default soundfont
      //BASS_MIDI_FontFree(font);             // free old soundfont
   }
   h = BASS_SampleLoad(FALSE, "title.ogg", 0, 0, 1, BASS_SAMPLE_FLOAT);
   c = BASS_SampleGetChannel(h, BASS_SAMCHAN_STREAM | BASS_SAMCHAN_NEW);
   BASS_ChannelSetAttribute(c, BASS_ATTRIB_VOL, 1.0f);
   BASS_ChannelSetSync(c, /*BASS_SYNC_ONETIME |*/ BASS_SYNC_MIXTIME | BASS_SYNC_END, 0, finishCallback, 0);
   BASS_ChannelSetSync(c, BASS_SYNC_SLIDE, 0, finishCallback, 0);
   BASS_ChannelSlideAttribute(c, BASS_ATTRIB_VOL, -1.0f, 7000);
   BASS_ChannelPlay(c, false);
}
```

In fact if playing was finished,i not free channel/hsample,but i created it as sample. When firstly playing is finished,and callback call first time,there is no crash,but at the second time,when ducking was finished,we have this crash. It also strange,when if i delete two lines,connected with callbacks and write :
```
ASS_ChannelSetSync(c, BASS_SYNC_MIXTIME | BASS_SYNC_END| BASS_SYNC_SLIDE, 0, finishCallback, 0);
```
There is no callback executed.
I have crash on windows 11 in mfc c++ application with visual studio. You can upload file,which i play,at https://disk.yandex.com/d/pJCJfnKyaW_pdw. Thank you very much for your help.

Ian @ un4seen

  • Administrator
  • Posts: 26177
static void CALLBACK finishCallback(HSYNC handle, DWORD channel, DWORD data, void* user) {
//If we have ducking,if any of this lines will be executed,we will have crash.
   BASS_SampleFree(h);
   BASS_ChannelFree(c);
}
...
   BASS_ChannelSetSync(c, /*BASS_SYNC_ONETIME |*/ BASS_SYNC_MIXTIME | BASS_SYNC_END, 0, finishCallback, 0);

It isn't safe to free a BASS channel within its own mixtime SYNCPROC callback. Removing the BASS_SYNC_MIXTIME flag from the BASS_ChannelSetSync call should prevent the crash.

It also strange,when if i delete two lines,connected with callbacks and write :
```
ASS_ChannelSetSync(c, BASS_SYNC_MIXTIME | BASS_SYNC_END| BASS_SYNC_SLIDE, 0, finishCallback, 0);
```
There is no callback executed.

It isn't possible to have a single sync apply to multiple sync types, eg. BASS_SYNC_END and BASS_SYNC_SLIDE. A separate BASS_ChannelSetSync call is needed for each one.

sashakozlovskiy

  • Posts: 54
But,as you remember,i can't avoid using mixtime flag. Also before track,which i wrote,all was ok. Why crash hapens only when ducking callback used,i.e without ducking all ok. Also it's ok,if ducking in ms less  (probably and equal) than track length-current_position_in_ms. I think,it's a bass issue,because before it wass ok. Whether this crash reproduceable with my file and example of code (you can insert this code in any c++ application and use this track). How i can report this issue to bass,because,as i wrote,it happens only when we use callback,which allow to us catch end of audio ducking and it actual not for all tracks. Also it very strange,what bass_channelfree call crash even if it was called before for this channel. Also bass_samplefree flag cal crash in this case.

Ian @ un4seen

  • Administrator
  • Posts: 26177
As noted in the SYNCPROC documentation, a mixtime SYNCPROC has similar restrictions in what functions are safe to call within it as a STREAMPROC does, and BASS_ChannelFree (on the same handle) is one of the unsafe functions. BASS_SampleFree too in this case because that frees all of the sample's channels.

Are you sure you need the BASS_SYNC_END sync to be mixtime? Note that a mixtime BASS_SYNC_END sync is called before the end is heard (due to buffering), so you won't hear the whole file if you free the channel then. But if you're certain that you want to free it then, you can add the BASS_SYNC_THREAD flag to allow that.

sashakozlovskiy

  • Posts: 54
Yes,i need in it (please see previous posts,in whiich i wrote about issue,when file played partially,and you wrote,what it connected with some command 0ff (http://www.un4seen.com/forum/?topic=20037.msg140533#msg140533)). Also i need catch callback for each loop. Yes,i can use autofree flag,but i dont want to free it always,so do it inside callback - best solution for me. line             BASS_ChannelSetSync(back_channel, /*BASS_SYNC_ONETIME |*/ BASS_SYNC_MIXTIME | BASS_SYNC_THREAD|BASS_SYNC_END, 0, finishCallback, 0); helps me,but i not sure,what it will works for all cases. In my opinion it bass issue,which should be fixed because:
1. This happends,when we use callback for end of playing and for ducking (if we use callback only for end of playing,it seems we haven't this crash).
2. This happens only for track,which i send or,probably,for tracks,which have ducking interval more (or equals too,not sure) than trackLengthInMs-currentPositionInMs. In other cases,it seems,crash not happens,except,probably,some cases,because i am not sure,but it seems,what sometimes crash happens too,but this cases,about which i wrote before,it cases,in which with almost 100 percent probability i have crash.
3. This happens,even if hchannel/hsample was freed before (at least in my tests i noticed this). So,if you have explanation,why in this three cases we have crash,i want to know it. Because before,when i havent this cases,i havent any crashes.
« Last Edit: 26 Feb '24 - 21:09 by sashakozlovskiy »

Chris

  • Posts: 2217
Another possible Option can be in the Syncproc to do only a a PostMessage
and then in the MessageHandler to free the Channels.

sashakozlovskiy

  • Posts: 54
Ok. So you haven't explanation,why this crash happens only for specific cases? Can you please provide example,how to use PostMessage and catch end of playing/end of ducking at the same time. For now i use BASS_SYNC_THREAD flag inside callback,as i wrote before,and it seems,what it works ok,but whether it guaranty behaviour,i.e whether it will be no crash. Also please look at my example to know,whether it possible fix something in bass,because crash happens,as i wrote before,only in several conditions. Also please fix issue,about which you reply to me at http://www.un4seen.com/forum/?topic=20037.msg140533#msg140533,because,in my opinion,it should work without any trick or please add this example in bass documentation/basss examples,to any person,who have this or similar problems,can solve this problems,because if you wasn't help to me,i probably not fixed this issue or rewrote my code to use other library,instead of bass,but thanks to your help i solved partially playing issue and now all ok,so it should be documented,if bass not play all files fully without any tricks. If you have already added it in bass documentation,thank you very much for this.

Ian @ un4seen

  • Administrator
  • Posts: 26177
The code you posted above will crash because it's freeing a BASS channel within its own mixtime SYNCPROC. BASS_SYNC_THREAD (and PostMessage) will move the sync code to a different thread, which makes it safe to free the channel in it. This is noted in the SYNCPROC documentation, so I don't think there's any great mystery here. If you're getting an unexplained crash in another case (without that SYNCPROC) then please post that code.

sashakozlovskiy

  • Posts: 54
Yes,i understand,and now with BASS_SYNC_THREAD flag it seems i haven't this crash. But,as i wrote before,it crash only in several cases,but it should crash always without BASS_SYNC_THREAD flag.