Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
channel_mapper.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 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/channel_mapper.h
10 //! @brief Channel mapper.
11 
12 #ifndef ROC_AUDIO_CHANNEL_MAPPER_H_
13 #define ROC_AUDIO_CHANNEL_MAPPER_H_
14 
16 #include "roc_audio/channel_set.h"
17 #include "roc_core/noncopyable.h"
18 
19 namespace roc {
20 namespace audio {
21 
22 //! Channel mapper.
23 //!
24 //! Converts between input and output samples with specified channel sets.
25 //!
26 //! Supports converting between:
27 //! - different channel layouts (e.g. surround, multitrack)
28 //! - different channel orders (e.g. smpte, alsa)
29 //! - different channel masks (e.g. stereo, mono)
30 class ChannelMapper : public core::NonCopyable<> {
31 public:
32  //! Initialize.
33  ChannelMapper(const ChannelSet& in_chans, const ChannelSet& out_chans);
34 
35  //! Map samples.
36  void map(const sample_t* in_samples,
37  size_t n_in_samples,
38  sample_t* out_samples,
39  size_t n_out_samples);
40 
41 private:
42  typedef void (ChannelMapper::*map_func_t)(const sample_t* in_samples,
43  sample_t* out_samples,
44  size_t n_samples);
45 
46  void map_surround_surround_(const sample_t* in_samples,
47  sample_t* out_samples,
48  size_t n_samples);
49  void map_multitrack_surround_(const sample_t* in_samples,
50  sample_t* out_samples,
51  size_t n_samples);
52  void map_multitrack_multitrack_(const sample_t* in_samples,
53  sample_t* out_samples,
54  size_t n_samples);
55 
56  void setup_map_func_();
57 
58  const ChannelSet in_chans_;
59  const ChannelSet out_chans_;
60  ChannelSet inout_chans_;
61 
62  map_func_t map_func_;
63 
64  // use for surround <=> surround mapping
65  ChannelMapperMatrix map_matrix_;
66 };
67 
68 } // namespace audio
69 } // namespace roc
70 
71 #endif // ROC_AUDIO_CHANNEL_MAPPER_H_
Channel mapping matrix.
Channel set.
void map(const sample_t *in_samples, size_t n_in_samples, sample_t *out_samples, size_t n_out_samples)
Map samples.
ChannelMapper(const ChannelSet &in_chans, const ChannelSet &out_chans)
Initialize.
Channel set. Multi-word bitmask with bits corresponding to enabled channels. Meaning of each channel ...
Definition: channel_set.h:26
Base class for non-copyable objects.
Definition: noncopyable.h:23
float sample_t
Raw audio sample.
Definition: sample.h:22
Root namespace.
Non-copyable object.