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)
85 using namespace std::chrono;
94 auto frames = available;
95 auto toProduce = frames;
96 double deltat = frames /
mRate;
98 if (deltat > realTimeRemaining)
103 auto extra =
std::min( extraRealTime, deltat - realTimeRemaining );
104 auto realTime = realTimeRemaining + extra;
105 frames = realTime *
mRate + 0.5;
106 toProduce = realTimeRemaining *
mRate + 0.5;
112 return { available, frames, toProduce };
115std::pair<double, double>
117 double trackTime,
size_t nSamples )
119 auto realDuration = nSamples /
mRate;
121 realDuration *= -1.0;
127 trackTime += realDuration;
129 if ( trackTime >= schedule.
mT1 )
130 return { schedule.
mT1, std::numeric_limits<double>::infinity() };
132 return { trackTime, trackTime };
158 static OldDefaultPlaybackPolicy defaultPolicy;
159 return defaultPolicy;
168 const double t0,
const double t1,
174 if ( pRecordingSchedule )
185 if (pRecordingSchedule)
189 if (pRecordingSchedule)
290 auto index = mTail.mIndex;
291 auto time = mLastTime;
292 auto remainder = mTail.mRemainder;
294 const auto size = mData.size();
298 while ( frames >= space ) {
299 auto times = policy.AdvancedTrackTime( schedule, time, space );
301 if (!std::isfinite(time))
303 index = (index + 1) %
size;
304 mData[ index ].timeValue = time;
311 auto times = policy.AdvancedTrackTime( schedule, time, frames );
313 if (!std::isfinite(time))
321 while ( frames > 0 && frames >= space ) {
322 index = (index + 1) %
size;
323 mData[ index ].timeValue = time;
330 mTail.mRemainder = remainder + frames;
331 mTail.mIndex = index;
346 if ( mData.empty() ) {
348 return ( mLastTime += nSamples / rate );
353 auto remainder = mHead.mRemainder;
355 const auto size = mData.size();
356 if ( nSamples >= space ) {
358 mHead.mIndex = (mHead.mIndex + 1) %
size,
365 mHead.mRemainder = remainder + nSamples;
366 return mData[ mHead.mIndex ].timeValue;
373 if ( !mData.empty() )
374 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