Skip to content

Commit ab9b93c

Browse files
committed
R2ROutput use Vector instead of std::vector
1 parent c9687b4 commit ab9b93c

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

examples/examples-stream/streams-generator-r2r/streams-generator-r2r.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SineWaveGenerator<int16_t> sineWave; // subclass of SoundG
1313
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
1414
R2ROutput out;
1515
StreamCopy copier(out, sound); // copies sound into i2s
16+
const int pins1[] = {13,12,14,27,26,25, 33, 32}; // r2r pins 32 is least significant
1617

1718
// Arduino Setup
1819
void setup(void) {
@@ -26,7 +27,7 @@ void setup(void) {
2627
auto config = out.defaultConfig();
2728
config.copyFrom(info);
2829
// 8 pins for 8 bit DAC for channel 1
29-
config.channel1_pins = {13,12,14,27,26,25, 33, 32};
30+
config.channel1_pins = pins1;
3031
// channel 2 would be config.channel2_pins
3132
out.begin(config);
3233

src/AudioBasic/Collections/Vector.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ class Vector {
136136
this->len = copyFrom.size();
137137
}
138138

139+
/// convert from c array
140+
template <typename TT, int N>
141+
Vector(TT (&a)[N]) {
142+
resize_internal(N, false);
143+
for (int j = 0; j < N; j++) {
144+
p_data[j] = a[j];
145+
}
146+
this->len = N;
147+
}
148+
139149
/// copy operator
140150
Vector<T> &operator=(Vector<T> &copyFrom) {
141151
resize_internal(copyFrom.size(), false);

src/AudioLibs/R2ROutput.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
#include "AudioTools/AudioLogger.h"
66
#include "AudioTools/AudioOutput.h"
77
#include "AudioTools/Buffers.h"
8-
#include "vector"
9-
8+
#include "AudioBasic/Collections/Vector.h"
109
namespace audio_tools {
1110

1211
/**
@@ -18,8 +17,8 @@ namespace audio_tools {
1817

1918
class R2RDriverBase {
2019
public:
21-
virtual void setupPins(std::vector<int> &channel1_pins,
22-
std::vector<int> &channel2_pins) = 0;
20+
virtual void setupPins(Vector<int> &channel1_pins,
21+
Vector<int> &channel2_pins) = 0;
2322

2423
virtual void writePins(int channels, int channel, unsigned uvalue) = 0;
2524
};
@@ -34,8 +33,8 @@ class R2RDriverBase {
3433

3534
class R2RDriver : public R2RDriverBase {
3635
public:
37-
void setupPins(std::vector<int> &channel1_pins,
38-
std::vector<int> &channel2_pins) override {
36+
void setupPins(Vector<int> &channel1_pins,
37+
Vector<int> &channel2_pins) override {
3938
TRACED();
4039
p_channel1_pins = &channel1_pins;
4140
p_channel2_pins = &channel2_pins;
@@ -68,9 +67,8 @@ class R2RDriver : public R2RDriverBase {
6867
}
6968

7069
protected:
71-
std::vector<int> *p_channel1_pins = nullptr;
72-
std::vector<int> *p_channel2_pins = nullptr;
73-
70+
Vector<int> *p_channel1_pins = nullptr;
71+
Vector<int> *p_channel2_pins = nullptr;
7472
} r2r_driver;
7573

7674
/**
@@ -81,8 +79,8 @@ class R2RDriver : public R2RDriverBase {
8179

8280
class R2RConfig : public AudioInfo {
8381
public:
84-
std::vector<int> channel1_pins;
85-
std::vector<int> channel2_pins;
82+
Vector<int> channel1_pins;
83+
Vector<int> channel2_pins;
8684
uint16_t buffer_size = DEFAULT_BUFFER_SIZE;
8785
uint16_t buffer_count = 2; // double buffer
8886
R2RDriverBase *driver = &r2r_driver; // by default use Arduino driver

0 commit comments

Comments
 (0)