Author Topic: Decoding channel's playback position when plugged into a mixer  (Read 1194 times)

3delite

  • Posts: 907
Hi!

The topic title should be: Decoding channel's current playback position when plugged into a mixer which is plugged into a mixer

A decoding channel is plugged into a mixer which is DSPd and used for BASS_Mixer_ChannelGetData() for visualization (with buffering enabled) and this mixer is plugged into a 'main mixer' which is non-decoding channel when using DS (played) and a decoding channel when using BASSWASAPI.
The problem is that I am displaying a waveform and need playback position display. The playback position display is using BASS_Mixer_ChannelGetPosition() and is 'pre-buffering time' ahead of what is currently heard.
I subtract the pre-buffering latency and the position is good now, but the position display is not as smooth as with a non-decoding channel, it seems it increments in maybe 100ms.

Is it possible to get a smooth reported playback position with this setup?

Thank you!

Ian @ un4seen

  • Administrator
  • Posts: 20433
The BASS_MIXER_POSEX flag and BASS_Mixer_ChannelGetPositionEx may be useful for that. Please see the documentation for details on that. For an example, assuming that your output and intermediate mixers have the same sample format, you could try something like this when using BASS/DirectSound output...

Code: [Select]
BASS_ChannelLock(outmixer, TRUE); // prevent processing mid-calculation
DWORD buffered=BASS_ChannelGetData(outmixer, 0, BASS_DATA_AVAILABLE); // get amount of buffered data from output mixer
QWORD pos=BASS_Mixer_ChannelGetPositionEx(source, BASS_POS_BYTE, buffered); // get source position at that point
BASS_ChannelLock(outmixer, FALSE);

BASSWASAPI's CONTEST.C example has a demonstration of doing this sort of thing with WASAPI output.

3delite

  • Posts: 907
Thank you very much, seems working perfectly!

One thing, I was locking the mixer channel that is plugged into the final output mixer and got random complete freeze. Changed to lock the final output mixer and now seems working.
Is this expected?

Thank you!

Ian @ un4seen

  • Administrator
  • Posts: 20433
Yep, you need to lock the output mixer. That ensures that the mixer doesn't start an update cycle while you get the buffer level and source position. If an update did happen to occur between the BASS_ChannelGetData and BASS_Mixer_ChannelGetPositionEx calls, then your "buffered" value would no longer be valid.

If you lock one of the mixer's sources instead (eg. your intermediate mixer), that could cause a deadlock in the BASS_ChannelGetData call, because BASS_ChannelGetData will wait for an update cycle to end if it is currently in the middle of one, but the update cycle may be stuck waiting for the source to be unlocked.

3delite

  • Posts: 907
Ok. Thank you!