LMMS
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//==============================================================================
40void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
41{
42 amplitude = newAmplitude;
43}
44
45void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
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 (phasePerSample == 0.0)
67
68 for (int i = 0; i < info.numSamples; ++i)
69 {
70 const float sample = amplitude * (float) std::sin (currentPhase);
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
double frequency
Definition juce_ToneGeneratorAudioSource.h:64
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override
Definition juce_ToneGeneratorAudioSource.cpp:52
void releaseResources() override
Definition juce_ToneGeneratorAudioSource.cpp:59
double phasePerSample
Definition juce_ToneGeneratorAudioSource.h:65
double currentPhase
Definition juce_ToneGeneratorAudioSource.h:65
double sampleRate
Definition juce_ToneGeneratorAudioSource.h:64
void setFrequency(double newFrequencyHz)
Definition juce_ToneGeneratorAudioSource.cpp:45
ToneGeneratorAudioSource()
Definition juce_ToneGeneratorAudioSource.cpp:26
void getNextAudioBlock(const AudioSourceChannelInfo &) override
Definition juce_ToneGeneratorAudioSource.cpp:63
float amplitude
Definition juce_ToneGeneratorAudioSource.h:66
void setAmplitude(float newAmplitude)
Definition juce_ToneGeneratorAudioSource.cpp:40
~ToneGeneratorAudioSource() override
Definition juce_ToneGeneratorAudioSource.cpp:35
register unsigned j
Definition inflate.c:1576
register unsigned i
Definition inflate.c:1575
struct backing_store_struct * info
Definition jmemsys.h:183
Definition carla_juce.cpp:31
Definition juce_AudioSource.h:33
static constexpr FloatType twoPi
Definition juce_MathsFunctions.h:385
signed int sample
Definition tap_dynamics_m.c:41