Audacity 3.2.0
MixerOptions.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file MixerOptions.cpp
6
7 Dominic Mazzoni
8 Markus Meyer
9 Vaughan Johnson
10
11 Paul Licameli split from Mix.cpp
12
13**********************************************************************/
14#include "MixerOptions.h"
15
16#include "Envelope.h"
17
19: envelope(DefaultWarp::Call(pProject)), minSpeed(0.0), maxSpeed(0.0)
20{
21}
22
24 : envelope(e), minSpeed(0.0), maxSpeed(0.0)
25 {}
26
27MixerOptions::Warp::Warp(double min, double max, double initial)
28 : minSpeed{ std::max(0.0, std::min(min, max)) }
29 , maxSpeed{ std::max(0.0, std::max(min, max)) }
30 , initialSpeed{initial}
31{
32 assert(min >= 0);
33 assert(max >= 0);
34 assert(min <= max);
35}
36
38 double inRate, double outRate, const Warp &options
39) : mHighQuality{ highQuality }
40{
41 double factor = (outRate / inRate);
42 if (const auto envelope = options.envelope) {
43 // variable rate resampling
44 mVariableRates = true;
45 mMinFactor = factor / envelope->GetRangeUpper();
46 mMaxFactor = factor / envelope->GetRangeLower();
47 }
48 else if (options.minSpeed > 0.0 && options.maxSpeed > 0.0) {
49 // variable rate resampling
50 mVariableRates = true;
51 mMinFactor = factor / options.maxSpeed;
52 mMaxFactor = factor / options.minSpeed;
53 }
54 else {
55 // constant rate resampling
56 mVariableRates = false;
57 mMinFactor = factor;
58 mMaxFactor = factor;
59 }
60}
61
62MixerOptions::Downmix::Downmix(unsigned numTracks, unsigned maxNumChannels)
63{
64 mNumTracks = mNumChannels = numTracks;
65 mMaxNumChannels = maxNumChannels;
66
67 if( mNumChannels > mMaxNumChannels )
68 mNumChannels = mMaxNumChannels;
69
70 Alloc();
71
72 for( unsigned int i = 0; i < mNumTracks; i++ )
73 for( unsigned int j = 0; j < mNumChannels; j++ )
74 mMap[ i ][ j ] = ( i == j );
75}
76
78{
79 mNumTracks = mixerSpec.mNumTracks;
80 mMaxNumChannels = mixerSpec.mMaxNumChannels;
81 mNumChannels = mixerSpec.mNumChannels;
82
83 Alloc();
84
85 for( unsigned int i = 0; i < mNumTracks; i++ )
86 for( unsigned int j = 0; j < mNumChannels; j++ )
87 mMap[ i ][ j ] = mixerSpec.mMap[ i ][ j ];
88}
89
90MixerOptions::Downmix::Downmix(const Downmix &mixerSpec, const std::vector<bool>& tracksMask)
91 : mMaxNumChannels(mixerSpec.mMaxNumChannels)
92 , mNumChannels(mixerSpec.mNumChannels)
93{
94 mNumTracks = static_cast<unsigned>(std::count(tracksMask.begin(), tracksMask.end(), true));
95 Alloc();
96 unsigned int dstTrackIndex = 0;
97 for( unsigned int srcTrackIndex = 0; srcTrackIndex < tracksMask.size(); srcTrackIndex++ )
98 {
99 if(!tracksMask[srcTrackIndex])
100 continue;
101
102 for( unsigned int j = 0; j < mNumChannels; j++ )
103 mMap[ dstTrackIndex ][ j ] = mixerSpec.mMap[ srcTrackIndex ][ j ] ;
104
105 ++dstTrackIndex;
106 }
107}
108
110{
111 mMap.reinit(mNumTracks, mMaxNumChannels);
112}
113
115{
116}
117
118bool MixerOptions::Downmix::SetNumChannels(unsigned newNumChannels)
119{
120 if( mNumChannels == newNumChannels )
121 return true;
122
123 if( newNumChannels > mMaxNumChannels )
124 return false;
125
126 for( unsigned int i = 0; i < mNumTracks; i++ )
127 {
128 for( unsigned int j = newNumChannels; j < mNumChannels; j++ )
129 mMap[ i ][ j ] = false;
130
131 for( unsigned int j = mNumChannels; j < newNumChannels; j++ )
132 mMap[ i ][ j ] = false;
133 }
134
135 mNumChannels = newNumChannels;
136 return true;
137}
138
140{
141 mNumTracks = mixerSpec.mNumTracks;
142 mNumChannels = mixerSpec.mNumChannels;
143 mMaxNumChannels = mixerSpec.mMaxNumChannels;
144
145 Alloc();
146
147 for( unsigned int i = 0; i < mNumTracks; i++ )
148 for( unsigned int j = 0; j < mNumChannels; j++ )
149 mMap[ i ][ j ] = mixerSpec.mMap[ i ][ j ];
150
151 return *this;
152}
int min(int a, int b)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
A matrix of booleans, one row per input channel, column per output.
Definition: MixerOptions.h:32
ArraysOf< bool > mMap
Definition: MixerOptions.h:38
bool SetNumChannels(unsigned numChannels)
Downmix(unsigned numTracks, unsigned maxNumChannels)
Downmix & operator=(const Downmix &mixerSpec)
STL namespace.
ResampleParameters(bool highQuality, double inRate, double outRate, const Warp &options)
Hook function for default time warp.
Definition: MixerOptions.h:60
Immutable structure is an argument to Mixer's constructor.
Definition: MixerOptions.h:56
const BoundedEnvelope *const envelope
Definition: MixerOptions.h:76
Warp(const AudacityProject *pProject)
Construct using the default warp function.
const double maxSpeed
Definition: MixerOptions.h:77
const double minSpeed
Definition: MixerOptions.h:77