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

sashakozlovskiy

  • Posts: 54
Yes,i noticed,what with bass_mixtime flag bass behaviour is sometimes incorrect,e.g file plays partially,etc. But if i delete this flag,i will have problems with some files,which played partially (see messages above)? Whether i should create two separate callbacks for this (one with mixtime,and second without it),or it exists more better solution? This solution should works for loops too,i.e for each loop callback should call too,if we have loops,as it works now. If not,whether function for callback with mixtime will call guaranty first? Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 26218
If you're using the mixtime BASS_SYNC_END sync for looping and would like to stop looping at some point, then you can simply have the SYNCPROC do nothing at that point:

Code: [Select]
void CALLBACK EndSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
if (loop_enabled) BASS_ChannelSetPosition(channel, loop_start, BASS_POS_BYTE);
}

Make sure you don't have the BASS_SAMPLE_LOOP flag set, otherwise it'll loop even if you don't call BASS_ChannelSetPosition there. If you want to free the stream at the end then use the BASS_STREAM_AUTOFREE flag for that (don't call BASS_ChannelFree in the SYNCPROC).

sashakozlovskiy

  • Posts: 54
Ok,i mean if file have continuation we should use mixtime flag,to catch end of buffering of it,but if this file haven't continuation,or second and other parts of this file was played,it stops,because i free resources. But in this case,as you wrote before,and i noticed it too,file can play not fully,because with mixtime flag finish_callback calls when buffering was finished,but not playing. So i asked you,how to solve this problem,i.e should i create separate syncprocs with mixtime flag,and without it,to catch firstly end of buffering,to continue playing,or it can be solved more simpler. To you can understand what i mean,you can read your explanation of situation at http://www.un4seen.com/forum/?topic=20037.msg140533#msg140533. Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 26218
The code in that linked post should work fine with the code/info in my last post, only the BASS_ChannelSetPosition call is different. Note you should not use BASS_SYNC_THREAD (or PostMessage) when looping in the SYNCPROC (that was just to allow you to free the channel in the SYNCPROC).

sashakozlovskiy

  • Posts: 54
Ok,but why when i use mixtime flag,my file play not fully (i mean situation without looping). You confirmed before,what i will have problems with this flag (http://www.un4seen.com/forum/?topic=20037.msg142377#msg142377).

Ian @ un4seen

  • Administrator
  • Posts: 26218
Are you still freeing the stream in the mixtime SYNCPROC? Note that "mixtime" means the sync is called when the decoder reaches the end, not when the end is heard (which is later due to buffering). So if you free the stream then, you won't hear it all.

sashakozlovskiy

  • Posts: 54
Yes,i want to free stream when playing was finnished and i can't continue playing of the stream. In fact i not only free stream,but do other things. So whether i should create two separate syncproc for this?

Ian @ un4seen

  • Administrator
  • Posts: 26218
Yes, if you want to do other things when the end is heard then you should also set a non-mixtime BASS_SYNC_END sync for that.

sashakozlovskiy

  • Posts: 54
And if we will have loop,whether this callback without mixtime will be called for each loop,or for loop we should use mixtime. My idea is to use separate syncproc for continuation of playing,and separate for end of playing to free stream (if we play file n times) or do something else. Also whether you plan add in bass documentation info about playing file issue,i.e situation,in which you help. Also i forgot to ask,why in your example with continuation of playing you use BASS_POS_MUSIC_ORDER flag?

Ian @ un4seen

  • Administrator
  • Posts: 26218
And if we will have loop,whether this callback without mixtime will be called for each loop,or for loop we should use mixtime. My idea is to use separate syncproc for continuation of playing,and separate for end of playing to free stream (if we play file n times) or do something else.

Looping syncs must be mixtime (without BASS_SYNC_THREAD). If you want to free the channel in the SYNCPROC then it must NOT be mixtime (or else use BASS_SYNC_THREAD). For anything else, it's up to you to decide if you want the sync when the decoder reaches the end (mixtime) or when the end is heard (not mixtime).

Also i forgot to ask,why in your example with continuation of playing you use BASS_POS_MUSIC_ORDER flag?

That's because it's seeking to the next "order" in a MOD music (HMUSIC).

sashakozlovskiy

  • Posts: 54
It very interesting,why looping will not works with bass_sync_thread? Also if we need in mixtime callback for looping,it very difficult to solve it,because i want to play file n times,and after latest playing i want to stopp/free it. But if i will stopp it,this file will be played partially,because of mixtime flag,or it exists way to do,what callback will called,when playing of file was finished after the latest loop?

Ian @ un4seen

  • Administrator
  • Posts: 26218
It very interesting,why looping will not works with bass_sync_thread?

Because the decoder's thread continues running in the meantime (it doesn't wait for your SYNCPROC running in another thread). Looping needs to be done in the decoder's thread.

