# New class: MemoryMappedAudioFormatReader

**URL:** <https://forum.juce.com/t/new-class-memorymappedaudioformatreader/9995>\
**Category:** General JUCE discussion\
**Created:** [February 18, 2013, 10:07pm UTC](https://forum.juce.com/t/new-class-memorymappedaudioformatreader/9995 "2013-02-18T22:07:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [February 18, 2013, 10:07pm UTC](https://forum.juce.com/t/new-class-memorymappedaudioformatreader/9995/1 "2013-02-18T22:07:07Z")

</div>

As a spin-off from some work I’m doing on tracktion, I’ve just added a new class MemoryMappedAudioFormatReader.

This allows some audio formats (WAV and AIFF only) to create special AudioFormatReaders that pull their data directly from disk via virtual memory-mapping. That means you can read from them with incredible speed and efficiently, as long as you define the region you want to access beforehand.

Hope this is useful to some of you, and since it’s very new and experimental, I’d love to get any feedback/bug reports about it!

---

<div class="post-metadata">

**Author:** ![lucem](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@lucem](https://forum.juce.com/u/lucem)\
**Post date:** [February 19, 2013, 10:20am UTC](https://forum.juce.com/t/new-class-memorymappedaudioformatreader/9995/2 "2013-02-19T10:20:51Z")

</div>

Nice! I’ll be sure to give it a test run.  
Could come in very handy for samplers, as well.

---

<div class="post-metadata">

**Author:** ![OBO](https://avatars.discourse-cdn.com/v4/letter/o/ba8739/32.png) [@OBO](https://forum.juce.com/u/OBO)\
**Post date:** [February 19, 2013, 1:44pm UTC](https://forum.juce.com/t/new-class-memorymappedaudioformatreader/9995/3 "2013-02-19T13:44:05Z")

</div>

Is there any advantage of this over loading an audio file into a MemoryBlock and read samples from there?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [February 19, 2013, 3:16pm UTC](https://forum.juce.com/t/new-class-memorymappedaudioformatreader/9995/4 "2013-02-19T15:16:49Z")

</div>

> [@OBO](#):
>
> Is there any advantage of this over loading an audio file into a MemoryBlock and read samples from there?

Yes, it’ll be better unless the files are very small.

---

<div class="post-metadata">

**Author:** ![chrisboy2000](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@chrisboy2000](https://forum.juce.com/u/chrisboy2000)\
**Post date:** [September 9, 2013, 1:23pm UTC](https://forum.juce.com/t/new-class-memorymappedaudioformatreader/9995/5 "2013-09-09T13:23:07Z")

</div>

Hi Jules,

&nbsp;

First post, so thank you for this amazing library :)

I am fiddeling around with this class and it's pretty hard for a noob like me without any demonstration code or a more detailed documentation.&nbsp;

Basically I am trying to achieve DFD streaming for a sampler. I got it&nbsp;working by replacing the AudioFormatReader "&source"&nbsp;in the SamplerSound constructor with&nbsp;a MemoryMappedAudioFormatReader. But if I map the entire file via

```
source.mapEntireFile();
```

It loads everything into memory. Most likely I don't understand the point, but how can I do real disk streaming? Is it possible to only map the section that is read by&nbsp;renderNextBlock()?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 9, 2013, 3:23pm UTC](https://forum.juce.com/t/new-class-memorymappedaudioformatreader/9995/6 "2013-09-09T15:23:00Z")

</div>

Sounds like you don't quite understand how a&nbsp;memory mapped file works.. A bit of googling&nbsp;can probably help you out there!

---

<div class="post-metadata">

**Author:** ![rmcgill](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rmcgill/32/180_2.png) [@rmcgill](https://forum.juce.com/u/rmcgill)\
**Post date:** [February 16, 2015, 11:15pm UTC](https://forum.juce.com/t/new-class-memorymappedaudioformatreader/9995/7 "2015-02-16T23:15:33Z")

</div>

I also have the same question as Chrisboy2000, unfortunately my googling hasn't helped me find the answer. I am trying to implement the **MemoryMappedAudioFormatReader** on a bunch of samples I am using for a keyboard/sampler app. &nbsp;But using **mapEntireFile()** puts the whole file into memory&nbsp;and when I max out the machines memory, the OS kills the app.

Can you please provide a brief description of what concepts I'm missing? Or a direction to a source that will explain this to&nbsp;me?

&nbsp;

Thank you for the Class and Juce!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [February 17, 2015, 8:55am UTC](https://forum.juce.com/t/new-class-memorymappedaudioformatreader/9995/8 "2015-02-17T08:55:27Z")

</div>

If you're running in 32 bits then you'd need to make judicious use of the&nbsp;mapSectionOfFile() method instead of mapping the whole thing.

---

<div class="post-metadata">

**Author:** ![rmcgill](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rmcgill/32/180_2.png) [@rmcgill](https://forum.juce.com/u/rmcgill)\
**Post date:** [March 25, 2015, 6:55am UTC](https://forum.juce.com/t/new-class-memorymappedaudioformatreader/9995/9 "2015-03-25T06:55:51Z")

</div>

My WAV audio sampler project successfully maps entire audio file (my sample set)&nbsp;after creating memorymappedaudioformatreader(). I am trying to implement this new reader into the synthesiser class based on the Juce demo. What is the correct method for implementing this reader?

Ive worked on this a lot but I'm stumped, pseudo code would be greatly appreciated!
