arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
SoundGenerator.h
1#pragma once
2
3#include <math.h>
4
5#include "AudioTools/CoreAudio/AudioBasic/Collections.h"
6#include "AudioTools/CoreAudio/AudioLogger.h"
7#include "AudioTools/CoreAudio/AudioTypes.h"
8#include "AudioTools/CoreAudio/Buffers.h"
9
16namespace audio_tools {
17
27template <class T>
29 public:
30 SoundGenerator() { info.bits_per_sample = sizeof(T) * 8; }
31
32 virtual ~SoundGenerator() { end(); }
33
34 virtual bool begin(AudioInfo info) {
35 this->info = info;
36 return begin();
37 }
38
39 virtual bool begin() {
40 TRACED();
41 active = true;
42 activeWarningIssued = false;
43 info.logInfo("SoundGenerator:");
44
45 // support bytes < framesize
46 ring_buffer.resize(info.channels * sizeof(T));
47
48 return true;
49 }
50
52 virtual void end() { active = false; }
53
56 virtual bool isActive() { return active; }
57
59 virtual T readSample() = 0;
60
62 virtual size_t readBytes(uint8_t *data, size_t len) {
63 LOGD("readBytes: %d", (int)len);
64 if (!active) return 0;
65 int channels = audioInfo().channels;
66 int frame_size = sizeof(T) * channels;
67 int frames = len / frame_size;
68 if (len >= frame_size) {
69 return readBytesFrames(data, len, frames, channels);
70 }
71 return readBytesFromBuffer(data, len, frame_size, channels);
72 }
73
76 AudioInfo def;
77 def.bits_per_sample = sizeof(T) * 8;
78 return def;
79 }
80
82 virtual void setFrequency(float frequency) {
83 LOGE("setFrequency not supported");
84 }
85
87 virtual AudioInfo audioInfo() { return info; }
88
90 virtual void setAudioInfo(AudioInfo info) {
91 this->info = info;
92 if (info.bits_per_sample != sizeof(T) * 8) {
93 LOGE("invalid bits_per_sample: %d", info.channels);
94 }
95 }
96
97 protected:
98 bool active = false;
99 bool activeWarningIssued = false;
100 // int output_channels = 1;
101 AudioInfo info;
102 RingBuffer<uint8_t> ring_buffer{0};
103
104 size_t readBytesFrames(uint8_t *buffer, size_t lengthBytes, int frames,
105 int channels) {
106 T *result_buffer = (T *)buffer;
107 for (int j = 0; j < frames; j++) {
108 T sample = readSample();
109 for (int ch = 0; ch < channels; ch++) {
110 *result_buffer++ = sample;
111 }
112 }
113 return frames * sizeof(T) * channels;
114 }
115
116 size_t readBytesFromBuffer(uint8_t *buffer, size_t lengthBytes,
117 int frame_size, int channels) {
118 // fill ringbuffer with one frame
119 if (ring_buffer.isEmpty()) {
120 uint8_t tmp[frame_size];
121 readBytesFrames(tmp, frame_size, 1, channels);
122 ring_buffer.writeArray(tmp, frame_size);
123 }
124 // provide result
125 return ring_buffer.readArray(buffer, lengthBytes);
126 }
127};
128
138template <class T>
140 public:
141 // the scale defines the max value which is generated
142 SineWaveGenerator(float amplitude = 0.9f * NumberConverter::maxValueT<T>(),
143 float phase = 0.0f) {
144 LOGD("SineWaveGenerator");
145 m_amplitude = amplitude;
146 m_phase = phase;
147 }
148
149 bool begin() override {
150 TRACEI();
152 this->m_deltaTime = 1.0f / SoundGenerator<T>::info.sample_rate;
153 return true;
154 }
155
156 bool begin(AudioInfo info) override {
157 LOGI("%s::begin(channels=%d, sample_rate=%d)", "SineWaveGenerator",
158 (int)info.channels, (int)info.sample_rate);
160 this->m_deltaTime = 1.0f / SoundGenerator<T>::info.sample_rate;
161 return true;
162 }
163
164 bool begin(AudioInfo info, float frequency) {
165 LOGI("%s::begin(channels=%d, sample_rate=%d, frequency=%.2f)",
166 "SineWaveGenerator", (int)info.channels, (int)info.sample_rate,
167 frequency);
169 this->m_deltaTime = 1.0f / SoundGenerator<T>::info.sample_rate;
170 if (frequency > 0.0f) {
171 setFrequency(frequency);
172 }
173 return true;
174 }
175
176 bool begin(int channels, int sample_rate, float frequency) {
177 SoundGenerator<T>::info.channels = channels;
178 SoundGenerator<T>::info.sample_rate = sample_rate;
179 return begin(SoundGenerator<T>::info, frequency);
180 }
181
182 // update m_deltaTime
183 virtual void setAudioInfo(AudioInfo info) override {
185 this->m_deltaTime = 1.0f / SoundGenerator<T>::info.sample_rate;
186 }
187
188 virtual AudioInfo defaultConfig() override {
190 }
191
193 void setFrequency(float frequency) override {
194 LOGI("setFrequency: %.2f", frequency);
195 LOGI("active: %s", SoundGenerator<T>::active ? "true" : "false");
196 m_frequency = frequency;
197 }
198
200 virtual T readSample() override {
201 float angle = double_Pi * m_cycles + m_phase;
202 T result = m_amplitude * sinf(angle);
203 m_cycles += m_frequency * m_deltaTime;
204 if (m_cycles > 1.0f) {
205 m_cycles -= 1.0f;
206 }
207 return result;
208 }
209
210 void setAmplitude(float amp) { m_amplitude = amp; }
211
212 protected:
213 volatile float m_frequency = 0.0f;
214 float m_cycles = 0.0f; // Varies between 0.0 and 1.0
215 float m_amplitude = 1.0f;
216 float m_deltaTime = 0.0f;
217 float m_phase = 0.0f;
218 const float double_Pi = 2.0f * PI;
219
220 void logStatus() {
221 SoundGenerator<T>::info.logStatus();
222 LOGI("amplitude: %f", this->m_amplitude);
223 LOGI("active: %s", SoundGenerator<T>::active ? "true" : "false");
224 }
225};
226
234template <class T>
236 public:
237 FastSineGenerator(float amplitude = 32767.0, float phase = 0.0)
238 : SineWaveGenerator<T>(amplitude, phase) {
239 LOGD("FastSineGenerator");
240 }
241
253
254 protected:
256 inline float sine(float t) {
257 float p = (t - (int)t) - 0.5f; // 0 <= p <= 1
258 float pp = p * p;
259 return (p - 6.283211f * pp * p + 9.132843f * pp * pp * p) * -6.221086f;
260 }
261};
262
270template <class T>
272 public:
273 SquareWaveGenerator(float amplitude = 32767.0f, float phase = 0.0f)
274 : FastSineGenerator<T>(amplitude, phase) {
275 LOGD("SquareWaveGenerator");
276 }
277
282
283 protected:
284 // returns amplitude for positive vales and -amplitude for negative values
285 T value(T value, T amplitude) {
286 return (value >= 0) ? amplitude : -amplitude;
287 }
288};
289
297template <class T>
299 public:
300 SawToothGenerator(float amplitude = 32767.0, float phase = 0.0)
301 : SineWaveGenerator<T>(amplitude, phase) {
302 LOGD("SawToothGenerator");
303 }
304
316
317 protected:
319 inline float saw(float t) {
320 float p = (t - (int)t) - 0.5f; // 0 <= p <= 1
321 return p;
322 }
323};
324
332template <class T>
334 public:
336 WhiteNoiseGenerator(T amplitude = 32767) { this->amplitude = amplitude; }
337
339 T readSample() { return (random(-amplitude, amplitude)); }
340
341 protected:
342 T amplitude;
343 // //range : [min, max]
344 int random(int min, int max) { return min + rand() % ((max + 1) - min); }
345};
346
354template <class T>
356 public:
358 PinkNoiseGenerator(T amplitude = 32767) {
359 this->amplitude = amplitude;
360 max_key = 0x1f; // Five bits set
361 key = 0;
362 for (int i = 0; i < 5; i++) white_values[i] = rand() % (amplitude / 5);
363 }
364
367 T last_key = key;
368 unsigned int sum;
369
370 key++;
371 if (key > max_key) key = 0;
372 // Exclusive-Or previous value with current value. This gives
373 // a list of bits that have changed.
374 int diff = last_key ^ key;
375 sum = 0;
376 for (int i = 0; i < 5; i++) {
377 // If bit changed get new random number for corresponding
378 // white_value
379 if (diff & (1 << i)) white_values[i] = rand() % (amplitude / 5);
380 sum += white_values[i];
381 }
382 return sum;
383 }
384
385 protected:
386 T max_key;
387 T key;
388 unsigned int white_values[5];
389 unsigned int amplitude;
390};
391
401template <class T>
403 public:
404 // the scale defines the max value which is generated
405 SilenceGenerator(T value = 0) { this->value = value; }
406
409 return value; // return 0
410 }
411
412 protected:
413 T value;
414};
415
423template <class T>
425 public:
427 maxValue = NumberConverter::maxValue(sizeof(T) * 8);
428 };
429
439 GeneratorFromStream(Stream &input, int channels = 1, float volume = 1.0) {
440 maxValue = NumberConverter::maxValue(sizeof(T) * 8);
441 setStream(input);
443 setChannels(channels);
444 }
445
447 void setStream(Stream &input) { this->p_stream = &input; }
448
449 void setChannels(int channels) { this->channels = channels; }
450
453 T data = 0;
454 float total = 0;
455 if (p_stream != nullptr) {
456 for (int j = 0; j < channels; j++) {
457 p_stream->readBytes((uint8_t *)&data, sizeof(T));
458 total += data;
459 }
460 float avg = (total / channels) * volume();
461 if (avg > maxValue) {
462 data = maxValue;
463 } else if (avg < -maxValue) {
464 data = -maxValue;
465 } else {
466 data = avg;
467 }
468 }
469 return data;
470 }
471
472 protected:
473 Stream *p_stream = nullptr;
474 int channels = 1;
475 float maxValue;
476};
477
487template <class T>
489 public:
490 GeneratorFromArray() = default;
503 template <size_t arrayLen>
504 GeneratorFromArray(T (&array)[arrayLen], int repeat = 0,
505 bool setInactiveAtEnd = false, size_t startIndex = 0) {
506 TRACED();
507 this->max_repeat = repeat;
508 this->inactive_at_end = setInactiveAtEnd;
509 this->sound_index = startIndex;
510 setArray(array, arrayLen);
511 }
512
513 template <int arrayLen>
514 void setArray(T (&array)[arrayLen]) {
515 TRACED();
516 setArray(array, arrayLen);
517 }
518
519 void setArray(T *array, size_t size) {
520 table.resize(size);
521 for (int j = 0; j < size; j++) {
522 table[j] = array[j];
523 }
524 LOGI("table_length: %d", (int)size);
525 }
526
527 virtual bool begin(AudioInfo info) override {
528 return SoundGenerator<T>::begin(info);
529 }
530
532 bool begin() override {
533 TRACEI();
535 sound_index = 0;
536 repeat_counter = 0;
537 is_running = true;
538 return true;
539 }
540
541 void end() { table.resize(0); }
542
544 T readSample() override {
545 // at end deactivate output
546 if (sound_index >= table.size()) {
547 // LOGD("reset index - sound_index: %d, table_length:
548 // %d",sound_index,table_length);
549 sound_index = 0;
550 // deactivate when count has been used up
551 if (max_repeat >= 1 && ++repeat_counter >= max_repeat) {
552 LOGD("atEnd");
553 this->is_running = false;
554 if (inactive_at_end) {
555 this->active = false;
556 }
557 }
558 }
559
560 // LOGD("index: %d - active: %d", sound_index, this->active);
561 T result = 0;
562 if (this->is_running) {
563 result = table[sound_index];
564 sound_index += index_increment;
565 }
566
567 return result;
568 }
569
570 // step size the sound index is incremented (default = 1)
571 void setIncrement(int inc) { index_increment = inc; }
572
573 // Sets up a sine table - returns the effective frequency
574 int setupSine(int sampleRate, float reqFrequency, float amplitude = 1.0) {
575 int sample_count =
576 static_cast<float>(sampleRate) /
577 reqFrequency; // e.g. 44100 / 300hz = 147 samples per wave
578 float angle = 2.0 * PI / sample_count;
579 table.resize(sample_count);
580 for (int j = 0; j < sample_count; j++) {
581 table[j] = sinf(j * angle) * amplitude;
582 }
583 // calculate effective frequency
584 return sampleRate / sample_count;
585 }
586
587 // Similar like is active to check if the array is still playing.
588 bool isRunning() { return is_running; }
589
590 protected:
591 int sound_index = 0;
592 int max_repeat = 0;
593 int repeat_counter = 0;
594 bool inactive_at_end;
595 bool is_running = false;
596 bool owns_data = false;
597 Vector<T> table;
598 int index_increment = 1;
599};
600
608template <class T>
610 public:
611 GeneratorFixedValue() = default;
612
613 virtual bool begin(AudioInfo info) { return SoundGenerator<T>::begin(info); }
614
615 void setValue(T value) { value_set = value; }
616
618 bool begin() override {
619 TRACEI();
621 is_running = true;
622 value_return = value_set;
623 return true;
624 }
625
627 T readSample() override { return value_return; }
628
629 // Similar like is active to check if the array is still playing.
630 bool isRunning() { return is_running; }
631
632 protected:
633 T value_set = 0;
634 T value_return = 0;
635 bool is_running = false;
636};
637
645template <class T>
646class SineFromTable : public SoundGenerator<T> {
647 public:
648 SineFromTable(float amplitude = 32767.0) {
649 this->amplitude = amplitude;
650 this->amplitude_to_be = amplitude;
651 }
652
654 void setAmplitude(float amplitude) { this->amplitude_to_be = amplitude; }
655
658 void setMaxAmplitudeStep(float step) { max_amplitude_step = step; }
659
661 // update angle
662 angle += step;
663 if (angle >= 360.0f) {
664 while (angle >= 360.0f) {
665 angle -= 360.0f;
666 }
667 // update frequency at start of circle (near 0 degrees)
668 step = step_new;
669
670 updateAmplitudeInSteps();
671 // amplitude = amplitude_to_be;
672 }
673 return interpolate(angle);
674 }
675
676 bool begin() {
677 is_first = true;
679 base_frequency = SoundGenerator<T>::audioInfo().sample_rate /
680 360.0f; // 122.5 hz (at 44100); 61 hz (at 22050)
681 return true;
682 }
683
684 bool begin(AudioInfo info, float frequency) {
685 SoundGenerator<T>::begin(info);
686 base_frequency = SoundGenerator<T>::audioInfo().sample_rate /
687 360.0f; // 122.5 hz (at 44100); 61 hz (at 22050)
688 setFrequency(frequency);
689 return true;
690 }
691
692 bool begin(int channels, int sample_rate, uint16_t frequency = 0) {
693 SoundGenerator<T>::info.channels = channels;
694 SoundGenerator<T>::info.sample_rate = sample_rate;
695 return begin(SoundGenerator<T>::info, frequency);
696 }
697
698 void setFrequency(float freq) {
699 step_new = freq / base_frequency;
700 if (is_first) {
701 step = step_new;
702 is_first = false;
703 }
704 LOGD("step: %f", step_new);
705 }
706
707 protected:
708 bool is_first = true;
709 float amplitude;
710 float amplitude_to_be;
711 float max_amplitude_step = 50.0f;
712 float base_frequency = 1.0f;
713 float step = 1.0f;
714 float step_new = 1.0f;
715 float angle = 0.0f;
716 // 122.5 hz (at 44100); 61 hz (at 22050)
717 const float values[181] = {
718 0, 0.0174524, 0.0348995, 0.052336, 0.0697565, 0.0871557,
719 0.104528, 0.121869, 0.139173, 0.156434, 0.173648, 0.190809,
720 0.207912, 0.224951, 0.241922, 0.258819, 0.275637, 0.292372,
721 0.309017, 0.325568, 0.34202, 0.358368, 0.374607, 0.390731,
722 0.406737, 0.422618, 0.438371, 0.45399, 0.469472, 0.48481,
723 0.5, 0.515038, 0.529919, 0.544639, 0.559193, 0.573576,
724 0.587785, 0.601815, 0.615661, 0.62932, 0.642788, 0.656059,
725 0.669131, 0.681998, 0.694658, 0.707107, 0.71934, 0.731354,
726 0.743145, 0.75471, 0.766044, 0.777146, 0.788011, 0.798636,
727 0.809017, 0.819152, 0.829038, 0.838671, 0.848048, 0.857167,
728 0.866025, 0.87462, 0.882948, 0.891007, 0.898794, 0.906308,
729 0.913545, 0.920505, 0.927184, 0.93358, 0.939693, 0.945519,
730 0.951057, 0.956305, 0.961262, 0.965926, 0.970296, 0.97437,
731 0.978148, 0.981627, 0.984808, 0.987688, 0.990268, 0.992546,
732 0.994522, 0.996195, 0.997564, 0.99863, 0.999391, 0.999848,
733 1, 0.999848, 0.999391, 0.99863, 0.997564, 0.996195,
734 0.994522, 0.992546, 0.990268, 0.987688, 0.984808, 0.981627,
735 0.978148, 0.97437, 0.970296, 0.965926, 0.961262, 0.956305,
736 0.951057, 0.945519, 0.939693, 0.93358, 0.927184, 0.920505,
737 0.913545, 0.906308, 0.898794, 0.891007, 0.882948, 0.87462,
738 0.866025, 0.857167, 0.848048, 0.838671, 0.829038, 0.819152,
739 0.809017, 0.798636, 0.788011, 0.777146, 0.766044, 0.75471,
740 0.743145, 0.731354, 0.71934, 0.707107, 0.694658, 0.681998,
741 0.669131, 0.656059, 0.642788, 0.62932, 0.615661, 0.601815,
742 0.587785, 0.573576, 0.559193, 0.544639, 0.529919, 0.515038,
743 0.5, 0.48481, 0.469472, 0.45399, 0.438371, 0.422618,
744 0.406737, 0.390731, 0.374607, 0.358368, 0.34202, 0.325568,
745 0.309017, 0.292372, 0.275637, 0.258819, 0.241922, 0.224951,
746 0.207912, 0.190809, 0.173648, 0.156434, 0.139173, 0.121869,
747 0.104528, 0.0871557, 0.0697565, 0.052336, 0.0348995, 0.0174524,
748 0};
749
750 T interpolate(float angle) {
751 bool positive = (angle <= 180.0f);
752 float angle_positive = positive ? angle : angle - 180.0f;
753 int angle_int1 = angle_positive;
754 int angle_int2 = angle_int1 + 1;
755 T v1 = values[angle_int1] * amplitude;
756 T v2 = values[angle_int2] * amplitude;
757 T result = v1 < v2 ? map(angle_positive, angle_int1, angle_int2, v1, v2)
758 : map(angle_positive, angle_int1, angle_int2, v2, v1);
759 // float result = v1;
760 return positive ? result : -result;
761 }
762
763 T map(T x, T in_min, T in_max, T out_min, T out_max) {
764 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
765 }
766
767 void updateAmplitudeInSteps() {
768 float diff = amplitude_to_be - amplitude;
769 if (abs(diff) > max_amplitude_step) {
770 diff = (diff < 0) ? -max_amplitude_step : max_amplitude_step;
771 }
772 if (abs(diff) >= 1.0f) {
773 amplitude += diff;
774 }
775 }
776};
777
786template <class T>
788 public:
789 GeneratorMixer() = default;
790
791 void add(SoundGenerator<T> &generator) { vector.push_back(&generator); }
792 void add(SoundGenerator<T> *generator) { vector.push_back(generator); }
793
794 void clear() { vector.clear(); }
795
797 float total = 0.0f;
798 float count = 0.0f;
799 for (auto &generator : vector) {
800 if (generator->isActive()) {
801 T sample = generator->readSample();
802 total += sample;
803 count += 1.0f;
804 }
805 }
806 return count > 0.0f ? total / count : 0;
807 }
808
809 protected:
810 Vector<SoundGenerator<T> *> vector;
811 int actualChannel = 0;
812};
813
822template <class T>
823class TestGenerator : public SoundGenerator<T> {
824 public:
825 TestGenerator(T max = 1000, T inc = 1) { this->max = max; }
826
827 T readSample() override {
828 value += inc;
829 if (abs(value) >= max) {
830 inc = -inc;
831 value += (inc * 2);
832 }
833 return value;
834 }
835
836 protected:
837 T max;
838 T value = 0;
839 T inc = 1;
840};
841
842} // namespace audio_tools
virtual int readArray(T data[], int len)
reads multiple values
Definition Buffers.h:37
virtual int writeArray(const T data[], int len)
Fills the buffer data.
Definition Buffers.h:59
Sine wave which is based on a fast approximation function.
Definition SoundGenerator.h:235
float sine(float t)
sine approximation.
Definition SoundGenerator.h:256
virtual T readSample() override
Provides a single sample.
Definition SoundGenerator.h:242
Just returns a constant value.
Definition SoundGenerator.h:609
T readSample() override
Provides a single sample.
Definition SoundGenerator.h:627
bool begin() override
Starts the generation of samples.
Definition SoundGenerator.h:618
We generate the samples from an array which is provided in the constructor.
Definition SoundGenerator.h:488
GeneratorFromArray(T(&array)[arrayLen], int repeat=0, bool setInactiveAtEnd=false, size_t startIndex=0)
Construct a new Generator from an array.
Definition SoundGenerator.h:504
T readSample() override
Provides a single sample.
Definition SoundGenerator.h:544
void end()
ends the processing
Definition SoundGenerator.h:541
bool begin() override
Starts the generation of samples.
Definition SoundGenerator.h:532
An Adapter Class which lets you use any Stream as a Generator.
Definition SoundGenerator.h:424
void setStream(Stream &input)
(Re-)Assigns a stream to the Adapter class
Definition SoundGenerator.h:447
GeneratorFromStream(Stream &input, int channels=1, float volume=1.0)
Constructs a new Generator from a Stream object that can be used e.g. as input for AudioEffectss.
Definition SoundGenerator.h:439
T readSample()
Provides a single sample from the stream.
Definition SoundGenerator.h:452
Generator which combines (mixes) multiple sound generators into one output.
Definition SoundGenerator.h:787
T readSample()
Provides a single sample.
Definition SoundGenerator.h:796
static int64_t maxValue(int value_bits_per_sample)
provides the biggest number for the indicated number of bits
Definition AudioTypes.h:299
Generates pink noise.
Definition SoundGenerator.h:355
PinkNoiseGenerator(T amplitude=32767)
the amplitude defines the max value which is generated
Definition SoundGenerator.h:358
T readSample()
Provides a single sample.
Definition SoundGenerator.h:366
Implements a typed Ringbuffer.
Definition Buffers.h:308
SawToothGenerator.
Definition SoundGenerator.h:298
virtual T readSample() override
Provides a single sample.
Definition SoundGenerator.h:305
float saw(float t)
sine approximation.
Definition SoundGenerator.h:319
Provides a fixed value (e.g. 0) as sound data. This can be used e.g. to test the output functionality...
Definition SoundGenerator.h:402
T readSample()
Provides a single sample.
Definition SoundGenerator.h:408
A sine generator based on a table. The table is created using degrees where one full wave is 360 degr...
Definition SoundGenerator.h:646
void setFrequency(float freq)
Abstract method: not implemented! Just provides an error message...
Definition SoundGenerator.h:698
void setAmplitude(float amplitude)
Defines the new amplitude (volume)
Definition SoundGenerator.h:654
void setMaxAmplitudeStep(float step)
Definition SoundGenerator.h:658
T readSample()
Provides a single sample.
Definition SoundGenerator.h:660
Generates a Sound with the help of sin() function. If you plan to change the amplitude or frequency (...
Definition SoundGenerator.h:139
void setFrequency(float frequency) override
Defines the frequency - after the processing has been started.
Definition SoundGenerator.h:193
virtual T readSample() override
Provides a single sample.
Definition SoundGenerator.h:200
virtual void setAudioInfo(AudioInfo info) override
Defines/updates the AudioInfo.
Definition SoundGenerator.h:183
virtual AudioInfo defaultConfig() override
Provides the default configuration.
Definition SoundGenerator.h:188
Base class to define the abstract interface for the sound generating classes.
Definition SoundGenerator.h:28
virtual size_t readBytes(uint8_t *data, size_t len)
Provides the data as byte array with the requested number of channels.
Definition SoundGenerator.h:62
virtual T readSample()=0
Provides a single sample.
virtual void setFrequency(float frequency)
Abstract method: not implemented! Just provides an error message...
Definition SoundGenerator.h:82
virtual bool isActive()
Definition SoundGenerator.h:56
virtual void setAudioInfo(AudioInfo info)
Defines/updates the AudioInfo.
Definition SoundGenerator.h:90
virtual AudioInfo audioInfo()
Provides the AudioInfo.
Definition SoundGenerator.h:87
virtual void end()
ends the processing
Definition SoundGenerator.h:52
virtual AudioInfo defaultConfig()
Provides the default configuration.
Definition SoundGenerator.h:75
Generates a square wave sound.
Definition SoundGenerator.h:271
virtual T readSample()
Provides a single sample.
Definition SoundGenerator.h:278
Definition NoArduino.h:142
Generates a test signal which is easy to check because the values are incremented or decremented by 1...
Definition SoundGenerator.h:823
T readSample() override
Provides a single sample.
Definition SoundGenerator.h:827
Vector implementation which provides the most important methods as defined by std::vector....
Definition Vector.h:21
Supports the setting and getting of the volume.
Definition AudioTypes.h:189
virtual float volume()
provides the actual volume in the range of 0.0f to 1.0f
Definition AudioTypes.h:192
virtual bool setVolume(float volume)
define the actual volume in the range of 0.0f to 1.0f
Definition AudioTypes.h:194
Generates a random noise sound with the help of rand() function.
Definition SoundGenerator.h:333
WhiteNoiseGenerator(T amplitude=32767)
the scale defines the max value which is generated
Definition SoundGenerator.h:336
T readSample()
Provides a single sample.
Definition SoundGenerator.h:339
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10
Basic Audio information which drives e.g. I2S.
Definition AudioTypes.h:53
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition AudioTypes.h:55
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition AudioTypes.h:57
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition AudioTypes.h:59