Author Topic: BASS_ChannelLock hangs (solved)  (Read 767 times)

SoundMike

  • Posts: 331
BASS_ChannelLock hangs (solved)
« on: 22 Mar '12 - 01:26 »
I'm having BASS_ChannelLock hang consistently with the following scenario:

I open an audio file to be played via splitter channels and BASSMix to two separate outputs, and part of the file is to be looped. The program hangs in the synchronizer callback the first time it is activated.

Here's an extract from my log of the run (btw, playback does not start from the beginning of the file, hence the initial BASS_Mixer_ChannelSetPosition calls):
Code: [Select]
------- INITIALISATION
0.873: BASS_SetConfig(BASS_CONFIG_FLOATDSP, BASSTRUE) returned 1
0.873: BASS_SetConfig(BASS_CONFIG_UPDATETHREADS, 2) returned 1
0.873: BASS_SetConfig(BASS_CONFIG_BUFFER, 300) returned 1
0.873: BASS_SetConfig(BASS_CONFIG_UPDATEPERIOD, 100) returned 1
1.216: BASS_Init(1, 44100, 0, 1381268, 0) returned 1
1.216: BASS_GetInfo(@\rBassInfo) returned 1
1.232: BASS_Init(2, 44100, 0, 1381268, 0) returned 1
1.232: BASS_GetInfo(@\rBassInfo) returned 1
1.232: BASS_SetDevice(1) returned 1
1.232: BASS_Mixer_StreamCreate(44100, 2, BASS_SAMPLE_FLOAT|BASS_MIXER_PAUSE) returned -1342177278
1.232: handle -1342177278 is mixer#1
1.248: BASS_ChannelPlay(mixer#1, BASSFALSE) returned 1
1.248: BASS_SetDevice(2) returned 1
1.248: BASS_Mixer_StreamCreate(44100, 2, BASS_SAMPLE_FLOAT|BASS_MIXER_PAUSE) returned -1342177276
1.248: handle -1342177276 is mixer#2
1.279: BASS_ChannelPlay(mixer#2, BASSFALSE) returned 1

------- OPEN WAV FILE
1.903: BASS_SetDevice(1) returned 1
1.903: BASS_StreamCreateFile(BASSFALSE, When I'm Sixty-Four4Mike.wav, 0, 0, BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE|BASS_UNICODE) returned -1342177274
1.903: handle -1342177274 is source#1
1.903: BASS_Split_StreamCreate(source#1, BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE, 0) returned -1342177272
1.903: handle -1342177272 is splitter#1
1.903: BASS_ChannelGetInfo(splitter#1, rChannelInfo) returned 1
1.903: BASS_Mixer_StreamAddChannel(mixer#1, splitter#1, BASS_MIXER_DOWNMIX|BASS_MIXER_PAUSE|BASS_MIXER_NORAMPIN|BASS_MIXER_BUFFER) returned 1
1.903: BASS_ChannelUpdate(mixer#1, 0) returned 1
1.903: BASS_Mixer_ChannelFlags(splitter#1, 0, 0) returned $822000
1.903: BASS_Mixer_ChannelSetPosition(splitter#1, 23304960, BASS_POS_BYTE) returned 1
1.903: BASS_Split_StreamReset(source#1) returned 1
1.903: BASS_SetDevice(2) returned 1
1.903: BASS_SetConfig(BASS_CONFIG_BUFFER, 300) returned 1
1.903: BASS_Split_StreamCreate(source#1, BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE, 0) returned -1342177269
1.903: handle -1342177269 is splitter#2
1.903: BASS_ChannelGetInfo(splitter#2, rChannelInfo) returned 1
1.903: BASS_Mixer_StreamAddChannel(mixer#2, splitter#2, BASS_MIXER_DOWNMIX|BASS_MIXER_PAUSE|BASS_MIXER_NORAMPIN|BASS_MIXER_BUFFER) returned 1
1.903: BASS_ChannelUpdate(mixer#2, 0) returned 1
1.903: BASS_Mixer_ChannelFlags(splitter#2, 0, 0) returned $822000
1.903: BASS_Mixer_ChannelSetPosition(splitter#2, 23304960, BASS_POS_BYTE) returned 1
1.903: BASS_Split_StreamReset(source#1) returned 1
1.903: BASS_ChannelGetInfo(splitter#1, @rBCI\chanInfo) returned 1
1.903: BASS_ChannelGetInfo(splitter#2, @rBCI\chanInfo) returned 1
1.903: BASS_ChannelLock(mixer#1, BASSTRUE) returned 1
1.903: BASS_ChannelLock(mixer#2, BASSTRUE) returned 1
1.903: BASS_Mixer_ChannelSetPosition(splitter#1, 23304960, BASS_POS_BYTE) returned 1
1.903: BASS_Split_StreamReset(source#1) returned 1
1.903: BASS_ChannelLock(mixer#1, BASSFALSE) returned 1
1.903: BASS_ChannelLock(mixer#2, BASSFALSE) returned 1

------- SET LOOP END SYNC POINT
1.903: BASS_Mixer_ChannelSetSync(splitter#1, BASS_SYNC_POS|BASS_SYNC_MIXTIME, 26043512, @LoopSyncProcMixTime(), 1) returned -805306354

------- PLAY
5.787: BASS_ChannelLock(mixer#1, BASSTRUE) returned 1
5.787: BASS_ChannelLock(mixer#2, BASSTRUE) returned 1
5.787: BASS_Mixer_ChannelFlags(splitter#1, 0, 0) returned $822000
5.787: BASS_ChannelIsActive(splitter#1) returned BASS_ACTIVE_PLAYING
5.787: BASS_Mixer_ChannelFlags(splitter#1, 0, BASS_MIXER_PAUSE) returned $802000
5.787: BASS_Mixer_ChannelFlags(splitter#2, 0, BASS_MIXER_PAUSE) returned $802000
5.803: BASS_ChannelLock(mixer#1, BASSFALSE) returned 1
5.803: BASS_ChannelLock(mixer#2, BASSFALSE) returned 1

13.509: LoopSyncProcMixTime handle=-805306354, channel=splitter#1, user=1: start
13.509: LoopSyncProcMixTime handle=-805306354, channel=splitter#1, user=1: calling BASS_ChannelLock(mixer#1, BASSTRUE)
13.509: LoopSyncProcMixTime handle=-805306354, channel=splitter#1, user=1: BASS_ChannelLock(mixer#1, BASSTRUE) returned 1
13.509: LoopSyncProcMixTime handle=-805306354, channel=splitter#1, user=1: calling BASS_ChannelLock(mixer#2, BASSTRUE)
------- HANGS HERE - does not return from BASS_ChannelLock(mixer#2, BASSTRUE)

LoopSyncProcMixTime is the synchronizer callback. I don't normally trace callback code but added this to identify where the program was hanging.

The theory is that a POS|MIXTIME synchronizer is set for splitter#1 only, and when that fires then I lock the two mixer streams, set the position of the source channel (source#1) to the loop-start position, issue a split stream reset on the source channel, and then unlock the two mixer streams. But it consistently hangs when try to lock the second mixer stream, Audibly, I hear the last fraction-of-a-second of the loop playing repeatedly until I kill the program.

If I omit locking/unlocking the mixer streams in the synchronizer then the program works, although understandably the outputs are slightly out-of-sync when the loop occurs.

Am I doing something wrong in my code, apart from a few redundant 'set position' calls on opening the file? For example, should I be calling BASS_Mixer_ChannelSetSync for both splitter channels?
« Last Edit: 23 Mar '12 - 03:57 by SoundMike »

Ian @ un4seen

  • Administrator
  • Posts: 20426
Re: BASS_ChannelLock hangs
« Reply #1 on: 22 Mar '12 - 17:04 »
That looks to me like you should probably be using BASS_ChannelSetSync to set the sync on the splitter source ("source#1"), rather than using BASS_Mixer_ChannelSetSync on one of the splitters ("splitter#1"). Doing that should avoid the need for resetting splitters and locking the mixers. The SYNCPROC function would just set the source to the loop-start position.

I think the reason for your current BASS_ChannelLock-induced deadlock is this... The SYNCPROC will be triggered when source#1 reaches the sync position, which will occur when a splitter stream is getting data from it, and that will occur when the mixer is getting data from the splitter (the data goes from source to splitter to mixer). That means the splitter and its mixer will be locked when the SYNCPROC is called. Due to BASS_CONFIG_UPDATETHREADS being set to 2 (for 2 update threads), the other mixer's splitter will in the meantime be waiting for its turn to process the source. So when the SYNCPROC tries to lock that 2nd mixer, it will result in a deadlock, ie. they are waiting for each other.

SoundMike

  • Posts: 331
Re: BASS_ChannelLock hangs
« Reply #2 on: 23 Mar '12 - 03:53 »
That looks to me like you should probably be using BASS_ChannelSetSync to set the sync on the splitter source ("source#1"), rather than using BASS_Mixer_ChannelSetSync on one of the splitters ("splitter#1"). Doing that should avoid the need for resetting splitters and locking the mixers. The SYNCPROC function would just set the source to the loop-start position.

Many thanks, Ian. That does the job perfectly and is also less code! :)