[FR] AudioFormat: add overloaded createMemoryMappedReader method


#1

Could you please add the following to the AudioFormat class and the WAV and AIFF derived classes:

In juce_AudioFormat.h

virtual MemoryMappedAudioFormatReader* createMemoryMappedReader (FileInputStream* stream);

In juce_AudioFormat.cpp

MemoryMappedAudioFormatReader* AudioFormat::createMemoryMappedReader (FileInputStream* fis)
{
    ScopedPointer<FileInputStream> f (fis);
    return nullptr;
}

In juce_WavAudioFormat.h and juce_AiffAudioFormat.h

MemoryMappedAudioFormatReader* createMemoryMappedReader (FileInputStream*) override;

and in juce_WavAudioFormat.cpp

[code]MemoryMappedAudioFormatReader* WavAudioFormat::createMemoryMappedReader (FileInputStream* fis)
{
if (fis != nullptr)
{
WavAudioFormatReader reader (fis);

    if (reader.lengthInSamples > 0)
        return new MemoryMappedWavReader (fis->getFile(), reader);
    }

return nullptr;

}
[/code]

and in juce_AiffAudioFormat.cpp

MemoryMappedAudioFormatReader* AiffAudioFormat::createMemoryMappedReader (FileInputStream* fin)
{
    if (fin != nullptr)
        {
        AiffAudioFormatReader reader (fin);
        
        if (reader.lengthInSamples > 0)
            return new MemoryMappedAiffReader (fin->getFile(), reader);
        }

    return nullptr;
}

Thanks,

Rail


#2

Hi Rail,

What’s wrong with the existing createMemoryMappedReader() method? Is this to avoid creating a second FileInputStream?

Ed


#3

Kinda - I have a ‘master’ file which holds multiple audio files (and other data) and we read all the embedded files each having a different Range inside the stream… so we have a class which keeps the offset into the ‘master’ file and creates the FileInputStream and handles the position, etc in the stream.

So basically I set the offset into the stream before I call creatememoryMappedReader().

Thanks,

Rail


#4

Ok, I’ve added this to develop now.

Ed


#5

Thanks Ed.

Much appreciated!

Rail