@@ -43,18 +43,14 @@ class SoundGenerator {
4343 // / Provides a single sample
4444 virtual T readSample () = 0;
4545
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- }
5046
5147 // / 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){
5349 LOGD (" readBytes: %d - channesl = %d" ,lengthBytes, channels);
5450 size_t result = 0 ;
5551 int frame_size = sizeof (T) * channels;
5652 if (active){
57- switch (channels){
53+ switch (channels () ){
5854 case 1 :
5955 result = readSamples ((T*) buffer, lengthBytes / frame_size) ;
6056 break ;
@@ -93,12 +89,23 @@ class SoundGenerator {
9389 return active;
9490 }
9591
92+ void setChannels (int channels){
93+ output_channels = channels;
94+ }
95+
96+ int channels () {
97+ return output_channels;
98+ }
99+
96100 protected:
97101 bool active = false ;
98102 bool activeWarningIssued = false ;
103+ int output_channels = 1 ;
99104
100105};
101106
107+
108+
102109/* *
103110 * @brief Generates a Sound with the help of sin() function.
104111 * @author Phil Schatzmann
@@ -115,8 +122,15 @@ class SineWaveGenerator : public SoundGenerator<T> {
115122 m_phase = phase;
116123 }
117124
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 ){
120134 LOGI (" SineWaveGenerator::begin" );
121135 this ->m_frequency = frequency;
122136 this ->m_sample_rate = sample_rate;
0 commit comments