Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
mixer.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2015 Roc Streaming authors
3
*
4
* This Source Code Form is subject to the terms of the Mozilla Public
5
* License, v. 2.0. If a copy of the MPL was not distributed with this
6
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
*/
8
9
//! @file roc_audio/mixer.h
10
//! @brief Mixer.
11
12
#ifndef ROC_AUDIO_MIXER_H_
13
#define ROC_AUDIO_MIXER_H_
14
15
#include "
roc_audio/frame_factory.h
"
16
#include "
roc_audio/iframe_reader.h
"
17
#include "
roc_audio/sample.h
"
18
#include "
roc_audio/sample_spec.h
"
19
#include "
roc_core/list.h
"
20
#include "
roc_core/noncopyable.h
"
21
#include "
roc_core/slice.h
"
22
#include "
roc_core/time.h
"
23
#include "
roc_packet/units.h
"
24
25
namespace
roc
{
26
namespace
audio
{
27
28
//! Mixer.
29
//! Mixes multiple input streams into one output stream.
30
//!
31
//! For example, these two input streams:
32
//! @code
33
//! 1, 2, 3, ...
34
//! 4, 5, 6, ...
35
//! @endcode
36
//!
37
//! are transformed into this output stream:
38
//! @code
39
//! 5, 7, 9, ...
40
//! @endcode
41
//!
42
//! If timestamps are enabled, mixer computes capture timestamp of output
43
//! frame as the average capture timestamps of all mixed input frames.
44
//! This makes sense only when all inputs are synchronized and their
45
//! timestamps are close to each other.
46
class
Mixer
:
public
IFrameReader
,
public
core::NonCopyable
<> {
47
public
:
48
//! Initialize.
49
//! @p buffer_factory is used to allocate a temporary buffer for mixing.
50
//! @p enable_timestamps defines whether to enable calculation of capture timestamps.
51
Mixer
(
FrameFactory
& frame_factory,
52
const
SampleSpec
& sample_spec,
53
bool
enable_timestamps);
54
55
//! Check if the mixer was succefully constructed.
56
bool
is_valid
()
const
;
57
58
//! Add input reader.
59
void
add_input
(
IFrameReader
&);
60
61
//! Remove input reader.
62
void
remove_input
(
IFrameReader
&);
63
64
//! Read audio frame.
65
//! @remarks
66
//! Reads samples from every input reader, mixes them, and fills @p frame
67
//! with the result.
68
virtual
bool
read
(
Frame
& frame);
69
70
private
:
71
void
read_(
sample_t
* out_data,
72
size_t
out_size,
73
unsigned
& out_flags,
74
core::nanoseconds_t
& out_cts);
75
76
core::List<IFrameReader, core::NoOwnership>
readers_;
77
core::Slice<sample_t>
temp_buf_;
78
79
const
SampleSpec
sample_spec_;
80
const
bool
enable_timestamps_;
81
82
bool
valid_;
83
};
84
85
}
// namespace audio
86
}
// namespace roc
87
88
#endif
// ROC_AUDIO_MIXER_H_
roc::audio::FrameFactory
Frame factory.
Definition
frame_factory.h:38
roc::audio::Frame
Audio frame.
Definition
frame.h:25
roc::audio::IFrameReader
Frame reader interface.
Definition
iframe_reader.h:22
roc::audio::Mixer::is_valid
bool is_valid() const
Check if the mixer was succefully constructed.
roc::audio::Mixer::remove_input
void remove_input(IFrameReader &)
Remove input reader.
roc::audio::Mixer::read
virtual bool read(Frame &frame)
Read audio frame.
roc::audio::Mixer::Mixer
Mixer(FrameFactory &frame_factory, const SampleSpec &sample_spec, bool enable_timestamps)
Initialize. buffer_factory is used to allocate a temporary buffer for mixing. enable_timestamps defin...
roc::audio::Mixer::add_input
void add_input(IFrameReader &)
Add input reader.
roc::audio::SampleSpec
Sample specification. Describes sample rate and channels.
Definition
sample_spec.h:30
roc::core::List
Intrusive doubly-linked list.
Definition
list.h:40
roc::core::NonCopyable
Base class for non-copyable objects.
Definition
noncopyable.h:23
roc::core::Slice
Slice.
Definition
slice.h:55
frame_factory.h
Frame factory.
iframe_reader.h
Frame reader interface.
list.h
Intrusive doubly-linked list.
roc::audio
Audio frames and audio processing.
roc::audio::sample_t
float sample_t
Raw audio sample.
Definition
sample.h:22
roc::core::nanoseconds_t
int64_t nanoseconds_t
Nanoseconds.
Definition
time.h:58
roc
Root namespace.
noncopyable.h
Non-copyable object.
sample.h
Audio sample.
sample_spec.h
Sample specifications.
slice.h
Slice.
time.h
Time definitions.
units.h
Various units used in packets.
roc_audio
mixer.h
Generated by
1.17.0