HART
0.2.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
hart_audio_buffer_process_with.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
#
include
"hart_exceptions.hpp"
4
5
namespace
hart
{
6
7
template
<
typename
SampleType
>
8
void
AudioBuffer
<
SampleType
>::
_processWith
(
DSPBase
<
SampleType
>&
dsp
,
size_t
requestedBlockSizeFrames
,
Preparation
dspPreparation
)
9
{
10
if
(
getNumChannels
() == 0)
11
HART_THROW_OR_RETURN_VOID
(
hart
::
ChannelLayoutError
,
"Can't process an AudioBuffer with a DSP if the buffer is default-constructed or has no channels allocated"
);
12
13
if
(
getNumFrames
() == 0)
14
HART_THROW_OR_RETURN_VOID
(
hart
::
SizeError
,
"Can't process an AudioBuffer with a DSP if the buffer is default-constructed or has no frames allocated"
);
15
16
if
(!
hasSampleRate
())
17
HART_THROW_OR_RETURN_VOID
(
hart
::
SampleRateError
,
"Can't process an AudioBuffer with a DSP if the buffer's sample rate is undefined"
);
18
19
if
(!
dsp
.
supportsChannelLayout
(
getNumChannels
(),
getNumChannels
()))
20
HART_THROW_OR_RETURN_VOID
(
hart
::
ChannelLayoutError
,
"Provided DSP doesn't support the number of channels that this buffer has"
);
21
22
if
(!
dsp
.
supportsSampleRate
(
getSampleRateHz
()))
23
HART_THROW_OR_RETURN_VOID
(
hart
::
SampleRateError
,
"Provided DSP doesn't support the sample rate that this buffer has"
);
24
25
const
size_t
blockSizeFrames
= (
requestedBlockSizeFrames
== 0) ?
getNumFrames
() :
requestedBlockSizeFrames
;
26
27
if
(
dspPreparation
==
Preparation
::
reset
||
dspPreparation
==
Preparation
::
resetAndPrepare
)
28
dsp
.
resetWithEnvelopes
();
29
30
if
(
dspPreparation
==
Preparation
::
prepare
||
dspPreparation
==
Preparation
::
resetAndPrepare
)
31
dsp
.
prepareWithEnvelopes
(
getSampleRateHz
(),
getNumChannels
(),
getNumChannels
(),
blockSizeFrames
);
32
33
if
(
blockSizeFrames
>=
getNumFrames
())
34
{
35
// Render in one go
36
dsp
.
processWithEnvelopes
(*
this
, *
this
);
37
return
;
38
}
39
40
size_t
offsetFrames
= 0;
41
hart
::
AudioBuffer
<
SampleType
>
block
(
getNumChannels
(),
blockSizeFrames
,
getSampleRateHz
());
42
43
while
(
offsetFrames
<
getNumFrames
())
44
{
45
const
size_t
currentBlockSizeFrames
=
std
::
min
(
blockSizeFrames
,
getNumFrames
() -
offsetFrames
);
46
hassert
(
currentBlockSizeFrames
<=
blockSizeFrames
);
47
48
if
(
currentBlockSizeFrames
!=
block
.
getNumFrames
())
49
{
50
// Expecting partial block at the end
51
hassert
(
currentBlockSizeFrames
<
blockSizeFrames
);
52
hassert
(
block
.
getNumFrames
() ==
blockSizeFrames
);
53
54
block
.
setNumFrames
(
currentBlockSizeFrames
);
55
}
56
57
hassert
(
getNumFrames
() >
block
.
getNumFrames
());
58
hassert
(
getNumChannels
() ==
block
.
getNumChannels
());
59
60
for
(
size_t
channel
= 0;
channel
<
getNumChannels
(); ++
channel
)
61
block
.
copyFrom
(
channel
, 0, *
this
,
channel
,
offsetFrames
,
currentBlockSizeFrames
);
62
63
dsp
.
processWithEnvelopes
(
block
,
block
);
64
65
for
(
size_t
channel
= 0;
channel
<
getNumChannels
(); ++
channel
)
66
copyFrom
(
channel
,
offsetFrames
,
block
,
channel
, 0,
currentBlockSizeFrames
);
67
68
offsetFrames
+=
currentBlockSizeFrames
;
69
}
70
}
71
72
}
// namespace hart
HART_THROW_OR_RETURN_VOID
#define HART_THROW_OR_RETURN_VOID(ExceptionType, message)
Throws an exception if HART_DO_NOT_THROW_EXCEPTIONS is set, prints a message and returns otherwise.
Definition
hart_exceptions.hpp:157
hassert
#define hassert(condition)
Triggers a HartAssertException if the condition is false
Definition
hart_exceptions.hpp:172
hart
Definition
hart_additive_noise.hpp:13
include
hart_audio_buffer_process_with.hpp
Generated on Mon May 18 2026 20:20:01 for HART by
1.9.8
© 2025 HART by
Daniel Leonov