Mercurial > hg > svapp
comparison audio/EffectWrapper.h @ 739:ddfac001b543 audio-source-refactor
Introduce EffectWrapper for the auditioning effect
author | Chris Cannam |
---|---|
date | Thu, 19 Mar 2020 16:14:02 +0000 |
parents | |
children | 54393ed09d65 |
comparison
equal
deleted
inserted
replaced
738:48001ed9143b | 739:ddfac001b543 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 | |
8 This program is free software; you can redistribute it and/or | |
9 modify it under the terms of the GNU General Public License as | |
10 published by the Free Software Foundation; either version 2 of the | |
11 License, or (at your option) any later version. See the file | |
12 COPYING included with this distribution for more information. | |
13 */ | |
14 | |
15 #ifndef SV_EFFECT_WRAPPER_H | |
16 #define SV_EFFECT_WRAPPER_H | |
17 | |
18 #include "bqaudioio/ApplicationPlaybackSource.h" | |
19 | |
20 #include "base/BaseTypes.h" | |
21 #include "base/RingBuffer.h" | |
22 | |
23 #include "plugin/RealTimePluginInstance.h" | |
24 | |
25 #include <vector> | |
26 #include <mutex> | |
27 #include <memory> | |
28 | |
29 /** | |
30 * A breakfastquay::ApplicationPlaybackSource wrapper that applies a | |
31 * real-time effect plugin. | |
32 */ | |
33 class EffectWrapper : public breakfastquay::ApplicationPlaybackSource | |
34 { | |
35 public: | |
36 /** | |
37 * Create a wrapper around the given ApplicationPlaybackSource, | |
38 * implementing another ApplicationPlaybackSource interface that | |
39 * draws from the same source data but with an effect optionally | |
40 * applied. | |
41 * | |
42 * The wrapper does not take ownership of the wrapped | |
43 * ApplicationPlaybackSource, whose lifespan must exceed that of | |
44 * this object. | |
45 */ | |
46 EffectWrapper(ApplicationPlaybackSource *source); | |
47 ~EffectWrapper(); | |
48 | |
49 /** | |
50 * Set the effect to apply. The effect instance is shared with the | |
51 * caller: the expectation is that the caller may continue to | |
52 * modify its parameters etc during auditioning. Replaces any | |
53 * instance previously set. | |
54 */ | |
55 void setEffect(std::weak_ptr<RealTimePluginInstance>); | |
56 | |
57 /** | |
58 * Remove any applied effect without setting another one. | |
59 */ | |
60 void clearEffect(); | |
61 | |
62 /** | |
63 * Bypass or un-bypass the effect. | |
64 */ | |
65 void setBypassed(bool bypassed); | |
66 | |
67 /** | |
68 * Return true if the effect is bypassed. | |
69 */ | |
70 bool isBypassed() const; | |
71 | |
72 /** | |
73 * Clear any buffered data. | |
74 */ | |
75 void reset(); | |
76 | |
77 // These functions are passed through to the wrapped | |
78 // ApplicationPlaybackSource | |
79 | |
80 std::string getClientName() const override; | |
81 int getApplicationSampleRate() const override; | |
82 int getApplicationChannelCount() const override; | |
83 | |
84 void setSystemPlaybackBlockSize(int) override; | |
85 void setSystemPlaybackSampleRate(int) override; | |
86 void setSystemPlaybackChannelCount(int) override; | |
87 void setSystemPlaybackLatency(int) override; | |
88 | |
89 void setOutputLevels(float peakLeft, float peakRight) override; | |
90 void audioProcessingOverload() override; | |
91 | |
92 /** | |
93 * Request some samples from the wrapped | |
94 * ApplicationPlaybackSource, apply effect if set, and return them | |
95 * to the target | |
96 */ | |
97 int getSourceSamples(float *const *samples, int nchannels, int nframes) | |
98 override; | |
99 | |
100 private: | |
101 ApplicationPlaybackSource *m_source; | |
102 std::weak_ptr<RealTimePluginInstance> m_effect; | |
103 bool m_bypassed; | |
104 bool m_failed; | |
105 int m_channelCount; | |
106 std::vector<RingBuffer<float>> m_effectOutputBuffers; | |
107 mutable std::mutex m_mutex; | |
108 | |
109 EffectWrapper(const EffectWrapper &)=delete; | |
110 EffectWrapper &operator=(const EffectWrapper &)=delete; | |
111 }; | |
112 | |
113 #endif | |
114 | |
115 |