Ardour
9.0-pre0-582-g084a23a80d
chunker.h
Go to the documentation of this file.
1
#ifndef AUDIOGRAPHER_CHUNKER_H
2
#define AUDIOGRAPHER_CHUNKER_H
3
4
#include "
audiographer/visibility.h
"
5
#include "
audiographer/flag_debuggable.h
"
6
#include "
audiographer/sink.h
"
7
#include "
audiographer/type_utils.h
"
8
#include "
audiographer/utils/listed_source.h
"
9
10
namespace
AudioGrapher
11
{
12
14
template
<
typename
T = DefaultSampleType>
15
class
/*LIBAUDIOGRAPHER_API*/
Chunker
16
:
public
ListedSource
<T>
17
,
public
Sink
<T>
18
,
public
FlagDebuggable
<>
19
{
20
public
:
24
Chunker
(
samplecnt_t
chunk_size
)
25
:
chunk_size
(
chunk_size
)
26
,
position
(0)
27
{
28
buffer
=
new
T[
chunk_size
];
29
add_supported_flag
(
ProcessContext<T>::EndOfInput
);
30
}
31
32
~Chunker
()
33
{
34
delete
[]
buffer
;
35
}
36
41
void
process
(
ProcessContext<T>
const
& context)
42
{
43
check_flags
(*
this
, context);
44
45
samplecnt_t
samples_left = context.
samples
();
46
samplecnt_t
input_position = 0;
47
48
while
(
position
+ samples_left >=
chunk_size
) {
49
// Copy from context to buffer
50
samplecnt_t
const
samples_to_copy =
chunk_size
-
position
;
51
TypeUtils<T>::copy
(&context.
data
()[input_position], &
buffer
[
position
], samples_to_copy);
52
53
// Update counters
54
position
= 0;
55
input_position += samples_to_copy;
56
samples_left -= samples_to_copy;
57
58
// Output whole buffer
59
ProcessContext<T>
c_out (context,
buffer
,
chunk_size
);
60
if
(samples_left) { c_out.
remove_flag
(
ProcessContext<T>::EndOfInput
); }
61
ListedSource<T>::output
(c_out);
62
}
63
64
if
(samples_left) {
65
// Copy the rest of the data
66
TypeUtils<T>::copy
(&context.
data
()[input_position], &
buffer
[
position
], samples_left);
67
position
+= samples_left;
68
}
69
70
if
(context.
has_flag
(
ProcessContext<T>::EndOfInput
) &&
position
> 0) {
71
ProcessContext<T>
c_out (context,
buffer
,
position
);
72
ListedSource<T>::output
(c_out);
73
}
74
}
75
using
Sink<T>::process
;
76
77
private
:
78
samplecnt_t
chunk_size
;
79
samplecnt_t
position
;
80
T *
buffer
;
81
82
};
83
84
}
// namespace
85
86
#endif
// AUDIOGRAPHER_CHUNKER_H
87
visibility.h
AudioGrapher::Chunker
A class that chunks process cycles into equal sized samples.
Definition:
chunker.h:19
AudioGrapher::Chunker::process
void process(ProcessContext< T > const &context)
Definition:
chunker.h:41
AudioGrapher::Chunker::Chunker
Chunker(samplecnt_t chunk_size)
Definition:
chunker.h:24
AudioGrapher::Chunker::~Chunker
~Chunker()
Definition:
chunker.h:32
AudioGrapher::Chunker::position
samplecnt_t position
Definition:
chunker.h:79
AudioGrapher::Chunker::chunk_size
samplecnt_t chunk_size
Definition:
chunker.h:78
AudioGrapher::Chunker::buffer
T * buffer
Definition:
chunker.h:80
AudioGrapher::FlagDebuggable
A debugging class for nodes that support a certain set of flags.
Definition:
flag_debuggable.h:16
AudioGrapher::FlagDebuggable::check_flags
void check_flags(SelfType &self, ProcessContext< ContextType > context)
Prints debug output if context contains flags that are not supported by this class.
Definition:
flag_debuggable.h:30
AudioGrapher::FlagDebuggable::add_supported_flag
void add_supported_flag(Flag flag)
Adds a flag to the set of flags supported.
Definition:
flag_debuggable.h:23
AudioGrapher::ListedSource
An generic Source that uses a std::list for managing outputs.
Definition:
listed_source.h:17
AudioGrapher::ListedSource::output
void output(ProcessContext< T > const &c)
Helper for derived classes.
Definition:
listed_source.h:28
AudioGrapher::ProcessContext
Definition:
process_context.h:25
AudioGrapher::ProcessContext::has_flag
bool has_flag(Flag flag) const
Definition:
process_context.h:100
AudioGrapher::ProcessContext::data
T const * data() const
data points to the array of data to process
Definition:
process_context.h:84
AudioGrapher::ProcessContext::samples
samplecnt_t const & samples() const
samples tells how many samples the array pointed by data contains
Definition:
process_context.h:88
AudioGrapher::ProcessContext::remove_flag
void remove_flag(Flag flag) const
Definition:
process_context.h:102
AudioGrapher::Sink
Definition:
sink.h:17
AudioGrapher::TypeUtils::copy
static void copy(T const *source, T *destination, samplecnt_t samples)
Definition:
type_utils.h:49
flag_debuggable.h
listed_source.h
AudioGrapher
Definition:
analysis_graph.h:33
AudioGrapher::samplecnt_t
int64_t samplecnt_t
Definition:
audiographer/audiographer/types.h:11
sink.h
type_utils.h
libs
audiographer
audiographer
general
chunker.h
Generated on Thu Dec 26 2024 05:38:48 for Ardour by
1.9.1