38 using namespace std::chrono;
42 return { 0.05s, 0.05s, 0.25s };
54 return { 4.0s, 4.0s, 10.0s };
64 unsigned long outputFrames)
79 time = std::clamp(time, schedule.
mT0, schedule.
mT1);
86 using namespace std::chrono;
95 auto frames = available;
96 auto toProduce = frames;
97 double deltat = frames /
mRate;
99 if (deltat > realTimeRemaining)
104 auto extra =
std::min( extraRealTime, deltat - realTimeRemaining );
105 auto realTime = realTimeRemaining + extra;
106 frames = realTime *
mRate + 0.5;
107 toProduce = realTimeRemaining *
mRate + 0.5;
113 return { available, frames, toProduce };
116std::pair<double, double>
118 double trackTime,
size_t nSamples )
120 auto realDuration = nSamples /
mRate;
122 realDuration *= -1.0;
128 trackTime += realDuration;
130 if ( trackTime >= schedule.
mT1 )
131 return { schedule.
mT1, std::numeric_limits<double>::infinity() };
133 return { trackTime, trackTime };
159 static OldDefaultPlaybackPolicy defaultPolicy;
160 return defaultPolicy;
169 const double t0,
const double t1,
175 if ( pRecordingSchedule )
186 if (pRecordingSchedule)
190 if (pRecordingSchedule)
291 auto index = mTail.mIndex;
292 auto time = mLastTime;
293 auto remainder = mTail.mRemainder;
295 const auto size = mData.size();
299 while ( frames >= space ) {
300 auto times = policy.AdvancedTrackTime( schedule, time, space );
302 if (!std::isfinite(time))
304 index = (index + 1) %
size;
305 mData[ index ].timeValue = time;
312 auto times = policy.AdvancedTrackTime( schedule, time, frames );
314 if (!std::isfinite(time))
322 while ( frames > 0 && frames >= space ) {
323 index = (index + 1) %
size;
324 mData[ index ].timeValue = time;
331 mTail.mRemainder = remainder + frames;
332 mTail.mIndex = index;
347 if ( mData.empty() ) {
349 return ( mLastTime += nSamples / rate );
354 auto remainder = mHead.mRemainder;
356 const auto size = mData.size();
357 if ( nSamples >= space ) {
359 mHead.mIndex = (mHead.mIndex + 1) %
size,
366 mHead.mRemainder = remainder + nSamples;
367 return mData[ mHead.mIndex ].timeValue;
374 if ( !mData.empty() )
375 mData[0].timeValue = time;
constexpr size_t TimeQueueGrainSize
double SolveIntegralOfInverse(double t0, double area) const
double IntegralOfInverse(double t0, double t1) const
Directs which parts of tracks to fetch for playback.
virtual BufferTimes SuggestedBufferTimes(PlaybackSchedule &schedule)
Provide hints for construction of playback RingBuffer objects.
virtual std::pair< double, double > AdvancedTrackTime(PlaybackSchedule &schedule, double trackTime, size_t nSamples)
Compute a new point in a track's timeline from an old point and a real duration.
virtual double OffsetSequenceTime(PlaybackSchedule &schedule, double offset)
Called when the play head needs to jump a certain distance.
virtual bool AllowSeek(PlaybackSchedule &schedule)
Whether repositioning commands are allowed during playback.
std::vector< std::unique_ptr< Mixer > > Mixers
virtual void Finalize(PlaybackSchedule &schedule)
Called after stopping of an audio stream or an unsuccessful start.
virtual bool Looping(const PlaybackSchedule &schedule) const
virtual Mixer::WarpOptions MixerWarpOptions(PlaybackSchedule &schedule)
Options to use when constructing mixers for each playback track.
virtual void Initialize(PlaybackSchedule &schedule, double rate)
Called before starting an audio stream.
virtual bool RepositionPlayback(PlaybackSchedule &schedule, const Mixers &playbackMixers, size_t frames, size_t available)
AudioIO::FillPlayBuffers calls this to update its cursors into tracks for changes of position or spee...
virtual PlaybackSlice GetPlaybackSlice(PlaybackSchedule &schedule, size_t available)
Choose length of one fetch of samples from tracks in a call to AudioIO::FillPlayBuffers.
virtual bool Done(PlaybackSchedule &schedule, unsigned long outputFrames)
Returns true if schedule.GetSequenceTime() has reached the end of playback.
virtual ~PlaybackPolicy()=0
virtual std::chrono::milliseconds SleepInterval(PlaybackSchedule &schedule)
How long to wait between calls to AudioIO::SequenceBufferExchange.
NonInterfering< Cursor > mHead
Aligned to avoid false sharing.
void Producer(PlaybackSchedule &schedule, PlaybackSlice slice)
Enqueue track time value advanced by the slice according to schedule's PlaybackPolicy.
std::vector< Record > Records
double GetLastTime() const
Return the last time saved by Producer.
double Consumer(size_t nSamples, double rate)
Find the track time value nSamples after the last consumed sample.
void Prime(double time)
Empty the queue and reassign the last produced time.
NonInterfering< Cursor > mTail
void SetLastTime(double time)
Positions or offsets within audio files need a wide type.
struct holding stream options, including a pointer to the time warp info and AudioIOListener and whet...
PolicyFactory policyFactory
const BoundedEnvelope * envelope
Immutable structure is an argument to Mixer's constructor.
std::unique_ptr< PlaybackPolicy > mpPlaybackPolicy
double RealTimeRemaining() const
double mT0
Playback starts at offset of mT0, which is measured in seconds.
double mT1
Playback ends at offset of mT1, which is measured in seconds. Note that mT1 may be less than mT0 duri...
double SolveWarpedLength(double t0, double length) const
Compute how much unwarped time must have elapsed if length seconds of warped time has elapsed,...
bool ReversedTime() const
True if the end time is before the start time.
double RealDurationSigned(double trackTime1) const
const BoundedEnvelope * mEnvelope
void Init(double t0, double t1, const AudioIOStartStreamOptions &options, const RecordingSchedule *pRecordingSchedule)
std::atomic< bool > mPolicyValid
double RealDuration(double trackTime1) const
void RealTimeInit(double trackTime)
void RealTimeAdvance(double increment)
void SetSequenceTime(double time)
Set current track time value, unadjusted.
double GetSequenceTime() const
Get current track time value, unadjusted.
double ComputeWarpedLength(double t0, double t1) const
Compute signed duration (in seconds at playback) of the specified region of the track.
PlaybackPolicy & GetPolicy()
Describes an amount of contiguous (but maybe time-warped) data to be extracted from tracks to play.
const size_t toProduce
Not more than frames; the difference will be trailing silence.
const size_t frames
Total number of frames to be buffered.
double TotalCorrection() const
double mLatencyCorrection
The old default playback policy plays once and consumes no messages.
~OldDefaultPlaybackPolicy() override=default