JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_ToneGeneratorAudioSource.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
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
23namespace juce
24{
25
27 : frequency (1000.0),
28 sampleRate (44100.0),
29 currentPhase (0.0),
30 phasePerSample (0.0),
31 amplitude (0.5f)
32{
33}
34
38
39//==============================================================================
41{
42 amplitude = newAmplitude;
43}
44
46{
47 frequency = newFrequencyHz;
48 phasePerSample = 0.0;
49}
50
51//==============================================================================
52void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/, double rate)
53{
54 currentPhase = 0.0;
55 phasePerSample = 0.0;
56 sampleRate = rate;
57}
58
62
64{
65 if (approximatelyEqual (phasePerSample, 0.0))
66 phasePerSample = MathConstants<double>::twoPi / (sampleRate / frequency);
67
68 for (int i = 0; i < info.numSamples; ++i)
69 {
70 const float sample = amplitude * (float) std::sin (currentPhase);
71 currentPhase += phasePerSample;
72
73 for (int j = info.buffer->getNumChannels(); --j >= 0;)
74 info.buffer->setSample (j, info.startSample + i, sample);
75 }
76}
77
78} // namespace juce
int getNumChannels() const noexcept
Returns the number of channels of audio data that this buffer contains.
void setSample(int destChannel, int destSample, Type newValue) noexcept
Sets a sample in the buffer.
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override
Implementation of the AudioSource method.
void releaseResources() override
Implementation of the AudioSource method.
void setFrequency(double newFrequencyHz)
Sets the signal's frequency.
ToneGeneratorAudioSource()
Creates a ToneGeneratorAudioSource.
void getNextAudioBlock(const AudioSourceChannelInfo &) override
Implementation of the AudioSource method.
void setAmplitude(float newAmplitude)
Sets the signal's amplitude.
typedef float
JUCE Namespace.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
T sin(T... args)
Used by AudioSource::getNextAudioBlock().
int numSamples
The number of samples in the buffer which the callback is expected to fill with data.
AudioBuffer< float > * buffer
The destination buffer to fill with audio data.
int startSample
The first sample in the buffer from which the callback is expected to write data.
Commonly used mathematical constants.