R2ROutput use Vector instead of std::vector

This commit is contained in:
pschatzmann 2024-09-01 13:27:33 +02:00
parent c9687b44a4
commit ab9b93cc75
3 changed files with 21 additions and 12 deletions

View File

@ -13,6 +13,7 @@ SineWaveGenerator<int16_t> sineWave; // subclass of SoundG
GeneratedSoundStream<int16_t> 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);

View File

@ -136,6 +136,16 @@ class Vector {
this->len = copyFrom.size();
}
/// convert from c array
template <typename TT, int N>
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<T> &operator=(Vector<T> &copyFrom) {
resize_internal(copyFrom.size(), false);

View File

@ -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<int> &channel1_pins,
std::vector<int> &channel2_pins) = 0;
virtual void setupPins(Vector<int> &channel1_pins,
Vector<int> &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<int> &channel1_pins,
std::vector<int> &channel2_pins) override {
void setupPins(Vector<int> &channel1_pins,
Vector<int> &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<int> *p_channel1_pins = nullptr;
std::vector<int> *p_channel2_pins = nullptr;
Vector<int> *p_channel1_pins = nullptr;
Vector<int> *p_channel2_pins = nullptr;
} r2r_driver;
/**
@ -81,8 +79,8 @@ class R2RDriver : public R2RDriverBase {
class R2RConfig : public AudioInfo {
public:
std::vector<int> channel1_pins;
std::vector<int> channel2_pins;
Vector<int> channel1_pins;
Vector<int> 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