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
16#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
41class Mixer : public IFrameReader, public core::NonCopyable<> {
42public:
43 //! Initialize.
44 //!
45 //! @b Parameters
46 //! - @p buffer_factory is used to allocate a temporary buffer of samples
47 //! - @p frame_length defines the temporary buffer length used to
48 //! read from, in nanoseconds
49 //! - @p sample_spec defines the sample spec taken from the audio signal
51 core::nanoseconds_t frame_length,
52 const audio::SampleSpec& sample_spec);
53
54 //! Check if the mixer was succefully constructed.
55 bool valid() const;
56
57 //! Add input reader.
59
60 //! Remove input reader.
62
63 //! Read audio frame.
64 //! @remarks
65 //! Reads samples from every input reader, mixes them, and fills @p frame
66 //! with the result.
67 virtual bool read(Frame& frame);
68
69private:
70 void read_(sample_t* out_data, size_t out_sz, unsigned& flags);
71
73 core::Slice<sample_t> temp_buf_;
74
75 bool valid_;
76};
77
78} // namespace audio
79} // namespace roc
80
81#endif // ROC_AUDIO_MIXER_H_
Buffer factory.
Audio frame.
Definition: frame.h:22
Frame reader interface.
Definition: iframe_reader.h:22
Mixer. Mixes multiple input streams into one output stream.
Definition: mixer.h:41
Mixer(core::BufferFactory< sample_t > &buffer_factory, core::nanoseconds_t frame_length, const audio::SampleSpec &sample_spec)
Initialize.
bool valid() const
Check if the mixer was succefully constructed.
void remove_input(IFrameReader &)
Remove input reader.
virtual bool read(Frame &frame)
Read audio frame.
void add_input(IFrameReader &)
Add input reader.
Sample stream specification. Defines sample rate and channel layout.
Definition: sample_spec.h:24
Intrusive doubly-linked list.
Definition: list.h:35
Base class for non-copyable objects.
Definition: noncopyable.h:23
Slice.
Definition: slice.h:54
Frame reader interface.
Intrusive doubly-linked list.
float sample_t
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.