HART
0.2.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
hart_audio_buffer_fill_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
>::
_fillWith
(
SignalBase
<
SampleType
>&
signal
,
size_t
requestedBlockSizeFrames
,
Preparation
signalPreparation
)
9
{
10
if
(
getNumChannels
() == 0)
11
HART_THROW_OR_RETURN_VOID
(
hart
::
ChannelLayoutError
,
"Can't fill an AudioBuffer with Signal 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 fill an AudioBuffer with Signal 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 fill an AudioBuffer with Signal if the buffer's sample rate is undefined"
);
18
19
if
(!
signal
.
supportsNumChannelsWithDSPChain
(
getNumChannels
()))
20
HART_THROW_OR_RETURN_VOID
(
hart
::
ChannelLayoutError
,
"Signal or an effect in its DSP chain doesn't support the number of channels that this buffer has"
);
21
22
if
(!
signal
.
supportsSampleRateWithDSPChain
(
getSampleRateHz
()))
23
HART_THROW_OR_RETURN_VOID
(
hart
::
SampleRateError
,
"Signal or an effect in its DSP chain doesn't support the sample rate that this buffer has"
);
24
25
const
size_t
blockSizeFrames
= (
requestedBlockSizeFrames
== 0) ?
getNumFrames
() :
requestedBlockSizeFrames
;
26
27
if
(
signalPreparation
==
Preparation
::
reset
||
signalPreparation
==
Preparation
::
resetAndPrepare
)
28
signal
.
resetWithDSPChain
();
29
30
if
(
signalPreparation
==
Preparation
::
prepare
||
signalPreparation
==
Preparation
::
resetAndPrepare
)
31
signal
.
prepareWithDSPChain
(
getSampleRateHz
(),
getNumChannels
(),
blockSizeFrames
);
32
33
if
(
blockSizeFrames
>=
getNumFrames
())
34
{
35
// Render in one go
36
signal
.
renderNextBlockWithDSPChain
(*
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
signal
.
renderNextBlockWithDSPChain
(
block
);
58
59
hassert
(
getNumFrames
() >
block
.
getNumFrames
());
60
hassert
(
getNumChannels
() ==
block
.
getNumChannels
());
61
62
for
(
size_t
channel
= 0;
channel
<
getNumChannels
(); ++
channel
)
63
copyFrom
(
channel
,
offsetFrames
,
block
,
channel
, 0,
currentBlockSizeFrames
);
64
65
offsetFrames
+=
currentBlockSizeFrames
;
66
}
67
}
68
69
}
// 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_fill_with.hpp
Generated on Mon May 18 2026 20:20:00 for HART by
1.9.8
© 2025 HART by
Daniel Leonov