Stopping a channel at mixtime sync

Started by gicci,

gicci

I have a MIDI channel, plugged in a Mixer that handles the playback, on which I set a mixtime sync at a specific position (through the mixer).
If I use BASS_ChannelSetPosition to make the music loop, everything works correctly.
If I use BASS_ChannelStop to make the music stop at that position, it stops immediately without waiting the remaining buffer to be played.

Is this the intended way it should work (it doesn't seem so reading the "SYNCPROC callback" manual)?
If yes how can I stop the playback precisely at a specific position?

Ian @ un4seen

What type of sync are you using (eg. BASS_SYNC_POS or BASS_SYNC_MIDI_TICK) and are you setting it on the mixer or the MIDI stream? And are you calling BASS_ChannelStop on the mixer or the MIDI stream in the SYNCPROC?

gicci

The sync is set with BASS_SYNC_MIDI_TICK via BASS_Mixer_ChannelSetSync().
To stop I call BASS_ChannelStop() on the MIDI channel.

Ian @ un4seen

For custom looping/ending purposes, you can use BASS_ChannelSetSync instead of BASS_Mixer_ChannelSetSync, but BASS_Mixer_ChannelSetSync with BASS_SYNC_MIXTIME should work the same. Calling BASS_ChannelStop (on the MIDI stream) in the SYNCPROC will end the MIDI stream but it won't stop the mixer playing any buffered data, so it'd be strange if you find it does. What do BASS_ChannelGetPosition and BASS_Mixer_ChannelGetPosition say the MIDI stream's position is when the mixer ends? Note that the position may be slightly beyond the sync's position because calling BASS_ChannelStop in a BASS_SYNC_MIDI_TICK sync (unlike a BASS_SYNC_POS sync) actually won't end the stream until the end of the current update cycle (this should be improved in the next release).

Instead of calling BASS_ChannelStop in the SYNCPROC, you can send a MIDI_EVENT_END event to end the MIDI stream more precisely and gracefully (with support for BASS_MIDI_DECAYEND):

BASS_MIDI_StreamEvent(handle, 0, MIDI_EVENT_END, 0);

gicci

The position in the MIDI channel and in the mixer are the same.

I found the problem, and it was my fault: since the channel stop doesn't trigger the end sync, I was simulating it at mix time, which inadvertently halted playback.

Your suggestion of streaming an end event was the right solution after all, since it triggers the end sync properly.