libASPL
Loading...
Searching...
No Matches
MuteControl.hpp
Go to the documentation of this file.
1// Copyright (c) libASPL authors
2// Licensed under MIT
3
4//! @file aspl/MuteControl.hpp
5//! @brief Mute control object.
6
7#pragma once
8
9#include <aspl/Direction.hpp>
10#include <aspl/Object.hpp>
11
12#include <CoreAudio/AudioServerPlugIn.h>
13
14#include <atomic>
15#include <mutex>
16
17namespace aspl {
18
19//! Mute control parameters.
21{
22 //! Define whether this is input or output control.
23 //! Used by default implementation of MuteControl::GetScope().
25};
26
27//! Mute control object.
28//!
29//! Stores a boolean state, indicating whether something is muted or not.
30//!
31//! Mute control does not affect I/O by its own. It just stores the mute flag
32//! and provides ApplyProcessing() method which zeroises provided samples if
33//! the mute flag is set.
34//!
35//! You can attach MuteControl to the Stream using Stream::AttachMuteControl()
36//! method, and then stream will use it to process samples passed to stream.
37//! Alternatively, you can invoke MuteControls manually the way you need.
38class MuteControl : public Object
39{
40public:
41 //! Construct stream.
42 explicit MuteControl(std::shared_ptr<const Context> context,
43 const MuteControlParameters& params = {});
44
45 //! @name Getters and setters
46 //! @{
47
48 //! Get the scope that the control is attached to.
49 //! Can return kAudioObjectPropertyScopeInput or kAudioObjectPropertyScopeOutput.
50 //! By default returns MuteControlParameters::Scope.
51 //! @note
52 //! Backs @c kAudioControlPropertyScope property.
54
55 //! Get the element that the control is attached to.
56 //! Typically should return kAudioObjectPropertyElementMain.
57 //! By default returns kAudioObjectPropertyElementMain.
58 //! @note
59 //! Backs @c kAudioControlPropertyElement property.
61
62 //! Get muted boolean state.
63 //! By default returns internal muted state.
64 //! Initial value of the flag is false.
65 //! @note
66 //! Backs @c kAudioBooleanControlPropertyValue property.
67 virtual bool GetIsMuted() const;
68
69 //! Set muted boolean state.
70 //! Invokes SetIsMutedImpl() and NotifyPropertiesChanged().
71 //! @note
72 //! Backs @c kAudioBooleanControlPropertyValue property.
74
75 //! @}
76
77 //! @name Processing
78 //! @{
79
80 //! Apply processing to given buffer.
81 //! The provided buffer contains exactly @p frameCount * @p channelCount samples.
82 //! If GetIsMuted() is false, this method does nothing.
83 //! If GetIsMuted() is true, this method overrides all samples with zeros.
84 //! @note
85 //! Invoked by Stream::ApplyProcessing() on realtime thread.
88 UInt32 channelCount) const;
89
90 //! @}
91
92 //! @name Property dispatch
93 //! @{
94
95 //! Get class ID.
96 AudioClassID GetClass() const override;
97
98 //! Get base class ID.
99 AudioClassID GetBaseClass() const override;
100
101 //! Check if this object is instance of given base class.
102 bool IsInstance(AudioClassID classID) const override;
103
104 //! Check whether given property is present.
107 const AudioObjectPropertyAddress* address) const override;
108
109 //! Check whether given property can be changed.
113 Boolean* outIsSettable) const override;
114
115 //! Get size of property value in bytes.
120 const void* qualifierData,
121 UInt32* outDataSize) const override;
122
123 //! Get property value.
128 const void* qualifierData,
131 void* outData) const override;
132
133 //! Change property value.
138 const void* qualifierData,
140 const void* inData) override;
141
142 //! @}
143
144protected:
145 //! @name Setters implementation
146 //! @{
147
148 //! Set muted boolean state.
149 //! Invoked by SetIsMuted().
150 //! By default sets internal muted state.
151 //! @note
152 //! Backs @c kAudioBooleanControlPropertyValue property.
154
155 //! @}
156
157private:
158 const MuteControlParameters params_;
159
160 std::mutex writeMutex_;
161 std::atomic<bool> isMuted_ = false;
162};
163
164} // namespace aspl
I/O direction.
Basic audio object.
Doubly-buffered value with non-blocking read and blocking write.
Mute control object.
virtual bool GetIsMuted() const
Get muted boolean state. By default returns internal muted state. Initial value of the flag is false.
Boolean HasProperty(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address) const override
Check whether given property is present.
OSStatus IsPropertySettable(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, Boolean *outIsSettable) const override
Check whether given property can be changed.
virtual void ApplyProcessing(Float32 *frames, UInt32 frameCount, UInt32 channelCount) const
Apply processing to given buffer. The provided buffer contains exactly frameCount * channelCount samp...
virtual AudioObjectPropertyElement GetElement() const
Get the element that the control is attached to. Typically should return kAudioObjectPropertyElementM...
virtual OSStatus SetIsMutedImpl(bool isMuted)
Set muted boolean state. Invoked by SetIsMuted(). By default sets internal muted state.
OSStatus SetIsMuted(bool isMuted)
Set muted boolean state. Invokes SetIsMutedImpl() and NotifyPropertiesChanged().
AudioClassID GetBaseClass() const override
Get base class ID.
OSStatus GetPropertyData(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, UInt32 qualifierDataSize, const void *qualifierData, UInt32 inDataSize, UInt32 *outDataSize, void *outData) const override
Get property value.
AudioClassID GetClass() const override
Get class ID.
bool IsInstance(AudioClassID classID) const override
Check if this object is instance of given base class.
virtual AudioObjectPropertyScope GetScope() const
Get the scope that the control is attached to. Can return kAudioObjectPropertyScopeInput or kAudioObj...
OSStatus SetPropertyData(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, UInt32 qualifierDataSize, const void *qualifierData, UInt32 inDataSize, const void *inData) override
Change property value.
OSStatus GetPropertyDataSize(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, UInt32 qualifierDataSize, const void *qualifierData, UInt32 *outDataSize) const override
Get size of property value in bytes.
MuteControl(std::shared_ptr< const Context > context, const MuteControlParameters &params={})
Construct stream.
Base class for audio objects.
Definition Object.hpp:55
Mute control parameters.
AudioObjectPropertyScope Scope
Define whether this is input or output control. Used by default implementation of MuteControl::GetSco...