OpenShot Audio Library | OpenShotAudio: juce_AudioFormatReaderSource.cpp Source File

OpenShot Audio Library | OpenShotAudio 0.3.1

Loading...
Searching...
No Matches
juce_AudioFormatReaderSource.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
27namespace juce
28{
29
30AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const r,
31 const bool deleteReaderWhenThisIsDeleted)
32 : reader (r, deleteReaderWhenThisIsDeleted),
33 nextPlayPos (0),
34 looping (false)
35{
36 jassert (reader != nullptr);
37}
38
39AudioFormatReaderSource::~AudioFormatReaderSource() {}
40
41int64 AudioFormatReaderSource::getTotalLength() const { return reader->lengthInSamples; }
42 void AudioFormatReaderSource::setNextReadPosition (int64 newPosition) { nextPlayPos = newPosition; }
43 void AudioFormatReaderSource::setLooping (bool shouldLoop) { looping = shouldLoop; }
44
45int64 AudioFormatReaderSource::getNextReadPosition() const
46{
47 return looping ? nextPlayPos % reader->lengthInSamples
48 : nextPlayPos;
49}
50
51 void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/, double /*sampleRate*/) {}
52 void AudioFormatReaderSource::releaseResources() {}
53
54 void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
55{
56 if (info.numSamples > 0)
57 {
58 const int64 start = nextPlayPos;
59
60 if (looping)
61 {
62 const int64 newStart = start % reader->lengthInSamples;
63 const int64 newEnd = (start + info.numSamples) % reader->lengthInSamples;
64
65 if (newEnd > newStart)
66 {
67 reader->read (info.buffer, info.startSample,
68 (int) (newEnd - newStart), newStart, true, true);
69 }
70 else
71 {
72 const int endSamps = (int) (reader->lengthInSamples - newStart);
73
74 reader->read (info.buffer, info.startSample,
75 endSamps, newStart, true, true);
76
77 reader->read (info.buffer, info.startSample + endSamps,
78 (int) newEnd, 0, true, true);
79 }
80
81 nextPlayPos = newEnd;
82 }
83 else
84 {
85 reader->read (info.buffer, info.startSample,
86 info.numSamples, start, true, true);
87 nextPlayPos += info.numSamples;
88 }
89 }
90}
91
92} // namespace juce
juce::AudioFormatReaderSource::getNextReadPosition
int64 getNextReadPosition() const override
Definition: juce_AudioFormatReaderSource.cpp:45
juce::AudioFormatReaderSource::prepareToPlay
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override
Definition: juce_AudioFormatReaderSource.cpp:51
juce::AudioFormatReaderSource::releaseResources
void releaseResources() override
Definition: juce_AudioFormatReaderSource.cpp:52
juce::AudioFormatReaderSource::~AudioFormatReaderSource
~AudioFormatReaderSource() override
Definition: juce_AudioFormatReaderSource.cpp:39
juce::AudioFormatReaderSource::AudioFormatReaderSource
AudioFormatReaderSource(AudioFormatReader *sourceReader, bool deleteReaderWhenThisIsDeleted)
Definition: juce_AudioFormatReaderSource.cpp:30
juce::AudioFormatReaderSource::setLooping
void setLooping(bool shouldLoop) override
Definition: juce_AudioFormatReaderSource.cpp:43
juce::AudioFormatReaderSource::setNextReadPosition
void setNextReadPosition(int64 newPosition) override
Definition: juce_AudioFormatReaderSource.cpp:42
juce::AudioFormatReaderSource::getTotalLength
int64 getTotalLength() const override
Definition: juce_AudioFormatReaderSource.cpp:41
juce::AudioFormatReaderSource::getNextAudioBlock
void getNextAudioBlock(const AudioSourceChannelInfo &) override
Definition: juce_AudioFormatReaderSource.cpp:54
juce::AudioFormatReader
Definition: juce_AudioFormatReader.h:45
juce::AudioSourceChannelInfo
Definition: juce_AudioSource.h:33
juce::AudioSourceChannelInfo::numSamples
int numSamples
Definition: juce_AudioSource.h:81
juce::AudioSourceChannelInfo::buffer
AudioBuffer< float > * buffer
Definition: juce_AudioSource.h:73
juce::AudioSourceChannelInfo::startSample
int startSample
Definition: juce_AudioSource.h:77