@@ -195,6 +195,7 @@ void FileReader::setActiveRecording (int index)
195195 currentSample = 0 ;
196196 startSample = 0 ;
197197 stopSample = currentNumSamples;
198+ bufferCacheWindow = 0 ;
198199
199200 for (int i = 0 ; i < currentNumChannels; ++i)
200201 {
@@ -203,7 +204,7 @@ void FileReader::setActiveRecording (int index)
203204
204205 static_cast <FileReaderEditor*> (getEditor ())->setTotalTime (samplesToMilliseconds (currentNumSamples));
205206
206- readBuffer.malloc (currentNumChannels * BUFFER_SIZE);
207+ readBuffer.malloc (currentNumChannels * BUFFER_SIZE * BUFFER_WINDOW_CACHE_SIZE );
207208}
208209
209210
@@ -232,16 +233,18 @@ void FileReader::process (AudioSampleBuffer& buffer)
232233{
233234
234235
235- const int samplesNeeded = int (float (buffer.getNumSamples ()) * (getDefaultSampleRate () / 44100 .0f ));
236+ const int samplesNeededPerBuffer = int (float (buffer.getNumSamples ()) * (getDefaultSampleRate () / 44100 .0f ));
237+ // const int samplesNeeded = int (float (buffer.getNumSamples()) * (getDefaultSampleRate() / 44100.0f));
238+ const int samplesNeeded = samplesNeededPerBuffer * BUFFER_WINDOW_CACHE_SIZE;
236239 // FIXME: needs to account for the fact that the ratio might not be an exact
237240 // integer value
238241
239242 int samplesRead = 0 ;
240243
241- while (samplesRead < samplesNeeded)
244+ while (bufferCacheWindow == 0 && samplesRead < samplesNeeded) // only read every 5th window
242245 {
243246 int samplesToRead = samplesNeeded - samplesRead;
244- if ( (currentSample + samplesToRead) > stopSample)
247+ if ( (currentSample + samplesToRead) > stopSample) // if there are enough samples for full buffer
245248 {
246249 samplesToRead = stopSample - currentSample;
247250 if (samplesToRead > 0 )
@@ -250,7 +253,7 @@ void FileReader::process (AudioSampleBuffer& buffer)
250253 input->seekTo (startSample);
251254 currentSample = startSample;
252255 }
253- else
256+ else // if there aren't enough samples for full buffer
254257 {
255258 input->readData (readBuffer + samplesRead * currentNumChannels, samplesToRead);
256259
@@ -262,12 +265,14 @@ void FileReader::process (AudioSampleBuffer& buffer)
262265
263266 for (int i = 0 ; i < currentNumChannels; ++i)
264267 {
265- input->processChannelData (readBuffer, buffer.getWritePointer (i, 0 ), i, samplesNeeded );
268+ input->processChannelData (readBuffer + samplesRead * currentNumChannels * bufferCacheWindow , buffer.getWritePointer (i, 0 ), i, samplesNeededPerBuffer );
266269 }
267270
268271 timestamp += samplesNeeded;
269- setTimestampAndSamples (timestamp, samplesNeeded );
272+ setTimestampAndSamples (timestamp, samplesNeededPerBuffer );
270273
274+ bufferCacheWindow += 1 ;
275+ bufferCacheWindow %= BUFFER_WINDOW_CACHE_SIZE;
271276}
272277
273278
0 commit comments