2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
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.
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
20 ==============================================================================
26 ToneGeneratorAudioSource::ToneGeneratorAudioSource()
35 ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
39 //==============================================================================
40 void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude
)
42 amplitude
= newAmplitude
;
45 void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz
)
47 frequency
= newFrequencyHz
;
51 //==============================================================================
52 void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/, double rate
)
59 void ToneGeneratorAudioSource::releaseResources()
63 void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo
& info
)
65 if (phasePerSample
== 0.0)
66 phasePerSample
= MathConstants
<double>::twoPi
/ (sampleRate
/ frequency
);
68 for (int i
= 0; i
< info
.numSamples
; ++i
)
70 const float sample
= amplitude
* (float) std::sin (currentPhase
);
71 currentPhase
+= phasePerSample
;
73 for (int j
= info
.buffer
->getNumChannels(); --j
>= 0;)
74 info
.buffer
->setSample (j
, info
.startSample
+ i
, sample
);