Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
mixer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Roc 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/ireader.h"
16 #include "roc_audio/units.h"
17 #include "roc_core/list.h"
18 #include "roc_core/noncopyable.h"
19 #include "roc_core/pool.h"
20 #include "roc_core/slice.h"
21 
22 namespace roc {
23 namespace audio {
24 
25 //! Mixer.
26 //! Mixes multiple input streams into one output stream.
27 //!
28 //! For example, these two input streams:
29 //! @code
30 //! 1, 2, 3, ...
31 //! 4, 5, 6, ...
32 //! @endcode
33 //!
34 //! are transformed into this output stream:
35 //! @code
36 //! 5, 7, 9, ...
37 //! @endcode
38 class Mixer : public IReader, public core::NonCopyable<> {
39 public:
40  //! Initialize.
41  //!
42  //! @b Parameters
43  //! - @p pool is used to allocate a temporary buffer of samples
44  //! - @p frame_size defines the temporary buffer size used to read from
45  //! attached readers
46  explicit Mixer(core::BufferPool<sample_t>& pool, size_t frame_size);
47 
48  //! Check if the mixer was succefully constructed.
49  bool valid() const;
50 
51  //! Add input reader.
52  void add(IReader&);
53 
54  //! Remove input reader.
55  void remove(IReader&);
56 
57  //! Read audio frame.
58  //! @remarks
59  //! Reads samples from every input reader, mixes them, and fills @p frame
60  //! with the result.
61  virtual void read(Frame& frame);
62 
63 private:
64  void read_(sample_t* out_data, size_t out_sz);
65 
67  core::Slice<sample_t> temp_buf_;
68 
69  bool valid_;
70 };
71 
72 } // namespace audio
73 } // namespace roc
74 
75 #endif // ROC_AUDIO_MIXER_H_
Pool.
Various units used in audio processing.
virtual void read(Frame &frame)
Read audio frame.
Mixer(core::BufferPool< sample_t > &pool, size_t frame_size)
Initialize.
Root namespace.
Intrusive doubly-linked list.
Definition: list.h:31
float sample_t
Audio sample.
Definition: units.h:21
bool valid() const
Check if the mixer was succefully constructed.
Audio reader interface.
Audio frame.
Definition: frame.h:22
Intrusive doubly-linked list.
void add(IReader &)
Add input reader.
Base class for non-copyable objects.
Definition: noncopyable.h:23
Audio reader interface.
Definition: ireader.h:22
Slice.
Non-copyable object.
Mixer. Mixes multiple input streams into one output stream.
Definition: mixer.h:38