openshot-audio  0.1.6
juce_MemoryMappedAudioFormatReader.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_MEMORYMAPPEDAUDIOFORMATREADER_H_INCLUDED
26 #define JUCE_MEMORYMAPPEDAUDIOFORMATREADER_H_INCLUDED
27 
28 
29 //==============================================================================
45 {
46 protected:
47  //==============================================================================
54  MemoryMappedAudioFormatReader (const File& file, const AudioFormatReader& details,
55  int64 dataChunkStart, int64 dataChunkLength, int bytesPerFrame);
56 
57 public:
59  const File& getFile() const noexcept { return file; }
60 
62  bool mapEntireFile();
63 
65  bool mapSectionOfFile (Range<int64> samplesToMap);
66 
68  Range<int64> getMappedSection() const noexcept { return mappedSection; }
69 
71  void touchSample (int64 sample) const noexcept;
72 
77  virtual void getSample (int64 sampleIndex, float* result) const noexcept = 0;
78 
80  size_t getNumBytesUsed() const { return map != nullptr ? map->getSize() : 0; }
81 
82 protected:
86  int64 dataChunkStart, dataLength;
88 
90  inline int64 sampleToFilePos (int64 sample) const noexcept { return dataChunkStart + sample * bytesPerFrame; }
91 
93  inline int64 filePosToSample (int64 filePos) const noexcept { return (filePos - dataChunkStart) / bytesPerFrame; }
94 
96  inline const void* sampleToPointer (int64 sample) const noexcept { return addBytesToPointer (map->getData(), sampleToFilePos (sample) - map->getRange().getStart()); }
97 
99  template <typename SampleType, typename Endianness>
100  Range<float> scanMinAndMaxInterleaved (int channel, int64 startSampleInFile, int64 numSamples) const noexcept
101  {
103 
104  return SourceType (addBytesToPointer (sampleToPointer (startSampleInFile), ((int) bitsPerSample / 8) * channel), (int) numChannels)
105  .findMinAndMax ((size_t) numSamples);
106  }
107 
109 };
110 
111 
112 #endif // JUCE_MEMORYMAPPEDAUDIOFORMATREADER_H_INCLUDED
Definition: juce_MemoryMappedAudioFormatReader.h:44
#define noexcept
Definition: juce_CompilerSupport.h:141
const int bytesPerFrame
Definition: juce_win32_AudioCDReader.cpp:956
Definition: juce_AudioDataConverters.h:355
const File & getFile() const noexcept
Definition: juce_MemoryMappedAudioFormatReader.h:59
void * getData() const noexcept
Definition: juce_MemoryMappedFile.h:88
Type * addBytesToPointer(Type *basePointer, IntegerType bytes) noexcept
Definition: juce_Memory.h:53
#define JUCE_API
Definition: juce_StandardHeader.h:139
Range< int64 > getMappedSection() const noexcept
Definition: juce_MemoryMappedAudioFormatReader.h:68
#define const
File file
Definition: juce_MemoryMappedAudioFormatReader.h:83
int64 sampleToFilePos(int64 sample) const noexcept
Definition: juce_MemoryMappedAudioFormatReader.h:90
Definition: juce_AudioFormatReader.h:38
Range< float > scanMinAndMaxInterleaved(int channel, int64 startSampleInFile, int64 numSamples) const noexcept
Definition: juce_MemoryMappedAudioFormatReader.h:100
int bytesPerFrame
Definition: juce_MemoryMappedAudioFormatReader.h:87
int64 filePosToSample(int64 filePos) const noexcept
Definition: juce_MemoryMappedAudioFormatReader.h:93
long long int64
Definition: juce_MathsFunctions.h:60
const void * sampleToPointer(int64 sample) const noexcept
Definition: juce_MemoryMappedAudioFormatReader.h:96
Range< int64 > mappedSection
Definition: juce_MemoryMappedAudioFormatReader.h:84
Range< float > findMinAndMax(size_t numSamples) const noexcept
Definition: juce_AudioDataConverters.h:490
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
size_t getNumBytesUsed() const
Definition: juce_MemoryMappedAudioFormatReader.h:80
ScopedPointer< MemoryMappedFile > map
Definition: juce_MemoryMappedAudioFormatReader.h:85
ValueType getStart() const noexcept
Definition: juce_Range.h:95
Definition: juce_File.h:45
int64 dataLength
Definition: juce_MemoryMappedAudioFormatReader.h:86
Range< int64 > getRange() const noexcept
Definition: juce_MemoryMappedFile.h:96