OpenShot Audio Library | OpenShotAudio 0.3.2

Loading...
Searching...
No Matches
juce_ToneGeneratorAudioSource.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 ToneGeneratorAudioSource::ToneGeneratorAudioSource()
27 : frequency (1000.0),
28 sampleRate (44100.0),
29 currentPhase (0.0),
30 phasePerSample (0.0),
31 amplitude (0.5f)
32{
33}
34
35 ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
36{
37}
38
39//==============================================================================
40 void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
41{
42 amplitude = newAmplitude;
43}
44
45 void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
46{
47 frequency = newFrequencyHz;
48 phasePerSample = 0.0;
49}
50
51//==============================================================================
52 void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/, double rate)
53{
54 currentPhase = 0.0;
55 phasePerSample = 0.0;
56 sampleRate = rate;
57}
58
59 void ToneGeneratorAudioSource::releaseResources()
60{
61}
62
63 void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
64{
65 if (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
juce::AudioBuffer::getNumChannels
int getNumChannels() const noexcept
Definition: juce_AudioSampleBuffer.h:233
juce::AudioBuffer::setSample
void setSample(int destChannel, int destSample, Type newValue) noexcept
Definition: juce_AudioSampleBuffer.h:576
juce::ToneGeneratorAudioSource::prepareToPlay
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override
Definition: juce_ToneGeneratorAudioSource.cpp:52
juce::ToneGeneratorAudioSource::releaseResources
void releaseResources() override
Definition: juce_ToneGeneratorAudioSource.cpp:59
juce::ToneGeneratorAudioSource::setFrequency
void setFrequency(double newFrequencyHz)
Definition: juce_ToneGeneratorAudioSource.cpp:45
juce::ToneGeneratorAudioSource::ToneGeneratorAudioSource
ToneGeneratorAudioSource()
Definition: juce_ToneGeneratorAudioSource.cpp:26
juce::ToneGeneratorAudioSource::getNextAudioBlock
void getNextAudioBlock(const AudioSourceChannelInfo &) override
Definition: juce_ToneGeneratorAudioSource.cpp:63
juce::ToneGeneratorAudioSource::setAmplitude
void setAmplitude(float newAmplitude)
Definition: juce_ToneGeneratorAudioSource.cpp:40
juce::ToneGeneratorAudioSource::~ToneGeneratorAudioSource
~ToneGeneratorAudioSource() override
Definition: juce_ToneGeneratorAudioSource.cpp:35
juce::AudioSourceChannelInfo
Definition: juce_AudioSource.h:33
juce::AudioSourceChannelInfo::numSamples
int numSamples
Definition: juce_AudioSource.h:81
juce::AudioSourceChannelInfo::buffer
AudioBuffer< float > * buffer
Definition: juce_AudioSource.h:73
juce::AudioSourceChannelInfo::startSample
int startSample
Definition: juce_AudioSource.h:77
juce::MathConstants
Definition: juce_MathsFunctions.h:363