@@ -43,18 +43,14 @@ class SoundGenerator {
43
43
// / Provides a single sample
44
44
virtual T readSample () = 0;
45
45
46
- // / Provides the data as byte array with the requested number of channels
47
- virtual size_t readBytes ( uint8_t *buffer, size_t lengthBytes){
48
- return readBytes (buffer, lengthBytes);
49
- }
50
46
51
47
// / Provides the data as byte array with the requested number of channels
52
- virtual size_t readBytes ( uint8_t *buffer, size_t lengthBytes, uint8_t channels ){
48
+ virtual size_t readBytes ( uint8_t *buffer, size_t lengthBytes){
53
49
LOGD (" readBytes: %d - channesl = %d" ,lengthBytes, channels);
54
50
size_t result = 0 ;
55
51
int frame_size = sizeof (T) * channels;
56
52
if (active){
57
- switch (channels){
53
+ switch (channels () ){
58
54
case 1 :
59
55
result = readSamples ((T*) buffer, lengthBytes / frame_size) ;
60
56
break ;
@@ -93,12 +89,23 @@ class SoundGenerator {
93
89
return active;
94
90
}
95
91
92
+ void setChannels (int channels){
93
+ output_channels = channels;
94
+ }
95
+
96
+ int channels () {
97
+ return output_channels;
98
+ }
99
+
96
100
protected:
97
101
bool active = false ;
98
102
bool activeWarningIssued = false ;
103
+ int output_channels = 1 ;
99
104
100
105
};
101
106
107
+
108
+
102
109
/* *
103
110
* @brief Generates a Sound with the help of sin() function.
104
111
* @author Phil Schatzmann
@@ -115,8 +122,15 @@ class SineWaveGenerator : public SoundGenerator<T> {
115
122
m_phase = phase;
116
123
}
117
124
118
- // / Starts the processing by defining the sample rate and frequency
119
- void begin (uint16_t sample_rate=44100 , uint16_t frequency=0 ){
125
+ void begin () {
126
+ b
127
+ egin (1 , 44100 , 0 );
128
+ }
129
+ void begin (uint16_t sample_rate, uint16_t frequency=0 ){
130
+ begin (1 , sample_rate, frequency);
131
+ }
132
+
133
+ void begin (int channels, uint16_t sample_rate, uint16_t frequency=0 ){
120
134
LOGI (" SineWaveGenerator::begin" );
121
135
this ->m_frequency = frequency;
122
136
this ->m_sample_rate = sample_rate;
0 commit comments