How to get the current playback progress from "SampledAudioNode"?
xioxin opened this issue · comments
In the old version, I realized this function by reading "m_virtualReadIndex".
I added this method to solve the problem.
This may not be the best way
int32_t SampledAudioNode::getFirstScheduledCursor()
{
std::shared_ptr<AudioBus> srcBus = m_sourceBus->valueBus();
int schedule_count = static_cast<int>(_internals->scheduled.size());
if (!schedule_count || !srcBus)
return 0.0;
Scheduled& s = _internals->scheduled.at(0);
return s.cursor;
}
That will work reliably within a process() call of a node, but there is a thread safety issue if you call it outside of the audio processing thread (the hazard occurs if the schedule is expired, just before _internals->scheduled.at(0);) ~ The chances it will crash are very low, but I think you can do this temporarily... I will think about how to do it in a thread-safe way.
@xioxin Almost the same as your suggestion, fdbf0f4
It's threadsafe, by copying the value into a cached location. Please let me know if that's giving the information you need.
// returns the greatest sample index played back by any of the scheduled
// instances in the most recent render quantum. A value less than zero
// indicates nothing's playing.
int32_t getCursor() const;
Thank you for the report and fix, it has been pushed to e1d688e