YSE sound engine  1.0
cross platform sound engine
 All Classes Namespaces Functions Pages
oscillators.hpp
1 /*
2  ==============================================================================
3 
4  oscillators.h
5  Created: 31 Jan 2014 2:54:59pm
6  Author: yvan
7 
8  ==============================================================================
9 */
10 
11 #ifndef OSCILLATORS_H_INCLUDED
12 #define OSCILLATORS_H_INCLUDED
13 
14 #include "../headers/defines.hpp"
15 #include "../headers/types.hpp"
16 #include "../headers/constants.hpp"
17 #include "sample.hpp"
18 
19 /* Constructor aside, all these objects should be used in dsp mode only */
20 
21 namespace YSE {
22  namespace DSP {
23 
24  class API saw {
25  public:
26  AUDIOBUFFER & operator()(Flt frequency, UInt length = STANDARD_BUFFERSIZE);
27  AUDIOBUFFER & operator()(AUDIOBUFFER & in);
28  saw();
29 
30  private:
31  Dbl phase;
32  Flt conv;
33  Flt frequency;
34  sample buffer;
35 
36  Flt *inPtr;
37  void calc(Bool useFrequency);
38  };
39 
40  class API cosine {
41  public:
42  AUDIOBUFFER & operator()(AUDIOBUFFER & in);
43  cosine();
44 
45  private:
46  sample buffer;
47  };
48 
49  class API sine {
50  public:
51  AUDIOBUFFER & operator()(Flt frequency, UInt length = STANDARD_BUFFERSIZE);
52  AUDIOBUFFER & operator()(AUDIOBUFFER & in);
53  sine();
54  void reset(); // set the phase back to zero
55 
56  private:
57  sample buffer;
58  Dbl phase;
59  Flt conv;
60  Flt frequency;
61 
62  Flt *inPtr;
63  void calc(Bool useFrequency);
64  };
65 
66 
67  class API noise {
68  public:
69  AUDIOBUFFER & operator()(UInt length = STANDARD_BUFFERSIZE);
70  noise();
71 
72  private:
73  sample buffer;
74  Int value;
75  };
76 
77  class API vcf {
78  public:
79  vcf& sharpness(Flt q);
80  // TODO a bit awkward: first output is function out, second output sent to 3th argument
81  AUDIOBUFFER & operator()(AUDIOBUFFER & in, AUDIOBUFFER & center, sample& out2);
82  vcf();
83 
84  private:
85  Flt re;
86  Flt im;
87  Flt q;
88  Flt isr;
89  sample buffer;
90  };
91 
92  }
93 }
94 
95 
96 
97 #endif // OSCILLATORS_H_INCLUDED