1
/************************************************************************
2
DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
3
Copyright (c) 2012-2014 Marcus Tomlinson
5
This file is part of DSPatch.
7
GNU Lesser General Public License Usage
8
This file may be used under the terms of the GNU Lesser General Public
9
License version 3.0 as published by the Free Software Foundation and
10
appearing in the file LGPLv3.txt included in the packaging of this
11
file. Please review the following information to ensure the GNU Lesser
12
General Public License version 3.0 requirements will be met:
13
http://www.gnu.org/copyleft/lgpl.html.
16
Alternatively, this file may be used in accordance with the terms and
17
conditions contained in a signed written agreement between you and
20
DSPatch is distributed in the hope that it will be useful,
21
but WITHOUT ANY WARRANTY; without even the implied warranty of
22
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23
************************************************************************/
25
#ifndef DSPOSCILLATOR_H
26
#define DSPOSCILLATOR_H
30
//=================================================================================================
32
class DspOscillator : public DspComponent
35
static std::string const pBufferSize; // Int
36
static std::string const pSampleRate; // Int
37
static std::string const pAmplitude; // Float
38
static std::string const pFrequency; // Float
40
DspOscillator( float startFreq = 1000.0, float startAmpl = 1.0 );
43
void SetBufferSize( int bufferSize );
44
void SetSampleRate( int sampleRate );
45
void SetAmpl( float ampl );
46
void SetFreq( float freq );
48
int GetBufferSize() const;
49
int GetSampleRate() const;
50
float GetAmpl() const;
51
float GetFreq() const;
54
virtual void Process_( DspSignalBus& inputs, DspSignalBus& outputs );
55
virtual bool ParameterUpdating_( std::string const& name, DspParameter const& param );
58
std::vector< float > _signalLookup;
59
std::vector< float > _signal;
61
unsigned long _lastPos;
62
unsigned long _lookupLength;
64
DspMutex _processMutex;
69
//=================================================================================================
71
class DspOscillatorPlugin : public DspPlugin
73
std::map< std::string, DspParameter > GetCreateParams() const
75
std::map< std::string, DspParameter > params;
76
params[ "startFreq" ] = DspParameter( DspParameter::Float );
77
params[ "startAmpl" ] = DspParameter( DspParameter::Float, 1.0f, std::make_pair( 0.0f, 1.0f ) );
81
DspComponent* Create( std::map< std::string, DspParameter >& params ) const
83
float const* startFreq = params[ "startFreq" ].GetFloat();
84
float const* startAmpl = params[ "startAmpl" ].GetFloat();
86
if( startFreq && startAmpl )
88
return new DspOscillator( *startFreq, *startAmpl );
90
else if( startFreq && !startAmpl )
92
return new DspOscillator( *startFreq );
96
return new DspOscillator();
101
EXPORT_DSPPLUGIN( DspOscillatorPlugin )
103
//=================================================================================================
105
#endif /* DSPOSCILLATOR_H */
1
/************************************************************************
2
DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
3
Copyright (c) 2012-2015 Marcus Tomlinson
5
This file is part of DSPatch.
7
GNU Lesser General Public License Usage
8
This file may be used under the terms of the GNU Lesser General Public
9
License version 3.0 as published by the Free Software Foundation and
10
appearing in the file LGPLv3.txt included in the packaging of this
11
file. Please review the following information to ensure the GNU Lesser
12
General Public License version 3.0 requirements will be met:
13
http://www.gnu.org/copyleft/lgpl.html.
16
Alternatively, this file may be used in accordance with the terms and
17
conditions contained in a signed written agreement between you and
20
DSPatch is distributed in the hope that it will be useful,
21
but WITHOUT ANY WARRANTY; without even the implied warranty of
22
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23
************************************************************************/
25
#ifndef DSPOSCILLATOR_H
26
#define DSPOSCILLATOR_H
30
//=================================================================================================
32
class DspOscillator : public DspComponent
35
int pBufferSize; // Int
36
int pSampleRate; // Int
37
int pAmplitude; // Float
38
int pFrequency; // Float
40
DspOscillator(float startFreq = 1000.0, float startAmpl = 1.0);
43
void SetBufferSize(int bufferSize);
44
void SetSampleRate(int sampleRate);
45
void SetAmpl(float ampl);
46
void SetFreq(float freq);
48
int GetBufferSize() const;
49
int GetSampleRate() const;
50
float GetAmpl() const;
51
float GetFreq() const;
54
virtual void Process_(DspSignalBus& inputs, DspSignalBus& outputs);
55
virtual bool ParameterUpdating_(int index, DspParameter const& param);
58
std::vector<float> _signalLookup;
59
std::vector<float> _signal;
64
DspMutex _processMutex;
69
//=================================================================================================
71
class DspOscillatorPlugin : public DspPlugin
73
std::map<std::string, DspParameter> GetCreateParams() const
75
std::map<std::string, DspParameter> params;
76
params["startFreq"] = DspParameter(DspParameter::Float);
77
params["startAmpl"] = DspParameter(DspParameter::Float, 1.0f, std::make_pair(0.0f, 1.0f));
81
DspComponent* Create(std::map<std::string, DspParameter>& params) const
83
float const* startFreq = params["startFreq"].GetFloat();
84
float const* startAmpl = params["startAmpl"].GetFloat();
86
if (startFreq && startAmpl)
88
return new DspOscillator(*startFreq, *startAmpl);
90
else if (startFreq && !startAmpl)
92
return new DspOscillator(*startFreq);
96
return new DspOscillator();
101
EXPORT_DSPPLUGIN(DspOscillatorPlugin)
103
//=================================================================================================
105
#endif /* DSPOSCILLATOR_H */