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 27 of file CrossFade.cpp.

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

Definition at line 34 of file CrossFade.cpp.

35 {
36 }

Member Function Documentation

void CrossFader::ClearClips ( )

Definition at line 290 of file CrossFade.cpp.

References mClips.

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

Definition at line 60 of file CrossFade.cpp.

References mClips.

Referenced by GetSamples().

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

Definition at line 40 of file CrossFade.cpp.

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

42 {
43  switch (mType)
44  {
45  case FT_MIX:
46  return CrossFadeMix(buffer,format, start,len);
47  break;
48  case FT_TRIANGULAR:
49  return CrossFadeMix(buffer,format, start,len);
50  break;
51  case FT_EXPONENTIAL:
52  default:
53  return CrossFadeMix(buffer,format, start,len);
54  break;
55 
56  }
57 
58 }
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:60
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: