In trying to read a file backwards using a class based on AudioFormatReaderSource but when I read some files I get drop outs. Here is the getNextAudioBlock() method I modified and the rest of the class:
class ReversibleAudioFormatReaderSource: public AudioFormatReaderSource
{
public:
ReversibleAudioFormatReaderSource(AudioFormatReader* sourceReader, bool deleteReaderWhenThisIsDeleted)
:AudioFormatReaderSource (sourceReader, deleteReaderWhenThisIsDeleted)
{
reader. setNonOwned(sourceReader);
}
void getNextAudioBlock (const AudioSourceChannelInfo& info) override
{
if (info.numSamples > 0)
{
blockSize= info.numSamples;
if(reversed)
{
const int64 start = nextPlayPos;
reader->read (info.buffer, info.startSample,
info.numSamples, start, true, true);
info.buffer->reverse(info.startSample, info.numSamples);
nextPlayPos-=info.numSamples;
}
else
{
const int64 start = nextPlayPos;
reader->read (info.buffer, info.startSample,
info.numSamples, start, true, true);
nextPlayPos += info.numSamples;
}
}
}
void reverse()
{
if(reversed)
reversed=false;
else
{
nextPlayPos-=blockSize;
reversed=true;
}
}
private:
//==============================================================================
OptionalScopedPointer<AudioFormatReader> reader;
int64 volatile nextPlayPos=0;
bool volatile reversed=false;
int64 blockSize;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ReversibleAudioFormatReaderSource)
};
Here is my github repo, with some files to illustrate this issue.
Why are these drop outs happening, are there mutexes on the AudioFormatReader?. Is there any solution for this?
Thanks for your help.