Audacity  2.2.2
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
CrossFader Class Reference

Not used by Audacity (yet) apparently work in progress that has been abandoned. More...

#include <CrossFade.h>

Public Member Functions

 CrossFader ()
 
 ~CrossFader ()
 
void SetMixCrossFade ()
 
void SetTriangularCrossFade ()
 
void SetExponentialCrossFade ()
 
void ClearClips ()
 
bool GetSamples (samplePtr buffer, sampleFormat format, sampleCount start, size_t len)
 

Protected Attributes

WaveClipHolders mClips
 

Private Member Functions

bool CrossFadeMix (samplePtr buffer, sampleFormat format, sampleCount start, size_t len)
 

Private Attributes

FadeType mType
 

Detailed Description

Not used by Audacity (yet) apparently work in progress that has been abandoned.

Definition at line 29 of file CrossFade.h.

Constructor & Destructor Documentation

CrossFader::CrossFader ( )

Definition at line 29 of file CrossFade.cpp.

29  :
30  mType(FT_MIX)
31 {
32 }
FadeType mType
Definition: CrossFade.h:54
CrossFader::~CrossFader ( )

Definition at line 36 of file CrossFade.cpp.

37 {
38 }

Member Function Documentation

void CrossFader::ClearClips ( )

Definition at line 292 of file CrossFade.cpp.

References mClips.

293 {
294  mClips.clear();
295 }
WaveClipHolders mClips
Definition: CrossFade.h:48
bool CrossFader::CrossFadeMix ( samplePtr  buffer,
sampleFormat  format,
sampleCount  start,
size_t  len 
)
private

Definition at line 62 of file CrossFade.cpp.

References sampleCount::as_long_long(), floatSample, int16Sample, int24Sample, and mClips.

Referenced by GetSamples().

63 {
64 
65  std::cout << "Crossfading from " << start.as_long_long()
66  << " to " << ( len + start ).as_long_long()
67  << std::endl;
68 
69  // start refers to the position in the wave.
70 
71 
72  //just mix the right things together.
73 
74 
75  //For each relevant clip, we need to construct a buffer.
76  //we should use one of the size len, because this has already
77  //been determined to be good in Mixer
78 
79  //Go through each clip, adding it to the total in the appropriate way.
80 
81  //this could be 'optimized' by getting all of the sequences and then
82  //iterating through each of them.
83 
84  int numclips = mClips.size();
85 
86  //create vectors to store the important info for each clip.
87  std::vector<sampleCount> clipStart(numclips);
88  std::vector<sampleCount> clipLength(numclips);
89  std::vector<Sequence*> tmpSequence(numclips);
90 
91 
92  unsigned int i = 0;
93  //Now, go through the clips and load up the vectors.
94  for(const auto &tmpclip: mClips)
95  {
96  tmpSequence[i] = tmpclip->GetSequence();
97 
98 
99  //start is the position of the beginning of the buffer
100  //relative to the beginning of the clip. It could be negative.
101  clipStart[i]= start - tmpclip->GetStartSample();
102 
103 
104 
105  //determine the index of the last sample to get, relative to the start of the clip
106 
107  //it will be no longer than the clip itself.
108  clipLength[i] = tmpclip->GetNumSamples()-clipStart[i];
109 
110  std::cout << "X:" << " "
111  << clipLength[i].as_long_long()
112  << " "
113  << tmpclip->GetStartSample().as_long_long()
114  << " ";
115  //if the buffer ends before the clip does, adjust the length
116  if(clipStart[i] + len < clipLength[i])
117  {
118  clipLength[i] = len + clipStart[i];
119  }
120  std::cout
121  << clipStart[i].as_long_long()
122  << " "
123  << clipLength[i].as_long_long()
124  << " "
125  << ( clipLength[i] - clipStart[i] ).as_long_long()
126  << std::endl;
127  }
128  std::cout << "-------------\n";
129 
130  //Now, determine the sample format:
131  switch(format) {
132  case int16Sample:
133  {
134  std::cout << "int\n";
135  short *dest = (short *)buffer;
136  vector<short*> shortSeq;
137 
138  //Copy the sequences over to the NEW vector, casting as you go.
139  for(int i = 0; i < numclips; i++)
140  // PRL: what the ... ? This cast is just wrong!
141  shortSeq.push_back((short*)tmpSequence[i]);
142 
143 
144  int clips;
145  double f;
146  //now, shortSeq contains the samples to mix together.
147  for (int j = 0; j < (int)len; j++)
148  {
149 
150  //Go through each clip
151  for(int i = 0; i < numclips; i++)
152  {
153  clips = 0;
154  f = 0;
155  if(j + clipStart[i] >= 0 &&
156  clipStart[i]+len < clipLength[i])//only copy if we are within the clip
157  {
158  // UNSAFE_SAMPLE_COUNT_TRUNCATION
159  // -- but class CrossFader is not used as of this writing
160  f += shortSeq[ i ][ j+ clipStart[i].as_long_long() ];
161  clips++;
162  }
163 
164  f/= clips;
165 
166  //Do bounds-checking
167  if (f > 32767)
168  f = 32767;
169  if (f < -32768)
170  f = -32768;
171 
172  //Set value
173  *dest = (short)f;
174  }
175  dest++;
176  }
177  }
178  break;
179 
180 
181  case int24Sample:
182  {
183  std::cout << "int24\n";
184  int *dest = (int *)buffer;
185  vector<int *> intSeq;
186 
187 
188  //Copy the sequences over to the NEW vector, casting as you go.
189  for(int i = 0; i < numclips; i++)
190  // Murder most foul! As in the best it is,
191  // But this most foul, strange, and unnatural.
192  intSeq.push_back((int*)tmpSequence[i]);
193 
194  int clips=0;
195  double f;
196  //Go through each sample position
197  for (int j = 0; j < (int)len; j++) {
198 
199  //go through each clip.
200  for(int i= 0; i < numclips; i++)
201  {
202  clips = 0;
203  f = 0;
204 
205  //only copy if we are within the clip
206  if(j + clipStart[i] >= 0 && clipStart[i] + len < clipLength[i])
207  {
208  // UNSAFE_SAMPLE_COUNT_TRUNCATION
209  // -- but class CrossFader is not used as of this writing
210  f+= intSeq[ i ][ j + clipStart[ i ].as_long_long() ];
211  clips++;
212  }
213 
214  f /= clips;
215 
216  if (f > 8388607)
217  f = 8388607;
218  if (f < -8388608)
219  f = -8388608;
220  *dest = (int)f;
221 
222  }
223  dest ++;
224  }
225  }
226  break;
227 
228 
229  case floatSample: {
230  std::cout << "float\n";
231  float *dest = (float *)buffer;
232  vector<float*> floatSeq;
233 
234  int clips = 0;
235  float f;
236 
237  //go through each sample position
238  for (int j = 0; j < (int)len; j++) {
239 
240 
241  clips = 0;
242  f = 0;
243 
244  for(int i = 0; i < numclips; i++)
245  {
246 
247  cout << numclips << " " ;
248 
249  cout <<f << " " ;
250 
251  if(j + clipStart[i] >= 0 &&
252  clipStart[i] + j < clipLength[i])//only copy if we are within the clip
253  {
254  // UNSAFE_SAMPLE_COUNT_TRUNCATION
255  // -- but class CrossFader is not used as of this writing
256  // -- hey wait, you never even tried to initialize floatSeq,
257  // not even with bad casts!!!
258  // Subscripts out of bounds, bombs away!!!
259  f += floatSeq[ i ][ ( j + clipStart[ i ] ).as_long_long() ];
260  clips++;
261  }
262  cout << f << " "<< i << " "
263  << floatSeq[ i ][ j + clipStart[ i ].as_long_long() ] << "|";
264  }
265  if(clips == 0)
266  *dest = 0.0f;
267  else
268  {
269 
270  f /= clips;
271  cout << f << "--";
272  // MM: XXX Should probably go outside the loop
273  if (f > 1.0f)
274  *dest = 1.0f;
275  else if (f < -1.0f)
276  *dest = -1.0f;
277  else
278  *dest = (float)f;
279 
280  }
281  cout << *dest << endl;
282  dest++;
283  }
284  } break;
285  } // switch
286 
287 
288  return true;
289 }
WaveClipHolders mClips
Definition: CrossFade.h:48
int format
Definition: ExportPCM.cpp:56
long long as_long_long() const
Definition: Types.h:89
bool CrossFader::GetSamples ( samplePtr  buffer,
sampleFormat  format,
sampleCount  start,
size_t  len 
)

