OpenShot Audio Library | OpenShotAudio 0.3.2

Loading...
Searching...
No Matches
juce_MemoryAudioSource.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 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23 namespace juce
24{
25
26 MemoryAudioSource::MemoryAudioSource (AudioBuffer<float>& bufferToUse, bool copyMemory, bool shouldLoop)
27 : isLooping (shouldLoop)
28{
29 if (copyMemory)
30 buffer.makeCopyOf (bufferToUse);
31 else
32 buffer.setDataToReferTo (bufferToUse.getArrayOfWritePointers(),
33 bufferToUse.getNumChannels(),
34 bufferToUse.getNumSamples());
35}
36
37//==============================================================================
38 void MemoryAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/, double /*sampleRate*/)
39{
40 position = 0;
41}
42
43 void MemoryAudioSource::releaseResources() {}
44
45 void MemoryAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
46{
47 auto& dst = *bufferToFill.buffer;
48 auto channels = jmin (dst.getNumChannels(), buffer.getNumChannels());
49 auto max = 0, pos = 0;
50 auto n = buffer.getNumSamples(), m = bufferToFill.numSamples;
51
52 int i;
53 for (i = position; (i < n || isLooping) && (pos < m); i += max)
54 {
55 max = jmin (m - pos, n - (i % n));
56
57 int ch = 0;
58 for (; ch < channels; ++ch)
59 dst.copyFrom (ch, bufferToFill.startSample + pos, buffer, ch, i % n, max);
60
61 for (; ch < dst.getNumChannels(); ++ch)
62 dst.clear (ch, bufferToFill.startSample + pos, max);
63
64 pos += max;
65 }
66
67 if (pos < m)
68 dst.clear (bufferToFill.startSample + pos, m - pos);
69
70 position = (i % n);
71}
72
73} // namespace juce
juce::AudioBuffer
Definition: juce_AudioSampleBuffer.h:34
juce::AudioBuffer::makeCopyOf
void makeCopyOf(const AudioBuffer< OtherType > &other, bool avoidReallocating=false)
Definition: juce_AudioSampleBuffer.h:481
juce::AudioBuffer::getNumChannels
int getNumChannels() const noexcept
Definition: juce_AudioSampleBuffer.h:233
juce::AudioBuffer::getNumSamples
int getNumSamples() const noexcept
Definition: juce_AudioSampleBuffer.h:238
juce::AudioBuffer::setDataToReferTo
void setDataToReferTo(Type **dataToReferTo, int newNumChannels, int newStartSample, int newNumSamples)
Definition: juce_AudioSampleBuffer.h:430
juce::AudioBuffer::getArrayOfWritePointers
Type ** getArrayOfWritePointers() noexcept
Definition: juce_AudioSampleBuffer.h:306
juce::MemoryAudioSource::MemoryAudioSource
MemoryAudioSource(AudioBuffer< float > &audioBuffer, bool copyMemory, bool shouldLoop=false)
Definition: juce_MemoryAudioSource.cpp:26
juce::MemoryAudioSource::prepareToPlay
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override
Definition: juce_MemoryAudioSource.cpp:38
juce::MemoryAudioSource::getNextAudioBlock
void getNextAudioBlock(const AudioSourceChannelInfo &bufferToFill) override
Definition: juce_MemoryAudioSource.cpp:45
juce::MemoryAudioSource::releaseResources
void releaseResources() override
Definition: juce_MemoryAudioSource.cpp:43
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