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#include "SampleTrack.h"
18
20: envelope(DefaultWarp::Call(list)), minSpeed(0.0), maxSpeed(0.0)
21{
22}
23
25 : envelope(e), minSpeed(0.0), maxSpeed(0.0)
26 {}
27
28MixerOptions::Warp::Warp(double min, double max, double initial)
29 : minSpeed{ std::max(0.0, std::min(min, max)) }
30 , maxSpeed{ std::max(0.0, std::max(min, max)) }
31 , initialSpeed{initial}
32{
33 assert(min >= 0);
34 assert(max >= 0);
35 assert(min <= max);
36}
37
39 const SampleTrack &leader, double rate, const Warp &options
40) : mHighQuality{ highQuality }
41{
42 auto range = TrackList::Channels<const SampleTrack>(&leader);
43 auto size = range.size();
44 mMinFactor.reserve(size);
45 mMaxFactor.reserve(size);
46 for (auto pTrack : range) {
47 double factor = (rate / pTrack->GetRate());
48 if (const auto envelope = options.envelope) {
49 // variable rate resampling
50 mVariableRates = true;
51 mMinFactor.push_back(factor / envelope->GetRangeUpper());
52 mMaxFactor.push_back(factor / envelope->GetRangeLower());
53 }
54 else if (options.minSpeed > 0.0 && options.maxSpeed > 0.0) {
55 // variable rate resampling
56 mVariableRates = true;
57 mMinFactor.push_back(factor / options.maxSpeed);
58 mMaxFactor.push_back(factor / options.minSpeed);
59 }
60 else {
61 // constant rate resampling
62 mVariableRates = false;
63 mMinFactor.push_back(factor);
64 mMaxFactor.push_back(factor);
65 }
66 }
67}
68
69MixerOptions::Downmix::Downmix(unsigned numTracks, unsigned maxNumChannels)
70{
71 mNumTracks = mNumChannels = numTracks;
72 mMaxNumChannels = maxNumChannels;
73
74 if( mNumChannels > mMaxNumChannels )
75 mNumChannels = mMaxNumChannels;
76
77 Alloc();
78
79 for( unsigned int i = 0; i < mNumTracks; i++ )
80 for( unsigned int j = 0; j < mNumChannels; j++ )
81 mMap[ i ][ j ] = ( i == j );
82}
83
85{
86 mNumTracks = mixerSpec.mNumTracks;
87 mMaxNumChannels = mixerSpec.mMaxNumChannels;
88 mNumChannels = mixerSpec.mNumChannels;
89
90 Alloc();
91
92 for( unsigned int i = 0; i < mNumTracks; i++ )
93 for( unsigned int j = 0; j < mNumChannels; j++ )
94 mMap[ i ][ j ] = mixerSpec.mMap[ i ][ j ];
95}
96
98{
99 mMap.reinit(mNumTracks, mMaxNumChannels);
100}
101
103{
104}
105
106bool MixerOptions::Downmix::SetNumChannels(unsigned newNumChannels)
107{
108 if( mNumChannels == newNumChannels )
109 return true;
110
111 if( newNumChannels > mMaxNumChannels )
112 return false;
113
114 for( unsigned int i = 0; i < mNumTracks; i++ )
115 {
116 for( unsigned int j = newNumChannels; j < mNumChannels; j++ )
117 mMap[ i ][ j ] = false;
118
119 for( unsigned int j = mNumChannels; j < newNumChannels; j++ )
120 mMap[ i ][ j ] = false;
121 }
122
123 mNumChannels = newNumChannels;
124 return true;
125}
126
128{
129 mNumTracks = mixerSpec.mNumTracks;
130 mNumChannels = mixerSpec.mNumChannels;
131 mMaxNumChannels = mixerSpec.mMaxNumChannels;
132
133 Alloc();
134
135 for( unsigned int i = 0; i < mNumTracks; i++ )
136 for( unsigned int j = 0; j < mNumChannels; j++ )
137 mMap[ i ][ j ] = mixerSpec.mMap[ i ][ j ];
138
139 return *this;
140}
int min(int a, int b)
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)
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1338
STL namespace.
std::vector< double > mMaxFactor
Definition: MixerOptions.h:85
ResampleParameters(bool highQuality, const SampleTrack &leader, double rate, const Warp &options)
std::vector< double > mMinFactor
Definition: MixerOptions.h:85
Hook function for default time warp.
Definition: MixerOptions.h:58
Immutable structure is an argument to Mixer's constructor.
Definition: MixerOptions.h:54
const BoundedEnvelope *const envelope
Definition: MixerOptions.h:74
const double maxSpeed
Definition: MixerOptions.h:75
const double minSpeed
Definition: MixerOptions.h:75
Warp(const TrackList &list)
Construct using the default warp function.