forked from juce-framework/JUCE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAUInputElement.cpp
85 lines (71 loc) · 2.21 KB
/
AUInputElement.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*!
@file AudioUnitSDK/AUInputElement.cpp
@copyright © 2000-2021 Apple Inc. All rights reserved.
*/
#include <AudioUnitSDK/AUBase.h>
namespace ausdk {
constexpr bool HasGoodBufferPointers(const AudioBufferList& abl, UInt32 nBytes) noexcept
{
const AudioBuffer* buf = abl.mBuffers; // NOLINT
for (UInt32 i = abl.mNumberBuffers; i-- > 0; ++buf) { // NOLINT
if (buf->mData == nullptr || buf->mDataByteSize < nBytes) {
return false;
}
}
return true;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// AUInputElement::SetConnection
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void AUInputElement::SetConnection(const AudioUnitConnection& conn)
{
if (conn.sourceAudioUnit == nullptr) {
Disconnect();
return;
}
mInputType = EInputType::FromConnection;
mConnection = conn;
AllocateBuffer();
}
void AUInputElement::Disconnect()
{
mInputType = EInputType::NoInput;
IOBuffer().Deallocate();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// AUInputElement::SetInputCallback
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void AUInputElement::SetInputCallback(AURenderCallback proc, void* refCon)
{
if (proc == nullptr) {
Disconnect();
} else {
mInputType = EInputType::FromCallback;
mInputProc = proc;
mInputProcRefCon = refCon;
AllocateBuffer();
}
}
OSStatus AUInputElement::SetStreamFormat(const AudioStreamBasicDescription& fmt)
{
const OSStatus err = AUIOElement::SetStreamFormat(fmt);
if (err == noErr) {
AllocateBuffer();
}
return err;
}
OSStatus AUInputElement::PullInput(AudioUnitRenderActionFlags& ioActionFlags,
const AudioTimeStamp& inTimeStamp, AudioUnitElement inElement, UInt32 nFrames)
{
if (!IsActive()) {
return kAudioUnitErr_NoConnection;
}
auto& iob = IOBuffer();
AudioBufferList& pullBuffer = (HasConnection() || !WillAllocateBuffer())
? iob.PrepareNullBuffer(GetStreamFormat(), nFrames)
: iob.PrepareBuffer(GetStreamFormat(), nFrames);
return PullInputWithBufferList(ioActionFlags, inTimeStamp, inElement, nFrames, pullBuffer);
}
} // namespace ausdk