Mercurial > hg > svapp
comparison audio/AudioCallbackPlaySource.h @ 738:48001ed9143b audio-source-refactor
Introduce TimeStretchWrapper; some work towards making the AudioCallbackPlaySource not actually try to be an ApplicationPlaybackSource itself but only return one that is constructed from wrappers that it controls the lifespan of
author | Chris Cannam |
---|---|
date | Wed, 18 Mar 2020 12:51:41 +0000 |
parents | 497d80d3b9c4 |
children | ddfac001b543 |
comparison
equal
deleted
inserted
replaced
737:497d80d3b9c4 | 738:48001ed9143b |
---|---|
34 #include <samplerate.h> | 34 #include <samplerate.h> |
35 | 35 |
36 #include <set> | 36 #include <set> |
37 #include <map> | 37 #include <map> |
38 | 38 |
39 namespace RubberBand { | |
40 class RubberBandStretcher; | |
41 } | |
42 | |
43 namespace breakfastquay { | 39 namespace breakfastquay { |
44 class ResamplerWrapper; | 40 class ResamplerWrapper; |
45 } | 41 } |
46 | 42 |
47 class Model; | 43 class Model; |
48 class ViewManagerBase; | 44 class ViewManagerBase; |
49 class AudioGenerator; | 45 class AudioGenerator; |
50 class PlayParameters; | 46 class PlayParameters; |
51 class RealTimePluginInstance; | 47 class RealTimePluginInstance; |
52 class AudioCallbackPlayTarget; | 48 class AudioCallbackPlayTarget; |
49 class TimeStretchWrapper; | |
53 | 50 |
54 /** | 51 /** |
55 * AudioCallbackPlaySource manages audio data supply to callback-based | 52 * AudioCallbackPlaySource manages audio data supply to callback-based |
56 * audio APIs such as JACK or CoreAudio. It maintains one ring buffer | 53 * audio APIs such as JACK or CoreAudio. It maintains one ring buffer |
57 * per channel, filled during playback by a non-realtime thread, and | 54 * per channel, filled during playback by a non-realtime thread, and |
58 * provides a method for a realtime thread to pick up the latest | 55 * provides a method for a realtime thread to pick up the latest |
59 * available sample data from these buffers. | 56 * available sample data from these buffers. |
60 */ | 57 */ |
61 class AudioCallbackPlaySource : public QObject, | 58 class AudioCallbackPlaySource : public QObject, |
62 public AudioPlaySource, | 59 public AudioPlaySource, |
60 //!!! to remove: | |
63 public breakfastquay::ApplicationPlaybackSource | 61 public breakfastquay::ApplicationPlaybackSource |
64 { | 62 { |
65 Q_OBJECT | 63 Q_OBJECT |
66 | 64 |
67 public: | 65 public: |
68 AudioCallbackPlaySource(ViewManagerBase *, QString clientName); | 66 AudioCallbackPlaySource(ViewManagerBase *, QString clientName); |
69 virtual ~AudioCallbackPlaySource(); | 67 virtual ~AudioCallbackPlaySource(); |
68 | |
69 /** | |
70 * Return an ApplicationPlaybackSource interface to this class. | |
71 * The returned pointer is only borrowed, and the object continues | |
72 * to be owned by us. Caller must ensure the lifetime of the | |
73 * AudioCallbackPlaySource exceeds the scope in which the pointer | |
74 * is retained. | |
75 */ | |
76 breakfastquay::ApplicationPlaybackSource *getApplicationPlaybackSource(); | |
70 | 77 |
71 /** | 78 /** |
72 * Add a data model to be played from. The source can mix | 79 * Add a data model to be played from. The source can mix |
73 * playback from a number of sources including dense and sparse | 80 * playback from a number of sources including dense and sparse |
74 * models. The models must match in sample rate, but they don't | 81 * models. The models must match in sample rate, but they don't |
122 | 129 |
123 /** | 130 /** |
124 * Set the playback target. | 131 * Set the playback target. |
125 */ | 132 */ |
126 virtual void setSystemPlaybackTarget(breakfastquay::SystemPlaybackTarget *); | 133 virtual void setSystemPlaybackTarget(breakfastquay::SystemPlaybackTarget *); |
127 | |
128 /** | |
129 * Set the resampler wrapper, if one is in use. | |
130 */ | |
131 virtual void setResamplerWrapper(breakfastquay::ResamplerWrapper *); | |
132 | 134 |
133 /** | 135 /** |
134 * Set the block size of the target audio device. This should be | 136 * Set the block size of the target audio device. This should be |
135 * called by the target class. | 137 * called by the target class. |
136 */ | 138 */ |
313 bool willResample); | 315 bool willResample); |
314 | 316 |
315 void channelCountIncreased(int count); // target channel count (see getTargetChannelCount()) | 317 void channelCountIncreased(int count); // target channel count (see getTargetChannelCount()) |
316 | 318 |
317 void audioOverloadPluginDisabled(); | 319 void audioOverloadPluginDisabled(); |
318 void audioTimeStretchMultiChannelDisabled(); | |
319 | 320 |
320 void activity(QString); | 321 void activity(QString); |
321 | 322 |
322 public slots: | 323 public slots: |
323 void audioProcessingOverload() override; | 324 void audioProcessingOverload() override; |
395 } | 396 } |
396 | 397 |
397 void clearRingBuffers(bool haveLock = false, int count = 0); | 398 void clearRingBuffers(bool haveLock = false, int count = 0); |
398 void unifyRingBuffers(); | 399 void unifyRingBuffers(); |
399 | 400 |
400 RubberBand::RubberBandStretcher *m_timeStretcher; | |
401 RubberBand::RubberBandStretcher *m_monoStretcher; | |
402 double m_stretchRatio; | |
403 bool m_stretchMono; | |
404 | |
405 int m_stretcherInputCount; | |
406 float **m_stretcherInputs; | |
407 sv_frame_t *m_stretcherInputSizes; | |
408 | |
409 // Called from fill thread, m_playing true, mutex held | 401 // Called from fill thread, m_playing true, mutex held |
410 // Return true if work done | 402 // Return true if work done |
411 bool fillBuffers(); | 403 bool fillBuffers(); |
412 | 404 |
413 // Called from fillBuffers. Return the number of frames written, | 405 // Called from fillBuffers. Return the number of frames written, |
440 }; | 432 }; |
441 | 433 |
442 QMutex m_mutex; | 434 QMutex m_mutex; |
443 QWaitCondition m_condition; | 435 QWaitCondition m_condition; |
444 FillThread *m_fillThread; | 436 FillThread *m_fillThread; |
445 breakfastquay::ResamplerWrapper *m_resamplerWrapper; // I don't own this | 437 breakfastquay::ResamplerWrapper *m_resamplerWrapper; |
438 TimeStretchWrapper *m_timeStretchWrapper; | |
439 void checkWrappers(); | |
446 }; | 440 }; |
447 | 441 |
448 #endif | 442 #endif |
449 | 443 |
450 |