OpenShot Library | libopenshot-audio  0.2.0
juce_AudioSubsectionReader.cpp
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2017 - ROLI Ltd.
6 
7  JUCE is an open source library subject to commercial or open-source
8  licensing.
9 
10  By using JUCE, you agree to the terms of both the JUCE 5 End-User License
11  Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
12  27th April 2017).
13 
14  End User License Agreement: www.juce.com/juce-5-licence
15  Privacy Policy: www.juce.com/juce-5-privacy-policy
16 
17  Or: You may also use this code under the terms of the GPL v3 (see
18  www.gnu.org/licenses).
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
31  int64 startSampleToUse, int64 lengthToUse,
32  bool deleteSource)
33  : AudioFormatReader (nullptr, sourceToUse->getFormatName()),
34  source (sourceToUse),
35  startSample (startSampleToUse),
36  deleteSourceWhenDeleted (deleteSource)
37 {
38  length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), lengthToUse);
39 
40  sampleRate = source->sampleRate;
41  bitsPerSample = source->bitsPerSample;
42  lengthInSamples = length;
43  numChannels = source->numChannels;
45 }
46 
48 {
49  if (deleteSourceWhenDeleted)
50  delete source;
51 }
52 
53 //==============================================================================
54 bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
55  int64 startSampleInFile, int numSamples)
56 {
57  clearSamplesBeyondAvailableLength (destSamples, numDestChannels, startOffsetInDestBuffer,
58  startSampleInFile, numSamples, length);
59 
60  return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
61  startSampleInFile + startSample, numSamples);
62 }
63 
64 void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile, int64 numSamples, Range<float>* results, int numChannelsToRead)
65 {
66  startSampleInFile = jmax ((int64) 0, startSampleInFile);
67  numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
68 
69  source->readMaxLevels (startSampleInFile + startSample, numSamples, results, numChannelsToRead);
70 }
71 
72 } // namespace juce
juce::AudioSubsectionReader::readSamples
bool readSamples(int **destSamples, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int numSamples) override
Subclasses must implement this method to perform the low-level read operation.
Definition: juce_AudioSubsectionReader.cpp:54
juce::AudioFormatReader::sampleRate
double sampleRate
The sample-rate of the stream.
Definition: juce_AudioFormatReader.h:226
juce::AudioFormatReader::clearSamplesBeyondAvailableLength
static void clearSamplesBeyondAvailableLength(int **destChannels, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int &numSamples, int64 fileLengthInSamples)
Used by AudioFormatReader subclasses to clear any parts of the data blocks that lie beyond the end of...
Definition: juce_AudioFormatReader.h:310
juce::AudioFormatReader::lengthInSamples
int64 lengthInSamples
The total number of samples in the audio stream.
Definition: juce_AudioFormatReader.h:232
juce::AudioFormatReader::readMaxLevels
virtual void readMaxLevels(int64 startSample, int64 numSamples, Range< float > *results, int numChannelsToRead)
Finds the highest and lowest sample levels from a section of the audio stream.
Definition: juce_AudioFormatReader.cpp:198
juce::AudioSubsectionReader::~AudioSubsectionReader
~AudioSubsectionReader() override
Destructor.
Definition: juce_AudioSubsectionReader.cpp:47
juce::AudioFormatReader::bitsPerSample
unsigned int bitsPerSample
The number of bits per sample, e.g.
Definition: juce_AudioFormatReader.h:229
juce::Range
A general-purpose range object, that simply represents any linear range with a start and end point.
Definition: juce_Range.h:43
juce::AudioFormatReader::numChannels
unsigned int numChannels
The total number of channels in the audio stream.
Definition: juce_AudioFormatReader.h:235
juce::AudioSubsectionReader::readMaxLevels
void readMaxLevels(int64 startSample, int64 numSamples, Range< float > *results, int numChannelsToRead) override
Finds the highest and lowest sample levels from a section of the audio stream.
Definition: juce_AudioSubsectionReader.cpp:64
juce::AudioSubsectionReader::AudioSubsectionReader
AudioSubsectionReader(AudioFormatReader *sourceReader, int64 subsectionStartSample, int64 subsectionLength, bool deleteSourceWhenDeleted)
Creates an AudioSubsectionReader for a given data source.
Definition: juce_AudioSubsectionReader.cpp:30
juce::AudioFormatReader::readSamples
virtual bool readSamples(int **destChannels, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int numSamples)=0
Subclasses must implement this method to perform the low-level read operation.
juce::AudioFormatReader::usesFloatingPointData
bool usesFloatingPointData
Indicates whether the data is floating-point or fixed.
Definition: juce_AudioFormatReader.h:238
juce::AudioFormatReader
Reads samples from an audio file stream.
Definition: juce_AudioFormatReader.h:48