2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
23 ==============================================================================
29 AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader
* const r
,
30 const bool deleteReaderWhenThisIsDeleted
)
31 : reader (r
, deleteReaderWhenThisIsDeleted
),
35 jassert (reader
!= nullptr);
38 AudioFormatReaderSource::~AudioFormatReaderSource() {}
40 int64
AudioFormatReaderSource::getTotalLength() const { return reader
->lengthInSamples
; }
41 void AudioFormatReaderSource::setNextReadPosition (int64 newPosition
) { nextPlayPos
= newPosition
; }
42 void AudioFormatReaderSource::setLooping (bool shouldLoop
) { looping
= shouldLoop
; }
44 int64
AudioFormatReaderSource::getNextReadPosition() const
46 return looping
? nextPlayPos
% reader
->lengthInSamples
50 void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/, double /*sampleRate*/) {}
51 void AudioFormatReaderSource::releaseResources() {}
53 void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo
& info
)
55 if (info
.numSamples
> 0)
57 const int64 start
= nextPlayPos
;
61 const int64 newStart
= start
% reader
->lengthInSamples
;
62 const int64 newEnd
= (start
+ info
.numSamples
) % reader
->lengthInSamples
;
64 if (newEnd
> newStart
)
66 reader
->read (info
.buffer
, info
.startSample
,
67 (int) (newEnd
- newStart
), newStart
, true, true);
71 const int endSamps
= (int) (reader
->lengthInSamples
- newStart
);
73 reader
->read (info
.buffer
, info
.startSample
,
74 endSamps
, newStart
, true, true);
76 reader
->read (info
.buffer
, info
.startSample
+ endSamps
,
77 (int) newEnd
, 0, true, true);
84 reader
->read (info
.buffer
, info
.startSample
,
85 info
.numSamples
, start
, true, true);
86 nextPlayPos
+= info
.numSamples
;