Loading...
Searching...
No Matches
juce_ResamplingAudioSource.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
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.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API ResamplingAudioSource : public AudioSource
{
public:
//==============================================================================
ResamplingAudioSource (AudioSource* inputSource,
bool deleteInputWhenDeleted,
int numChannels = 2);
~ResamplingAudioSource() override;
void setResamplingRatio (double samplesInPerOutputSample);
double getResamplingRatio() const noexcept { return ratio; }
void flushBuffers();
//==============================================================================
void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
void releaseResources() override;
void getNextAudioBlock (const AudioSourceChannelInfo&) override;
private:
//==============================================================================
OptionalScopedPointer<AudioSource> input;
double ratio = 1.0, lastRatio = 1.0;
AudioBuffer<float> buffer;
int bufferPos = 0, sampsInBuffer = 0;
double subSampleOffset = 0.0;
double coefficients[6];
SpinLock ratioLock;
CriticalSection callbackLock;
const int numChannels;
HeapBlock<float*> destBuffers;
HeapBlock<const float*> srcBuffers;
void setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6);
void createLowPass (double proportionalRate);
struct FilterState
{
double x1, x2, y1, y2;
};
HeapBlock<FilterState> filterStates;
void resetFilters();
void applyFilter (float* samples, int num, FilterState& fs);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ResamplingAudioSource)
};
} // namespace juce
juce::AudioBuffer
Definition juce_AudioSampleBuffer.h:34
juce::AudioSource::AudioSource
AudioSource()=default
juce::CriticalSection
Definition juce_CriticalSection.h:43
juce::HeapBlock
Definition juce_HeapBlock.h:87
juce::OptionalScopedPointer
Definition juce_OptionalScopedPointer.h:38
juce::ResamplingAudioSource::getResamplingRatio
double getResamplingRatio() const noexcept
Definition juce_ResamplingAudioSource.h:66
juce::ResamplingAudioSource::setResamplingRatio
void setResamplingRatio(double samplesInPerOutputSample)
Definition juce_ResamplingAudioSource.cpp:38
juce::ResamplingAudioSource::ResamplingAudioSource
ResamplingAudioSource(AudioSource *inputSource, bool deleteInputWhenDeleted, int numChannels=2)
Definition juce_ResamplingAudioSource.cpp:26
juce::SpinLock
Definition juce_SpinLock.h:42
juce::AudioSourceChannelInfo
Definition juce_AudioSource.h:33