Also if we need in mixtime callback for looping,it very difficult to solve it,because i want to play file n times,and after latest playing i want to stopp/free it. But if i will stopp it,this file will be played partially,because of mixtime flag,or it exists way to do,what callback will called,when playing of file was finished after the latest loop?

I would suggest that you do what I wrote in reply #76. Simply do nothing in the SYNCPROC when you want to stop looping (eg. after N loops), and set the BASS_STREAM_AUTOFREE flag if you want it freed after ending.

sashakozlovskiy

  • Posts: 54
Ok,so you suggest after latest loop call BASS_ChannelSetPosition(channel, loop_start, BASS_POS_BYTE);,but at first would we should use instead loop_start,to stopp channel after latest loop at the end of playing,and whether it will stop playing at the end of playing but not at the end of buffering,because we use mixtime flag. May  be it exists way to do,what finish callback call too? If not,please help me how to stop playing at the end of llatest loop.

sashakozlovskiy

  • Posts: 54
The second solution is inside callback delete loop_flag from channel,if it possible. In this case finish callback should be call? Whether this solution possible? If not,i will try your solution,if you will reply on my previous post. Thanks.

sashakozlovskiy

  • Posts: 54
I noticed,what even without mixtime flag finishcallback calls (whether it intended behaviour),but i can't stop channel inside this callback. When bass_channelStop was called,it become small pause and looping continue again (why pause happens,because if playing not stopped,it shouldn't be pause,because for now it seems,what bass try to stop channel (we have pause,as i wrote) but can't do this). But when i call bass_channelFree inside finish callback without mixtime flag,playing stop,but i not always want to free channels but only,for example,stop it. For example i try to do inside finish callback without mixtime:
            BASS_ChannelFlags(channel, 0, BASS_SAMPLE_LOOP);
            BASS_ChannelStop(channel);
But it give me no effect.

Ian @ un4seen

  • Administrator
  • Posts: 26218
Ok,so you suggest after latest loop call BASS_ChannelSetPosition(channel, loop_start, BASS_POS_BYTE);,but at first would we should use instead loop_start,to stopp channel after latest loop at the end of playing,and whether it will stop playing at the end of playing but not at the end of buffering,because we use mixtime flag. May  be it exists way to do,what finish callback call too? If not,please help me how to stop playing at the end of llatest loop.

Your SYNCPROC should call BASS_ChannelSetPosition when you want to loop, and do nothing when you want to end. If you don't call BASS_ChannelSetPosition then it won't loop, so long as you don't have the BASS_SAMPLE_LOOP flag set.

sashakozlovskiy

  • Posts: 54
Ok. As i noticed,finish_callback calls for each loop and stopping of channel and reseting of the loop flag helps me. Now it seems,what it works as expected. Also i free channel inside finish callback (separate sinc,which i call,when playing was finished (not buffering) and which calls each loop,and i haven't any crash now). As i wrote before,please add in bass documentation example,which shows,how to fix issue,if bass playing track partially,to other people can fix this too,if they have the same issue. Also i have a question,whether i should free and init bass again,including bass addons,if i want to change hz of device,or it exists more easier way to do this.

Ian @ un4seen

  • Administrator
  • Posts: 26218
You can use the BASS_DEVICE_REINIT and BASS_DEVICE_FREQ flags with BASS_Init to change the device's rate while preserving BASS channels, but note that will have no effect on some platforms (eg. the rate needs to be set via the Sound control panel on Windows). Please see the BASS_Init documentation for details.