OpenShot Library | libopenshot-audio  0.2.0
juce_ReverbAudioSource.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 ReverbAudioSource::ReverbAudioSource (AudioSource* const inputSource, const bool deleteInputWhenDeleted)
27  : input (inputSource, deleteInputWhenDeleted),
28  bypass (false)
29 {
30  jassert (inputSource != nullptr);
31 }
32 
34 
35 void ReverbAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
36 {
37  const ScopedLock sl (lock);
38  input->prepareToPlay (samplesPerBlockExpected, sampleRate);
39  reverb.setSampleRate (sampleRate);
40 }
41 
43 
45 {
46  const ScopedLock sl (lock);
47 
48  input->getNextAudioBlock (bufferToFill);
49 
50  if (! bypass)
51  {
52  float* const firstChannel = bufferToFill.buffer->getWritePointer (0, bufferToFill.startSample);
53 
54  if (bufferToFill.buffer->getNumChannels() > 1)
55  {
56  reverb.processStereo (firstChannel,
57  bufferToFill.buffer->getWritePointer (1, bufferToFill.startSample),
58  bufferToFill.numSamples);
59  }
60  else
61  {
62  reverb.processMono (firstChannel, bufferToFill.numSamples);
63  }
64  }
65 }
66 
68 {
69  const ScopedLock sl (lock);
70  reverb.setParameters (newParams);
71 }
72 
73 void ReverbAudioSource::setBypassed (bool b) noexcept
74 {
75  if (bypass != b)
76  {
77  const ScopedLock sl (lock);
78  bypass = b;
79  reverb.reset();
80  }
81 }
82 
83 } // namespace juce
juce::Reverb::processStereo
void processStereo(float *const left, float *const right, const int numSamples) noexcept
Applies the reverb to two stereo channels of audio data.
Definition: juce_Reverb.h:136
juce::Reverb::processMono
void processMono(float *const samples, const int numSamples) noexcept
Applies the reverb to a single mono channel of audio data.
Definition: juce_Reverb.h:170
juce::AudioSource
Base class for objects that can produce a continuous stream of audio.
Definition: juce_AudioSource.h:113
juce::ReverbAudioSource::setParameters
void setParameters(const Reverb::Parameters &newParams)
Changes the reverb's parameters.
Definition: juce_ReverbAudioSource.cpp:67
juce::ReverbAudioSource::prepareToPlay
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override
Tells the source to prepare for playing.
Definition: juce_ReverbAudioSource.cpp:35
juce::AudioBuffer::getWritePointer
Type * getWritePointer(int channelNumber) noexcept
Returns a writeable pointer to one of the buffer's channels.
Definition: juce_AudioSampleBuffer.h:277
juce::ReverbAudioSource::ReverbAudioSource
ReverbAudioSource(AudioSource *inputSource, bool deleteInputWhenDeleted)
Creates a ReverbAudioSource to process a given input source.
Definition: juce_ReverbAudioSource.cpp:26
juce::AudioSourceChannelInfo::startSample
int startSample
The first sample in the buffer from which the callback is expected to write data.
Definition: juce_AudioSource.h:81
juce::AudioSourceChannelInfo::numSamples
int numSamples
The number of samples in the buffer which the callback is expected to fill with data.
Definition: juce_AudioSource.h:85
juce::ReverbAudioSource::releaseResources
void releaseResources() override
Allows the source to release anything it no longer needs after playback has stopped.
Definition: juce_ReverbAudioSource.cpp:42
juce::AudioBuffer::getNumChannels
int getNumChannels() const noexcept
Returns the number of channels of audio data that this buffer contains.
Definition: juce_AudioSampleBuffer.h:237
juce::ReverbAudioSource::~ReverbAudioSource
~ReverbAudioSource() override
Destructor.
Definition: juce_ReverbAudioSource.cpp:33
juce::AudioSourceChannelInfo::buffer
AudioBuffer< float > * buffer
The destination buffer to fill with audio data.
Definition: juce_AudioSource.h:77
juce::AudioSourceChannelInfo
Used by AudioSource::getNextAudioBlock().
Definition: juce_AudioSource.h:36
juce::Reverb::setParameters
void setParameters(const Parameters &newParams)
Applies a new set of parameters to the reverb.
Definition: juce_Reverb.h:73
juce::GenericScopedLock
Automatically locks and unlocks a mutex object.
Definition: juce_ScopedLock.h:58
juce::ReverbAudioSource::getNextAudioBlock
void getNextAudioBlock(const AudioSourceChannelInfo &) override
Called repeatedly to fetch subsequent blocks of audio data.
Definition: juce_ReverbAudioSource.cpp:44
juce::Reverb::Parameters
Holds the parameters being used by a Reverb object.
Definition: juce_Reverb.h:54
juce::Reverb::setSampleRate
void setSampleRate(const double sampleRate)
Sets the sample rate that will be used for the reverb.
Definition: juce_Reverb.h:92