comparison audioio/AudioCallbackPlaySource.h @ 450:d9d132c0e240 alignment_view

Merge from default branch
author Chris Cannam
date Mon, 20 Apr 2015 09:21:32 +0100
parents 72c662fe7ea3
children
comparison
equal deleted inserted replaced
430:adfb2948fabf 450:d9d132c0e240
81 /** 81 /**
82 * Start making data available in the ring buffers for playback, 82 * Start making data available in the ring buffers for playback,
83 * from the given frame. If playback is already under way, reseek 83 * from the given frame. If playback is already under way, reseek
84 * to the given frame and continue. 84 * to the given frame and continue.
85 */ 85 */
86 virtual void play(int startFrame); 86 virtual void play(sv_frame_t startFrame);
87 87
88 /** 88 /**
89 * Stop playback and ensure that no more data is returned. 89 * Stop playback and ensure that no more data is returned.
90 */ 90 */
91 virtual void stop(); 91 virtual void stop();
97 97
98 /** 98 /**
99 * Return the frame number that is currently expected to be coming 99 * Return the frame number that is currently expected to be coming
100 * out of the speakers. (i.e. compensating for playback latency.) 100 * out of the speakers. (i.e. compensating for playback latency.)
101 */ 101 */
102 virtual int getCurrentPlayingFrame(); 102 virtual sv_frame_t getCurrentPlayingFrame();
103 103
104 /** 104 /**
105 * Return the last frame that would come out of the speakers if we 105 * Return the last frame that would come out of the speakers if we
106 * stopped playback right now. 106 * stopped playback right now.
107 */ 107 */
108 virtual int getCurrentBufferedFrame(); 108 virtual sv_frame_t getCurrentBufferedFrame();
109 109
110 /** 110 /**
111 * Return the frame at which playback is expected to end (if not looping). 111 * Return the frame at which playback is expected to end (if not looping).
112 */ 112 */
113 virtual int getPlayEndFrame() { return m_lastModelEndFrame; } 113 virtual sv_frame_t getPlayEndFrame() { return m_lastModelEndFrame; }
114 114
115 /** 115 /**
116 * Set the target and the block size of the target audio device. 116 * Set the target and the block size of the target audio device.
117 * This should be called by the target class. 117 * This should be called by the target class.
118 */ 118 */
131 * at the target sample rate. This is the difference between the 131 * at the target sample rate. This is the difference between the
132 * frame currently "leaving the speakers" and the last frame (or 132 * frame currently "leaving the speakers" and the last frame (or
133 * highest last frame across all channels) requested via 133 * highest last frame across all channels) requested via
134 * getSamples(). The default is zero. 134 * getSamples(). The default is zero.
135 */ 135 */
136 void setTargetPlayLatency(int); 136 void setTargetPlayLatency(sv_frame_t);
137 137
138 /** 138 /**
139 * Get the playback latency of the target audio device. 139 * Get the playback latency of the target audio device.
140 */ 140 */
141 int getTargetPlayLatency() const; 141 sv_frame_t getTargetPlayLatency() const;
142 142
143 /** 143 /**
144 * Specify that the target audio device has a fixed sample rate 144 * Specify that the target audio device has a fixed sample rate
145 * (i.e. cannot accommodate arbitrary sample rates based on the 145 * (i.e. cannot accommodate arbitrary sample rates based on the
146 * source). If the target sets this to something other than the 146 * source). If the target sets this to something other than the
147 * source sample rate, this class will resample automatically to 147 * source sample rate, this class will resample automatically to
148 * fit. 148 * fit.
149 */ 149 */
150 void setTargetSampleRate(int); 150 void setTargetSampleRate(sv_samplerate_t);
151 151
152 /** 152 /**
153 * Return the sample rate set by the target audio device (or the 153 * Return the sample rate set by the target audio device (or the
154 * source sample rate if the target hasn't set one). 154 * source sample rate if the target hasn't set one).
155 */ 155 */
156 virtual int getTargetSampleRate() const; 156 virtual sv_samplerate_t getTargetSampleRate() const;
157 157
158 /** 158 /**
159 * Set the current output levels for metering (for call from the 159 * Set the current output levels for metering (for call from the
160 * target) 160 * target)
161 */ 161 */
187 /** 187 /**
188 * Get the actual sample rate of the source material. This may 188 * Get the actual sample rate of the source material. This may
189 * safely be called from a realtime thread. Returns 0 if there is 189 * safely be called from a realtime thread. Returns 0 if there is
190 * no source yet available. 190 * no source yet available.
191 */ 191 */
192 virtual int getSourceSampleRate() const; 192 virtual sv_samplerate_t getSourceSampleRate() const;
193 193
194 /** 194 /**
195 * Get "count" samples (at the target sample rate) of the mixed 195 * Get "count" samples (at the target sample rate) of the mixed
196 * audio data, in all channels. This may safely be called from a 196 * audio data, in all channels. This may safely be called from a
197 * realtime thread. 197 * realtime thread.
198 */ 198 */
199 int getSourceSamples(int count, float **buffer); 199 sv_frame_t getSourceSamples(sv_frame_t count, float **buffer);
200 200
201 /** 201 /**
202 * Set the time stretcher factor (i.e. playback speed). 202 * Set the time stretcher factor (i.e. playback speed).
203 */ 203 */
204 void setTimeStretch(float factor); 204 void setTimeStretch(double factor);
205 205
206 /** 206 /**
207 * Set the resampler quality, 0 - 2 where 0 is fastest and 2 is 207 * Set the resampler quality, 0 - 2 where 0 is fastest and 2 is
208 * highest quality. 208 * highest quality.
209 */ 209 */
242 signals: 242 signals:
243 void modelReplaced(); 243 void modelReplaced();
244 244
245 void playStatusChanged(bool isPlaying); 245 void playStatusChanged(bool isPlaying);
246 246
247 void sampleRateMismatch(int requested, int available, bool willResample); 247 void sampleRateMismatch(sv_samplerate_t requested,
248 sv_samplerate_t available,
249 bool willResample);
248 250
249 void audioOverloadPluginDisabled(); 251 void audioOverloadPluginDisabled();
250 void audioTimeStretchMultiChannelDisabled(); 252 void audioTimeStretchMultiChannelDisabled();
251 253
252 void activity(QString); 254 void activity(QString);
258 void selectionChanged(); 260 void selectionChanged();
259 void playLoopModeChanged(); 261 void playLoopModeChanged();
260 void playSelectionModeChanged(); 262 void playSelectionModeChanged();
261 void playParametersChanged(PlayParameters *); 263 void playParametersChanged(PlayParameters *);
262 void preferenceChanged(PropertyContainer::PropertyName); 264 void preferenceChanged(PropertyContainer::PropertyName);
263 void modelChangedWithin(int startFrame, int endFrame); 265 void modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame);
264 266
265 protected: 267 protected:
266 ViewManagerBase *m_viewManager; 268 ViewManagerBase *m_viewManager;
267 AudioGenerator *m_audioGenerator; 269 AudioGenerator *m_audioGenerator;
268 QString m_clientName; 270 QString m_clientName;
278 }; 280 };
279 281
280 std::set<Model *> m_models; 282 std::set<Model *> m_models;
281 RingBufferVector *m_readBuffers; 283 RingBufferVector *m_readBuffers;
282 RingBufferVector *m_writeBuffers; 284 RingBufferVector *m_writeBuffers;
283 int m_readBufferFill; 285 sv_frame_t m_readBufferFill;
284 int m_writeBufferFill; 286 sv_frame_t m_writeBufferFill;
285 Scavenger<RingBufferVector> m_bufferScavenger; 287 Scavenger<RingBufferVector> m_bufferScavenger;
286 int m_sourceChannelCount; 288 int m_sourceChannelCount;
287 int m_blockSize; 289 sv_frame_t m_blockSize;
288 int m_sourceSampleRate; 290 sv_samplerate_t m_sourceSampleRate;
289 int m_targetSampleRate; 291 sv_samplerate_t m_targetSampleRate;
290 int m_playLatency; 292 sv_frame_t m_playLatency;
291 AudioCallbackPlayTarget *m_target; 293 AudioCallbackPlayTarget *m_target;
292 double m_lastRetrievalTimestamp; 294 double m_lastRetrievalTimestamp;
293 int m_lastRetrievedBlockSize; 295 sv_frame_t m_lastRetrievedBlockSize;
294 bool m_trustworthyTimestamps; 296 bool m_trustworthyTimestamps;
295 int m_lastCurrentFrame; 297 sv_frame_t m_lastCurrentFrame;
296 bool m_playing; 298 bool m_playing;
297 bool m_exiting; 299 bool m_exiting;
298 int m_lastModelEndFrame; 300 sv_frame_t m_lastModelEndFrame;
299 int m_ringBufferSize; 301 int m_ringBufferSize;
300 float m_outputLeft; 302 float m_outputLeft;
301 float m_outputRight; 303 float m_outputRight;
302 RealTimePluginInstance *m_auditioningPlugin; 304 RealTimePluginInstance *m_auditioningPlugin;
303 bool m_auditioningPluginBypassed; 305 bool m_auditioningPluginBypassed;
304 Scavenger<RealTimePluginInstance> m_pluginScavenger; 306 Scavenger<RealTimePluginInstance> m_pluginScavenger;
305 int m_playStartFrame; 307 sv_frame_t m_playStartFrame;
306 bool m_playStartFramePassed; 308 bool m_playStartFramePassed;
307 RealTime m_playStartedAt; 309 RealTime m_playStartedAt;
308 310
309 RingBuffer<float> *getWriteRingBuffer(int c) { 311 RingBuffer<float> *getWriteRingBuffer(int c) {
310 if (m_writeBuffers && c < (int)m_writeBuffers->size()) { 312 if (m_writeBuffers && c < (int)m_writeBuffers->size()) {
326 void clearRingBuffers(bool haveLock = false, int count = 0); 328 void clearRingBuffers(bool haveLock = false, int count = 0);
327 void unifyRingBuffers(); 329 void unifyRingBuffers();
328 330
329 RubberBand::RubberBandStretcher *m_timeStretcher; 331 RubberBand::RubberBandStretcher *m_timeStretcher;
330 RubberBand::RubberBandStretcher *m_monoStretcher; 332 RubberBand::RubberBandStretcher *m_monoStretcher;
331 float m_stretchRatio; 333 double m_stretchRatio;
332 bool m_stretchMono; 334 bool m_stretchMono;
333 335
334 int m_stretcherInputCount; 336 int m_stretcherInputCount;
335 float **m_stretcherInputs; 337 float **m_stretcherInputs;
336 int *m_stretcherInputSizes; 338 sv_frame_t *m_stretcherInputSizes;
337 339
338 // Called from fill thread, m_playing true, mutex held 340 // Called from fill thread, m_playing true, mutex held
339 // Return true if work done 341 // Return true if work done
340 bool fillBuffers(); 342 bool fillBuffers();
341 343
342 // Called from fillBuffers. Return the number of frames written, 344 // Called from fillBuffers. Return the number of frames written,
343 // which will be count or fewer. Return in the frame argument the 345 // which will be count or fewer. Return in the frame argument the
344 // new buffered frame position (which may be earlier than the 346 // new buffered frame position (which may be earlier than the
345 // frame argument passed in, in the case of looping). 347 // frame argument passed in, in the case of looping).
346 int mixModels(int &frame, int count, float **buffers); 348 sv_frame_t mixModels(sv_frame_t &frame, sv_frame_t count, float **buffers);
347 349
348 // Called from getSourceSamples. 350 // Called from getSourceSamples.
349 void applyAuditioningEffect(int count, float **buffers); 351 void applyAuditioningEffect(sv_frame_t count, float **buffers);
350 352
351 // Ranges of current selections, if play selection is active 353 // Ranges of current selections, if play selection is active
352 std::vector<RealTime> m_rangeStarts; 354 std::vector<RealTime> m_rangeStarts;
353 std::vector<RealTime> m_rangeDurations; 355 std::vector<RealTime> m_rangeDurations;
354 void rebuildRangeLists(); 356 void rebuildRangeLists();
355 357
356 int getCurrentFrame(RealTime outputLatency); 358 sv_frame_t getCurrentFrame(RealTime outputLatency);
357 359
358 class FillThread : public Thread 360 class FillThread : public Thread
359 { 361 {
360 public: 362 public:
361 FillThread(AudioCallbackPlaySource &source) : 363 FillThread(AudioCallbackPlaySource &source) :