~marcustomlinson/dspatchables/trunk

« back to all changes in this revision

Viewing changes to DspOscillator/DspOscillator.h

  • Committer: Marcus Tomlinson
  • Date: 2015-04-05 22:25:24 UTC
  • mfrom: (1.1.10 trunk)
  • Revision ID: marcus.tomlinson@canonical.com-20150405222524-urntp725s5hbk2im
Merged add_basic_components

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/************************************************************************
2
 
DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
3
 
Copyright (c) 2012-2014 Marcus Tomlinson
4
 
 
5
 
This file is part of DSPatch.
6
 
 
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.
14
 
 
15
 
Other Usage
16
 
Alternatively, this file may be used in accordance with the terms and
17
 
conditions contained in a signed written agreement between you and
18
 
Marcus Tomlinson.
19
 
 
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
 
************************************************************************/
24
 
 
25
 
#ifndef DSPOSCILLATOR_H
26
 
#define DSPOSCILLATOR_H
27
 
 
28
 
#include <DSPatch.h>
29
 
 
30
 
//=================================================================================================
31
 
 
32
 
class DspOscillator : public DspComponent
33
 
{
34
 
public:
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
39
 
 
40
 
  DspOscillator( float startFreq = 1000.0, float startAmpl = 1.0 );
41
 
  ~DspOscillator();
42
 
 
43
 
  void SetBufferSize( int bufferSize );
44
 
  void SetSampleRate( int sampleRate );
45
 
  void SetAmpl( float ampl );
46
 
  void SetFreq( float freq );
47
 
 
48
 
  int GetBufferSize() const;
49
 
  int GetSampleRate() const;
50
 
  float GetAmpl() const;
51
 
  float GetFreq() const;
52
 
 
53
 
protected:
54
 
  virtual void Process_( DspSignalBus& inputs, DspSignalBus& outputs );
55
 
  virtual bool ParameterUpdating_( std::string const& name, DspParameter const& param );
56
 
 
57
 
private:
58
 
  std::vector< float > _signalLookup;
59
 
  std::vector< float > _signal;
60
 
 
61
 
  unsigned long _lastPos;
62
 
  unsigned long _lookupLength;
63
 
 
64
 
  DspMutex _processMutex;
65
 
 
66
 
  void _BuildLookup();
67
 
};
68
 
 
69
 
//=================================================================================================
70
 
 
71
 
class DspOscillatorPlugin : public DspPlugin
72
 
{
73
 
  std::map< std::string, DspParameter > GetCreateParams() const
74
 
  {
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 ) );
78
 
    return params;
79
 
  }
80
 
 
81
 
  DspComponent* Create( std::map< std::string, DspParameter >& params ) const
82
 
  {
83
 
    float const* startFreq = params[ "startFreq" ].GetFloat();
84
 
    float const* startAmpl = params[ "startAmpl" ].GetFloat();
85
 
 
86
 
    if( startFreq && startAmpl )
87
 
    {
88
 
      return new DspOscillator( *startFreq, *startAmpl );
89
 
    }
90
 
    else if( startFreq && !startAmpl )
91
 
    {
92
 
      return new DspOscillator( *startFreq );
93
 
    }
94
 
    else
95
 
    {
96
 
      return new DspOscillator();
97
 
    }
98
 
  }
99
 
};
100
 
 
101
 
EXPORT_DSPPLUGIN( DspOscillatorPlugin )
102
 
 
103
 
//=================================================================================================
104
 
 
105
 
#endif /* DSPOSCILLATOR_H */
 
1
/************************************************************************
 
2
DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
 
3
Copyright (c) 2012-2015 Marcus Tomlinson
 
4
 
 
5
This file is part of DSPatch.
 
6
 
 
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.
 
14
 
 
15
Other Usage
 
16
Alternatively, this file may be used in accordance with the terms and
 
17
conditions contained in a signed written agreement between you and
 
18
Marcus Tomlinson.
 
19
 
 
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
************************************************************************/
 
24
 
 
25
#ifndef DSPOSCILLATOR_H
 
26
#define DSPOSCILLATOR_H
 
27
 
 
28
#include <DSPatch.h>
 
29
 
 
30
//=================================================================================================
 
31
 
 
32
class DspOscillator : public DspComponent
 
33
{
 
34
public:
 
35
    int pBufferSize;  // Int
 
36
    int pSampleRate;  // Int
 
37
    int pAmplitude;   // Float
 
38
    int pFrequency;   // Float
 
39
 
 
40
    DspOscillator(float startFreq = 1000.0, float startAmpl = 1.0);
 
41
    ~DspOscillator();
 
42
 
 
43
    void SetBufferSize(int bufferSize);
 
44
    void SetSampleRate(int sampleRate);
 
45
    void SetAmpl(float ampl);
 
46
    void SetFreq(float freq);
 
47
 
 
48
    int GetBufferSize() const;
 
49
    int GetSampleRate() const;
 
50
    float GetAmpl() const;
 
51
    float GetFreq() const;
 
52
 
 
53
protected:
 
54
    virtual void Process_(DspSignalBus& inputs, DspSignalBus& outputs);
 
55
    virtual bool ParameterUpdating_(int index, DspParameter const& param);
 
56
 
 
57
private:
 
58
    std::vector<float> _signalLookup;
 
59
    std::vector<float> _signal;
 
60
 
 
61
    int _lastPos;
 
62
    int _lookupLength;
 
63
 
 
64
    DspMutex _processMutex;
 
65
 
 
66
    void _BuildLookup();
 
67
};
 
68
 
 
69
//=================================================================================================
 
70
 
 
71
class DspOscillatorPlugin : public DspPlugin
 
72
{
 
73
    std::map<std::string, DspParameter> GetCreateParams() const
 
74
    {
 
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));
 
78
        return params;
 
79
    }
 
80
 
 
81
    DspComponent* Create(std::map<std::string, DspParameter>& params) const
 
82
    {
 
83
        float const* startFreq = params["startFreq"].GetFloat();
 
84
        float const* startAmpl = params["startAmpl"].GetFloat();
 
85
 
 
86
        if (startFreq && startAmpl)
 
87
        {
 
88
            return new DspOscillator(*startFreq, *startAmpl);
 
89
        }
 
90
        else if (startFreq && !startAmpl)
 
91
        {
 
92
            return new DspOscillator(*startFreq);
 
93
        }
 
94
        else
 
95
        {
 
96
            return new DspOscillator();
 
97
        }
 
98
    }
 
99
};
 
100
 
 
101
EXPORT_DSPPLUGIN(DspOscillatorPlugin)
 
102
 
 
103
//=================================================================================================
 
104
 
 
105
#endif /* DSPOSCILLATOR_H */