LMMS
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
30 const bool deleteReaderWhenThisIsDeleted)
31 : reader (r, deleteReaderWhenThisIsDeleted),
32 nextPlayPos (0),
34{
35 jassert (reader != nullptr);
36}
37
39
40int64 AudioFormatReaderSource::getTotalLength() const { return reader->lengthInSamples; }
42void AudioFormatReaderSource::setLooping (bool shouldLoop) { looping = shouldLoop; }
43
45{
46 return looping ? nextPlayPos % reader->lengthInSamples
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 reader->read (info.buffer, info.startSample,
85 info.numSamples, start, true, true);
86 nextPlayPos += info.numSamples;
87 }
88 }
89}
90
91} // namespace juce
Definition juce_AudioFormatReader.h:44
bool looping
Definition juce_AudioFormatReaderSource.h:96
int64 getNextReadPosition() const override
Definition juce_AudioFormatReaderSource.cpp:44
int64 nextPlayPos
Definition juce_AudioFormatReaderSource.h:95
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override
Definition juce_AudioFormatReaderSource.cpp:50
void releaseResources() override
Definition juce_AudioFormatReaderSource.cpp:51
~AudioFormatReaderSource() override
Definition juce_AudioFormatReaderSource.cpp:38
OptionalScopedPointer< AudioFormatReader > reader
Definition juce_AudioFormatReaderSource.h:93
AudioFormatReaderSource(AudioFormatReader *sourceReader, bool deleteReaderWhenThisIsDeleted)
Definition juce_AudioFormatReaderSource.cpp:29
void setLooping(bool shouldLoop) override
Definition juce_AudioFormatReaderSource.cpp:42
void setNextReadPosition(int64 newPosition) override
Definition juce_AudioFormatReaderSource.cpp:41
int64 getTotalLength() const override
Definition juce_AudioFormatReaderSource.cpp:40
void getNextAudioBlock(const AudioSourceChannelInfo &) override
Definition juce_AudioFormatReaderSource.cpp:53
virtual ASIOError start()=0
struct backing_store_struct * info
Definition jmemsys.h:183
#define jassert(expression)
Definition carla_juce.cpp:31
long long int64
Definition juce_MathsFunctions.h:54
#define false
Definition ordinals.h:83
Definition juce_AudioSource.h:33
int r
Definition crypt.c:458
typedef int(UZ_EXP MsgFn)()