Skip to content

Commit ae4df9c

Browse files
committed
R2ROutput logging
1 parent 734b435 commit ae4df9c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/AudioLibs/R2ROutput.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ class R2ROutput : public AudioOutput {
3535
}
3636

3737
bool begin(R2RConfig c) {
38+
TRACED();
3839
cfg = c;
3940
rcfg = c;
4041
return begin();
4142
}
4243

4344
bool begin() override {
45+
TRACED();
4446
if (cfg.channels == 0 || cfg.channels > 2) {
4547
LOGE("channels is %d", cfg.channels);
4648
return false;
@@ -56,28 +58,34 @@ class R2ROutput : public AudioOutput {
5658
}
5759
setupPins();
5860
timer.setCallbackParameter(this);
61+
timer.setIsSave(true);
5962
return timer.begin(r2r_timer_callback, cfg.sample_rate, HZ);
6063
}
6164

6265
size_t write(const uint8_t *data, size_t len) override {
6366
size_t result = buffer.writeArray(data, len);
6467
// activate output when buffer is full
6568
if (!is_active && buffer.isFull()) {
69+
LOGI("is_active = true");
6670
is_active = true;
6771
}
6872
return result;
6973
}
7074

7175
protected:
7276
TimerAlarmRepeating timer;
73-
NBuffer<uint8_t> buffer{1024, 2};
77+
// Double buffer
78+
NBuffer<uint8_t> buffer{DEFAULT_BUFFER_SIZE, 2};
7479
R2RConfig rcfg;
7580

7681
void setupPins() {
82+
TRACED();
7783
for (int j = 0; j < rcfg.channel1_pins.size(); j++) {
84+
LOGI("Setup pin %d", rcfg.channel1_pins[j]);
7885
pinMode(rcfg.channel1_pins[j], OUTPUT);
7986
}
8087
for (int j = 0; j < rcfg.channel2_pins.size(); j++) {
88+
LOGI("Setup pin %d", rcfg.channel1_pins[j]);
8189
pinMode(rcfg.channel2_pins[j], OUTPUT);
8290
}
8391
}
@@ -98,7 +106,7 @@ class R2ROutput : public AudioOutput {
98106
template <typename T>
99107
void writeValueT(int channel) {
100108
// don't do anything if we do not have enough data
101-
if (buffer.available()< sizeof(T)) return;
109+
if (buffer.available() < sizeof(T)) return;
102110

103111
// get next value from buffer
104112
T value = 0;
@@ -107,16 +115,20 @@ class R2ROutput : public AudioOutput {
107115
unsigned uvalue = (int)value + NumberConverter::maxValueT<T>() + 1;
108116
// scale value
109117
uvalue = uvalue >> ((sizeof(T) * 8) - rcfg.channel1_pins.size());
118+
//Serial.println(uvalue);
119+
110120
// output pins
111121
switch (channel) {
112122
case 0:
113123
for (int j = 0; j < rcfg.channel1_pins.size(); j++) {
114-
digitalWrite(rcfg.channel1_pins[j], (uvalue >> j) & 1);
124+
int pin = rcfg.channel1_pins[j];
125+
if (pin >= 0) digitalWrite(pin, (uvalue >> j) & 1);
115126
}
116127
break;
117128
case 1:
118129
for (int j = 0; j < rcfg.channel2_pins.size(); j++) {
119-
digitalWrite(rcfg.channel2_pins[j], (uvalue >> j) & 1);
130+
int pin = rcfg.channel2_pins[j];
131+
if (pin >= 0) digitalWrite(pin, (uvalue >> j) & 1);
120132
}
121133
break;
122134
}

0 commit comments

Comments
 (0)