mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added the JUCE DSP module
This commit is contained in:
parent
281c2fe2af
commit
244a944857
212 changed files with 37051 additions and 1301 deletions
66
modules/juce_audio_basics/sources/juce_MemoryAudioSource.cpp
Normal file
66
modules/juce_audio_basics/sources/juce_MemoryAudioSource.cpp
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2017 - ROLI Ltd.
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
The code included in this file is provided under the terms of the ISC license
|
||||
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
|
||||
To use, copy, modify, and/or distribute this software for any purpose with or
|
||||
without fee is hereby granted provided that the above copyright notice and
|
||||
this permission notice appear in all copies.
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
//==============================================================================
|
||||
MemoryAudioSource::MemoryAudioSource (AudioBuffer<float>& bufferToUse, bool copyMemory, bool shouldLoop)
|
||||
: isLooping (shouldLoop)
|
||||
{
|
||||
if (copyMemory)
|
||||
buffer.makeCopyOf (bufferToUse);
|
||||
else
|
||||
buffer.setDataToReferTo (bufferToUse.getArrayOfWritePointers(),
|
||||
bufferToUse.getNumChannels(),
|
||||
bufferToUse.getNumSamples());
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void MemoryAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/, double /*sampleRate*/)
|
||||
{
|
||||
position = 0;
|
||||
}
|
||||
|
||||
void MemoryAudioSource::releaseResources() {}
|
||||
|
||||
void MemoryAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
|
||||
{
|
||||
auto& dst = *bufferToFill.buffer;
|
||||
auto channels = jmin (dst.getNumChannels(), buffer.getNumChannels());
|
||||
auto max = 0, pos = 0;
|
||||
auto n = buffer.getNumSamples(), m = bufferToFill.numSamples;
|
||||
|
||||
for (auto i = position; (i < n || isLooping) && (pos < m); i += max)
|
||||
{
|
||||
max = jmin (m - pos, n - (i % n));
|
||||
|
||||
int ch = 0;
|
||||
for (; ch < channels; ++ch)
|
||||
dst.copyFrom (ch, bufferToFill.startSample + pos, buffer, ch, i % n, max);
|
||||
|
||||
for (; ch < dst.getNumChannels(); ++ch)
|
||||
dst.clear (ch, bufferToFill.startSample + pos, max);
|
||||
|
||||
pos += max;
|
||||
}
|
||||
|
||||
if (pos < m)
|
||||
dst.clear (bufferToFill.startSample + pos, m - pos);
|
||||
}
|
||||
61
modules/juce_audio_basics/sources/juce_MemoryAudioSource.h
Normal file
61
modules/juce_audio_basics/sources/juce_MemoryAudioSource.h
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2017 - ROLI Ltd.
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
The code included in this file is provided under the terms of the ISC license
|
||||
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
|
||||
To use, copy, modify, and/or distribute this software for any purpose with or
|
||||
without fee is hereby granted provided that the above copyright notice and
|
||||
this permission notice appear in all copies.
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
An AudioSource which takes some float audio data as an input.
|
||||
*/
|
||||
class JUCE_API MemoryAudioSource : public AudioSource
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
/** Creates a MemoryAudioSource by providing an audio buffer.
|
||||
|
||||
If copyMemory is true then the buffer will be copied into an internal
|
||||
buffer which will be owned by the MemoryAudioSource. If copyMemory is
|
||||
false, then you must ensure that the lifetime of the audio buffer is
|
||||
at least as long as the MemoryAudioSource.
|
||||
*/
|
||||
MemoryAudioSource (AudioBuffer<float>& audioBuffer, bool copyMemory, bool shouldLoop = false);
|
||||
|
||||
//==============================================================================
|
||||
/** Implementation of the AudioSource method. */
|
||||
void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
|
||||
|
||||
/** Implementation of the AudioSource method. */
|
||||
void releaseResources() override;
|
||||
|
||||
/** Implementation of the AudioSource method. */
|
||||
void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override;
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
AudioBuffer<float> buffer;
|
||||
int position = 0;
|
||||
bool isLooping;
|
||||
|
||||
//==============================================================================
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MemoryAudioSource)
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue