1
1
#pragma once
2
2
3
3
#include " AudioConfig.h"
4
- #ifdef USE_STK
5
4
6
5
#include " Arduino.h"
7
6
#include " freertos/FreeRTOS.h"
8
- #include " Stk.h"
9
- #include " Voicer.h"
10
- #include " Instrmnt.h"
7
+ #include " StkAll.h"
11
8
12
9
namespace audio_tools {
13
10
@@ -28,6 +25,8 @@ namespace audio_tools {
28
25
template <class T >
29
26
class STKGenerator : public SoundGenerator <T> {
30
27
public:
28
+ STKGenerator () = default ;
29
+
31
30
// Creates an STKGenerator for an instrument
32
31
STKGenerator (stk::Instrmnt &instrument) : SoundGenerator<T>() {
33
32
this ->p_instrument = &instrument;
@@ -38,6 +37,14 @@ class STKGenerator : public SoundGenerator<T> {
38
37
this ->p_voicer = &voicer;
39
38
}
40
39
40
+ void setInput (stk::Instrmnt &instrument){
41
+ this ->p_instrument = &instrument;
42
+ }
43
+
44
+ void setInput (stk::Voicer &voicer){
45
+ this ->p_voicer = &voicer;
46
+ }
47
+
41
48
// / provides the default configuration
42
49
AudioBaseInfo defaultConfig () {
43
50
AudioBaseInfo info;
@@ -48,12 +55,13 @@ class STKGenerator : public SoundGenerator<T> {
48
55
}
49
56
50
57
// / Starts the processing
51
- void begin (AudioBaseInfo cfg){
58
+ bool begin (AudioBaseInfo cfg){
52
59
LOGI (LOG_METHOD);
53
60
cfg.logInfo ();
54
61
SoundGenerator<T>::begin (cfg);
55
62
max_value = NumberConverter::maxValue (sizeof (T)*8 );
56
63
stk::Stk::setSampleRate (SoundGenerator<T>::info.sample_rate );
64
+ return true ;
57
65
}
58
66
59
67
// / Provides a single sample
@@ -74,7 +82,27 @@ class STKGenerator : public SoundGenerator<T> {
74
82
75
83
};
76
84
85
+ /* *
86
+ * @brief STK Stream for Instrument or Voicer
87
+ *
88
+ * @tparam T
89
+ */
90
+ template <class T >
91
+ class STKStream : public GeneratedSoundStream <T> {
92
+ public:
93
+ STKStream (Instrmnt &instrument){
94
+ generator.setInput (instrument);
95
+ GeneratedSoundStream<T>::setInput (generator);
96
+ }
97
+ STKStream (Voicer &voicer){
98
+ generator.setInput (voicer);
99
+ GeneratedSoundStream<T>::setInput (generator);
100
+ }
101
+ protected:
102
+ STKGenerator<T> generator;
103
+
104
+ };
105
+
77
106
78
107
}
79
108
80
- #endif
0 commit comments