Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
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
17#include "roc_audio/sample.h"
19#include "roc_core/list.h"
21#include "roc_core/slice.h"
22#include "roc_core/time.h"
23#include "roc_packet/units.h"
24
25namespace roc {
26namespace 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.
46class Mixer : public IFrameReader, public core::NonCopyable<> {
47public:
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.
60
61 //! Remove input reader.
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
70private:
71 void read_(sample_t* out_data,
72 size_t out_size,
73 unsigned& out_flags,
74 core::nanoseconds_t& out_cts);
75
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_
Audio frame.
Definition frame.h:25
Frame reader interface.
Mixer. Mixes multiple input streams into one output stream.
Definition mixer.h:46
bool is_valid() const
Check if the mixer was succefully constructed.
void remove_input(IFrameReader &)
Remove input reader.
virtual bool read(Frame &frame)
Read audio frame.
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...
void add_input(IFrameReader &)
Add input reader.
Sample specification. Describes sample rate and channels.
Definition sample_spec.h:30
Intrusive doubly-linked list.
Definition list.h:40
Base class for non-copyable objects.
Definition noncopyable.h:23
Frame factory.
Frame reader interface.
Intrusive doubly-linked list.
float sample_t
Raw audio sample.
Definition sample.h:22
int64_t nanoseconds_t
Nanoseconds.
Definition time.h:58
Root namespace.
Non-copyable object.
Audio sample.
Sample specifications.
Slice.
Time definitions.
Various units used in packets.