MCPcopy Create free account
hub / github.com/audacity/audacity / ProcessStereo

Method ProcessStereo

libraries/lib-builtin-effects/SoundTouchBase.cpp:247–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245}
246
247bool SoundTouchBase::ProcessStereo(soundtouch::SoundTouch *pSoundTouch,
248 WaveTrack &orig, WaveTrack &outputTrack,
249 sampleCount start, sampleCount end, const TimeWarper &warper)
250{
251 pSoundTouch->setSampleRate(
252 static_cast<unsigned int>(orig.GetRate() + 0.5));
253
254 auto channels = orig.Channels();
255 auto &leftTrack = **channels.first++;
256 auto &rightTrack = **channels.first;
257
258 auto newChannels = outputTrack.Channels();
259 auto &outputLeftTrack = **newChannels.first++;
260 auto &outputRightTrack = **newChannels.first;
261
262 //Get the length of the buffer (as double). len is
263 //used simple to calculate a progress meter, so it is easier
264 //to make it a double now than it is to do it later
265 double len = (end - start).as_double();
266
267 //Initiate a processing buffer. This buffer will (most likely)
268 //be shorter than the length of the track being processed.
269 // Make soundTouchBuffer twice as big as MaxBlockSize for each channel,
270 // because Soundtouch wants them interleaved, i.e., each
271 // Soundtouch sample is left-right pair.
272 auto maxBlockSize = orig.GetMaxBlockSize();
273 {
274 Floats leftBuffer{ maxBlockSize };
275 Floats rightBuffer{ maxBlockSize };
276 Floats soundTouchBuffer{ maxBlockSize * 2 };
277
278 // Go through the track one stereo buffer at a time.
279 // sourceSampleCount counts the sample at which the current buffer starts,
280 // per channel.
281 auto sourceSampleCount = start;
282 while (sourceSampleCount < end) {
283 auto blockSize = limitSampleBufferSize(
284 orig.GetBestBlockSize(sourceSampleCount),
285 end - sourceSampleCount
286 );
287
288 // Get the samples from the tracks and put them in the buffers.
289 leftTrack.GetFloats((leftBuffer.get()), sourceSampleCount, blockSize);
290 rightTrack
291 .GetFloats((rightBuffer.get()), sourceSampleCount, blockSize);
292
293 // Interleave into soundTouchBuffer.
294 for (decltype(blockSize) index = 0; index < blockSize; index++) {
295 soundTouchBuffer[index * 2] = leftBuffer[index];
296 soundTouchBuffer[(index * 2) + 1] = rightBuffer[index];
297 }
298
299 //Add samples to SoundTouch
300 pSoundTouch->putSamples(soundTouchBuffer.get(), blockSize);
301
302 //Get back samples from SoundTouch
303 unsigned int outputCount = pSoundTouch->numSamples();
304 if (outputCount > 0)

Callers

nothing calls this directly

Calls 15

ProcessStereoResultsMethod · 0.95
limitSampleBufferSizeFunction · 0.85
maxFunction · 0.85
ChannelsMethod · 0.80
setSampleRateMethod · 0.45
GetRateMethod · 0.45
GetMaxBlockSizeMethod · 0.45
GetBestBlockSizeMethod · 0.45
GetFloatsMethod · 0.45
getMethod · 0.45
putSamplesMethod · 0.45
numSamplesMethod · 0.45

Tested by

no test coverage detected