Audacity 3.2.0
DownmixSource.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 DownmixSource.cpp
6
7 Dominic Mazzoni
8 Markus Meyer
9 Vaughan Johnson
10
11*******************************************************************/
12
13
14#include "DownmixSource.h"
15
16#include "AudioGraphChannel.h"
17#include "WideSampleSequence.h"
18
20 const WideSampleSequence& sequence,
21 const ArrayOf<bool> *channelMap)
22 : mDownstream(downstream)
23 , mSequence(sequence)
24 , mpMap(channelMap)
25{
26}
27
29{
30 return mDownstream;
31}
32
34{
35 return mSequence.NChannels();
36}
37
38float SequenceDownmixSource::GetChannelGain(size_t channel) const
39{
40 return mSequence.GetChannelVolume(channel);
41}
42
43void SequenceDownmixSource::FindChannelFlags(unsigned char *channelFlags, size_t numChannels, size_t iChannel)
44{
45 const bool* map = mpMap ? mpMap[iChannel].get() : nullptr;
46 const auto end = channelFlags + numChannels;
47 std::fill(channelFlags, end, 0);
48 if (map)
49 // ignore left and right when downmixing is customized
50 std::copy(map, map + numChannels, channelFlags);
52 std::fill(channelFlags, end, 1);
53 else if (iChannel == 0)
54 channelFlags[0] = 1;
55 else if (iChannel == 1) {
56 if (numChannels >= 2)
57 channelFlags[1] = 1;
58 else
59 channelFlags[0] = 1;
60 }
61}
63{
64 return mpMap == nullptr;
65}
66
68 : mDownstream(downstream), mNChannels(channels)
69{
70}
71
73{
74 return mDownstream;
75}
76
78{
79 return mNChannels;
80}
81
83{
84 return 1.0f;
85}
86
87void SimpleDonwmixSource::FindChannelFlags(unsigned char* channelFlags, size_t numChannels, size_t iChannel)
88{
89 if(mNChannels == 1)
90 {
91 for(size_t i = 0; i < numChannels; ++i)
92 channelFlags[i] = true;
93 }
94 else
95 {
96 for(size_t i = 0; i < numChannels; ++i)
97 channelFlags[i] = i == iChannel;
98 }
99}
100
102{
103 return true;
104}
Upstream producer of sample streams, taking Buffers as external context.
void FindChannelFlags(unsigned char *channelFlags, size_t numChannels, size_t iChannel) override
bool CanMakeMono() const override
Returns true if source channels could be combined into mono if needed.
const WideSampleSequence & mSequence
Definition: DownmixSource.h:48
SequenceDownmixSource(AudioGraph::Source &downstream, const WideSampleSequence &sequence, const ArrayOf< bool > *channelMap)
size_t NChannels() const override
Number of output channels of the underlying Source.
AudioGraph::Source & mDownstream
Definition: DownmixSource.h:47
const ArrayOf< bool > * mpMap
Definition: DownmixSource.h:51
float GetChannelGain(size_t channel) const override
Gain multiplier that should be applied to the channel.
AudioGraph::Source & GetDownstream() const override
Returns underlying AudioGraph::Source processed by Mixer.
AudioGraph::Source & GetDownstream() const override
Returns underlying AudioGraph::Source processed by Mixer.
SimpleDonwmixSource(AudioGraph::Source &downstream, size_t channels)
size_t NChannels() const override
Number of output channels of the underlying Source.
float GetChannelGain(size_t channel) const override
Gain multiplier that should be applied to the channel.
void FindChannelFlags(unsigned char *channelFlags, size_t numChannels, size_t iChannel) override
AudioGraph::Source & mDownstream
Definition: DownmixSource.h:70
bool CanMakeMono() const override
Returns true if source channels could be combined into mono if needed.
virtual float GetChannelVolume(int channel) const =0
virtual size_t NChannels() const =0
A constant property.
bool IsMono(const Channel &channel)
Whether the channel is mono.
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40