diff --git a/examples/examples-stream/streams-generator-r2r/streams-generator-r2r.ino b/examples/examples-stream/streams-generator-r2r/streams-generator-r2r.ino index 818e02530..36da48321 100644 --- a/examples/examples-stream/streams-generator-r2r/streams-generator-r2r.ino +++ b/examples/examples-stream/streams-generator-r2r/streams-generator-r2r.ino @@ -13,6 +13,7 @@ SineWaveGenerator sineWave; // subclass of SoundG GeneratedSoundStream sound(sineWave); // Stream generated from sine wave R2ROutput out; StreamCopy copier(out, sound); // copies sound into i2s +const int pins1[] = {13,12,14,27,26,25, 33, 32}; // r2r pins 32 is least significant // Arduino Setup void setup(void) { @@ -26,7 +27,7 @@ void setup(void) { auto config = out.defaultConfig(); config.copyFrom(info); // 8 pins for 8 bit DAC for channel 1 - config.channel1_pins = {13,12,14,27,26,25, 33, 32}; + config.channel1_pins = pins1; // channel 2 would be config.channel2_pins out.begin(config); diff --git a/src/AudioBasic/Collections/Vector.h b/src/AudioBasic/Collections/Vector.h index f69825126..d2a750fa4 100644 --- a/src/AudioBasic/Collections/Vector.h +++ b/src/AudioBasic/Collections/Vector.h @@ -136,6 +136,16 @@ class Vector { this->len = copyFrom.size(); } + /// convert from c array + template + Vector(TT (&a)[N]) { + resize_internal(N, false); + for (int j = 0; j < N; j++) { + p_data[j] = a[j]; + } + this->len = N; + } + /// copy operator Vector &operator=(Vector ©From) { resize_internal(copyFrom.size(), false); diff --git a/src/AudioLibs/R2ROutput.h b/src/AudioLibs/R2ROutput.h index c5f608f1a..bfaac0d75 100644 --- a/src/AudioLibs/R2ROutput.h +++ b/src/AudioLibs/R2ROutput.h @@ -5,8 +5,7 @@ #include "AudioTools/AudioLogger.h" #include "AudioTools/AudioOutput.h" #include "AudioTools/Buffers.h" -#include "vector" - +#include "AudioBasic/Collections/Vector.h" namespace audio_tools { /** @@ -18,8 +17,8 @@ namespace audio_tools { class R2RDriverBase { public: - virtual void setupPins(std::vector &channel1_pins, - std::vector &channel2_pins) = 0; + virtual void setupPins(Vector &channel1_pins, + Vector &channel2_pins) = 0; virtual void writePins(int channels, int channel, unsigned uvalue) = 0; }; @@ -34,8 +33,8 @@ class R2RDriverBase { class R2RDriver : public R2RDriverBase { public: - void setupPins(std::vector &channel1_pins, - std::vector &channel2_pins) override { + void setupPins(Vector &channel1_pins, + Vector &channel2_pins) override { TRACED(); p_channel1_pins = &channel1_pins; p_channel2_pins = &channel2_pins; @@ -68,9 +67,8 @@ class R2RDriver : public R2RDriverBase { } protected: - std::vector *p_channel1_pins = nullptr; - std::vector *p_channel2_pins = nullptr; - + Vector *p_channel1_pins = nullptr; + Vector *p_channel2_pins = nullptr; } r2r_driver; /** @@ -81,8 +79,8 @@ class R2RDriver : public R2RDriverBase { class R2RConfig : public AudioInfo { public: - std::vector channel1_pins; - std::vector channel2_pins; + Vector channel1_pins; + Vector channel2_pins; uint16_t buffer_size = DEFAULT_BUFFER_SIZE; uint16_t buffer_count = 2; // double buffer R2RDriverBase *driver = &r2r_driver; // by default use Arduino driver