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

Function process

lib-src/soundtouch/source/SoundStretch/main.cpp:177–225  ·  view source on GitHub ↗

Processes the sound

Source from the content-addressed store, hash-verified

175
176// Processes the sound
177static void process(SoundTouch *pSoundTouch, WavInFile *inFile, WavOutFile *outFile)
178{
179 int nSamples;
180 int nChannels;
181 int buffSizeSamples;
182 SAMPLETYPE sampleBuffer[BUFF_SIZE];
183
184 if ((inFile == NULL) || (outFile == NULL)) return; // nothing to do.
185
186 nChannels = (int)inFile->getNumChannels();
187 assert(nChannels > 0);
188 buffSizeSamples = BUFF_SIZE / nChannels;
189
190 // Process samples read from the input file
191 while (inFile->eof() == 0)
192 {
193 int num;
194
195 // Read a chunk of samples from the input file
196 num = inFile->read(sampleBuffer, BUFF_SIZE);
197 nSamples = num / (int)inFile->getNumChannels();
198
199 // Feed the samples into SoundTouch processor
200 pSoundTouch->putSamples(sampleBuffer, nSamples);
201
202 // Read ready samples from SoundTouch processor & write them output file.
203 // NOTES:
204 // - 'receiveSamples' doesn't necessarily return any samples at all
205 // during some rounds!
206 // - On the other hand, during some round 'receiveSamples' may have more
207 // ready samples than would fit into 'sampleBuffer', and for this reason
208 // the 'receiveSamples' call is iterated for as many times as it
209 // outputs samples.
210 do
211 {
212 nSamples = pSoundTouch->receiveSamples(sampleBuffer, buffSizeSamples);
213 outFile->write(sampleBuffer, nSamples * nChannels);
214 } while (nSamples != 0);
215 }
216
217 // Now the input file is processed, yet 'flush' few last samples that are
218 // hiding in the SoundTouch's internal processing pipeline.
219 pSoundTouch->flush();
220 do
221 {
222 nSamples = pSoundTouch->receiveSamples(sampleBuffer, buffSizeSamples);
223 outFile->write(sampleBuffer, nSamples * nChannels);
224 } while (nSamples != 0);
225}
226
227
228

Callers 1

mainFunction · 0.70

Calls 7

eofMethod · 0.80
getNumChannelsMethod · 0.45
readMethod · 0.45
putSamplesMethod · 0.45
receiveSamplesMethod · 0.45
writeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected