JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_AudioFormatReaderSource.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
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 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
32 nextPlayPos (0),
33 looping (false)
34{
35 jassert (reader != nullptr);
36}
37
39
40int64 AudioFormatReaderSource::getTotalLength() const { return reader->lengthInSamples; }
43
45{
46 return looping ? nextPlayPos % reader->lengthInSamples
47 : nextPlayPos;
48}
49
50void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/, double /*sampleRate*/) {}
52
54{
55 if (info.numSamples > 0)
56 {
57 const int64 start = nextPlayPos;
58
59 if (looping)
60 {
61 const int64 newStart = start % reader->lengthInSamples;
62 const int64 newEnd = (start + info.numSamples) % reader->lengthInSamples;
63
64 if (newEnd > newStart)
65 {
66 reader->read (info.buffer, info.startSample,
67 (int) (newEnd - newStart), newStart, true, true);
68 }
69 else
70 {
71 const int endSamps = (int) (reader->lengthInSamples - newStart);
72
73 reader->read (info.buffer, info.startSample,
74 endSamps, newStart, true, true);
75
76 reader->read (info.buffer, info.startSample + endSamps,
77 (int) newEnd, 0, true, true);
78 }
79
80 nextPlayPos = newEnd;
81 }
82 else
83 {
84 const auto samplesToRead = jlimit (int64{},
85 (int64) info.numSamples,
86 reader->lengthInSamples - start);
87
88 reader->read (info.buffer, info.startSample, (int) samplesToRead, start, true, true);
89 info.buffer->clear ((int) (info.startSample + samplesToRead),
90 (int) (info.numSamples - samplesToRead));
91
92 nextPlayPos += info.numSamples;
93 }
94 }
95}
96
97} // namespace juce
void clear() noexcept
Clears all the samples in all channels and marks the buffer as cleared.
int64 getNextReadPosition() const override
Implements the PositionableAudioSource method.
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override
Implementation of the AudioSource method.
void releaseResources() override
Implementation of the AudioSource method.
AudioFormatReaderSource(AudioFormatReader *sourceReader, bool deleteReaderWhenThisIsDeleted)
Creates an AudioFormatReaderSource for a given reader.
void setLooping(bool shouldLoop) override
Toggles loop-mode.
void setNextReadPosition(int64 newPosition) override
Implements the PositionableAudioSource method.
int64 getTotalLength() const override
Implements the PositionableAudioSource method.
void getNextAudioBlock(const AudioSourceChannelInfo &) override
Implementation of the AudioSource method.
Reads samples from an audio file stream.
#define jassert(expression)
Platform-independent assertion macro.
typedef int
JUCE Namespace.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
long long int64
A platform-independent 64-bit integer type.
Used by AudioSource::getNextAudioBlock().
int numSamples
The number of samples in the buffer which the callback is expected to fill with data.
AudioBuffer< float > * buffer
The destination buffer to fill with audio data.
int startSample
The first sample in the buffer from which the callback is expected to write data.