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

Started by sashakozlovskiy,

Ian @ un4seen

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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.