Definition at line 42 of file CrossFade.cpp.

References CrossFadeMix(), FT_EXPONENTIAL, FT_MIX, FT_TRIANGULAR, and mType.

44 {
45  switch (mType)
46  {
47  case FT_MIX:
48  return CrossFadeMix(buffer,format, start,len);
49  break;
50  case FT_TRIANGULAR:
51  return CrossFadeMix(buffer,format, start,len);
52  break;
53  case FT_EXPONENTIAL:
54  default:
55  return CrossFadeMix(buffer,format, start,len);
56  break;
57 
58  }
59 
60 }
FadeType mType
Definition: CrossFade.h:54
int format
Definition: ExportPCM.cpp:56
bool CrossFadeMix(samplePtr buffer, sampleFormat format, sampleCount start, size_t len)
Definition: CrossFade.cpp:62
void CrossFader::SetExponentialCrossFade ( )
inline

Definition at line 40 of file CrossFade.h.

References FT_EXPONENTIAL, and mType.

FadeType mType
Definition: CrossFade.h:54
void CrossFader::SetMixCrossFade ( )
inline

Definition at line 38 of file CrossFade.h.

References FT_MIX, and mType.

38 {mType = FT_MIX;};
FadeType mType
Definition: CrossFade.h:54
void CrossFader::SetTriangularCrossFade ( )
inline

Definition at line 39 of file CrossFade.h.

References FT_TRIANGULAR, and mType.

39 {mType = FT_TRIANGULAR;};
FadeType mType
Definition: CrossFade.h:54

Member Data Documentation

WaveClipHolders CrossFader::mClips
protected

Definition at line 48 of file CrossFade.h.

Referenced by ClearClips(), and CrossFadeMix().

FadeType CrossFader::mType
private

The documentation for this class was generated from the following files: