comparison audio/AudioCallbackPlaySource.h @ 554:4be200469a9c 3.0-integration

Merge from branch bqresample
author Chris Cannam
date Fri, 09 Dec 2016 18:01:55 +0000
parents 2a1e9e017484
children 206d65e2b69a
comparison
equal deleted inserted replaced
546:4de547a5905c 554:4be200469a9c
35 #include <set> 35 #include <set>
36 #include <map> 36 #include <map>
37 37
38 namespace RubberBand { 38 namespace RubberBand {
39 class RubberBandStretcher; 39 class RubberBandStretcher;
40 }
41
42 namespace breakfastquay {
43 class ResamplerWrapper;
40 } 44 }
41 45
42 class Model; 46 class Model;
43 class ViewManagerBase; 47 class ViewManagerBase;
44 class AudioGenerator; 48 class AudioGenerator;
119 * Set the playback target. 123 * Set the playback target.
120 */ 124 */
121 virtual void setSystemPlaybackTarget(breakfastquay::SystemPlaybackTarget *); 125 virtual void setSystemPlaybackTarget(breakfastquay::SystemPlaybackTarget *);
122 126
123 /** 127 /**
128 * Set the resampler wrapper, if one is in use.
129 */
130 virtual void setResamplerWrapper(breakfastquay::ResamplerWrapper *);
131
132 /**
124 * Set the block size of the target audio device. This should be 133 * Set the block size of the target audio device. This should be
125 * called by the target class. 134 * called by the target class.
126 */ 135 */
127 virtual void setSystemPlaybackBlockSize(int blockSize); 136 virtual void setSystemPlaybackBlockSize(int blockSize);
128 137
134 */ 143 */
135 int getTargetBlockSize() const; 144 int getTargetBlockSize() const;
136 145
137 /** 146 /**
138 * Set the playback latency of the target audio device, in frames 147 * Set the playback latency of the target audio device, in frames
139 * at the target sample rate. This is the difference between the 148 * at the device sample rate. This is the difference between the
140 * frame currently "leaving the speakers" and the last frame (or 149 * frame currently "leaving the speakers" and the last frame (or
141 * highest last frame across all channels) requested via 150 * highest last frame across all channels) requested via
142 * getSamples(). The default is zero. 151 * getSamples(). The default is zero.
143 */ 152 */
144 void setSystemPlaybackLatency(int); 153 void setSystemPlaybackLatency(int);
159 168
160 /** 169 /**
161 * Return the sample rate set by the target audio device (or the 170 * Return the sample rate set by the target audio device (or the
162 * source sample rate if the target hasn't set one). 171 * source sample rate if the target hasn't set one).
163 */ 172 */
164 virtual sv_samplerate_t getTargetSampleRate() const; 173 sv_samplerate_t getDeviceSampleRate() const;
165 174
166 /** 175 /**
167 * Indicate how many channels the target audio device was opened 176 * Indicate how many channels the target audio device was opened
168 * with. Note that the target device does channel mixing in the 177 * with. Note that the target device does channel mixing in the
169 * case where our requested channel count does not match its. 178 * case where our requested channel count does not match its.
192 /** 201 /**
193 * Get the number of channels of audio that will be provided 202 * Get the number of channels of audio that will be provided
194 * to the play target. This may be more than the source channel 203 * to the play target. This may be more than the source channel
195 * count: for example, a mono source will provide 2 channels 204 * count: for example, a mono source will provide 2 channels
196 * after pan. 205 * after pan.
206 *
197 * This may safely be called from a realtime thread. Returns 0 if 207 * This may safely be called from a realtime thread. Returns 0 if
198 * there is no source yet available. 208 * there is no source yet available.
199 */ 209 *
200 int getTargetChannelCount() const; 210 * override from AudioPlaySource
211 */
212 virtual int getTargetChannelCount() const override;
201 213
202 /** 214 /**
203 * ApplicationPlaybackSource equivalent of the above. 215 * ApplicationPlaybackSource equivalent of the above.
204 */ 216 *
205 virtual int getApplicationChannelCount() const { 217 * override from breakfastquay::ApplicationPlaybackSource
218 */
219 virtual int getApplicationChannelCount() const override {
206 return getTargetChannelCount(); 220 return getTargetChannelCount();
207 } 221 }
208 222
209 /** 223 /**
210 * Get the actual sample rate of the source material. This may 224 * Get the actual sample rate of the source material (the main
211 * safely be called from a realtime thread. Returns 0 if there is 225 * model). This may safely be called from a realtime thread.
212 * no source yet available. 226 * Returns 0 if there is no source yet available.
213 */ 227 *
214 virtual sv_samplerate_t getSourceSampleRate() const; 228 * When this changes, the AudioCallbackPlaySource notifies its
215 229 * ResamplerWrapper of the new sample rate so that it can resample
216 /** 230 * correctly on the way to the device (which is opened at a fixed
217 * ApplicationPlaybackSource equivalent of the above. 231 * rate, see getApplicationSampleRate).
218 */ 232 */
219 virtual int getApplicationSampleRate() const { 233 virtual sv_samplerate_t getSourceSampleRate() const override;
220 return int(round(getSourceSampleRate())); 234
235 /**
236 * ApplicationPlaybackSource interface method: get the sample rate
237 * at which the application wants the device to be opened. We
238 * always allow the device to open at its default rate, and then
239 * we resample if the audio is at a different rate. This avoids
240 * having to close and re-open the device to obtain consistent
241 * behaviour for consecutive sessions with different source rates.
242 */
243 virtual int getApplicationSampleRate() const override {
244 return 0;
221 } 245 }
222 246
223 /** 247 /**
224 * Get "count" samples (at the target sample rate) of the mixed 248 * Get "count" samples (at the target sample rate) of the mixed
225 * audio data, in all channels. This may safely be called from a 249 * audio data, in all channels. This may safely be called from a
309 sv_frame_t m_writeBufferFill; 333 sv_frame_t m_writeBufferFill;
310 Scavenger<RingBufferVector> m_bufferScavenger; 334 Scavenger<RingBufferVector> m_bufferScavenger;
311 int m_sourceChannelCount; 335 int m_sourceChannelCount;
312 sv_frame_t m_blockSize; 336 sv_frame_t m_blockSize;
313 sv_samplerate_t m_sourceSampleRate; 337 sv_samplerate_t m_sourceSampleRate;
314 sv_samplerate_t m_targetSampleRate; 338 sv_samplerate_t m_deviceSampleRate;
315 sv_frame_t m_playLatency; 339 sv_frame_t m_playLatency;
316 breakfastquay::SystemPlaybackTarget *m_target; 340 breakfastquay::SystemPlaybackTarget *m_target;
317 double m_lastRetrievalTimestamp; 341 double m_lastRetrievalTimestamp;
318 sv_frame_t m_lastRetrievedBlockSize; 342 sv_frame_t m_lastRetrievedBlockSize;
319 bool m_trustworthyTimestamps; 343 bool m_trustworthyTimestamps;
394 }; 418 };
395 419
396 QMutex m_mutex; 420 QMutex m_mutex;
397 QWaitCondition m_condition; 421 QWaitCondition m_condition;
398 FillThread *m_fillThread; 422 FillThread *m_fillThread;
423 breakfastquay::ResamplerWrapper *m_resamplerWrapper; // I don't own this
399 }; 424 };
400 425
401 #endif 426 #endif
402 427
403 428