Skip to content

Commit 2b3da4e

Browse files
committed
remove copy2() from AudioCopy
1 parent dd5ef51 commit 2b3da4e

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed

examples/examples-stream/streams-memory_raw-i2s/streams-memory_raw-i2s.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515

16-
uint8_t channels = 2;
16+
uint8_t channels = 1;
1717
uint16_t sample_rate = 22050;
1818

1919
I2SStream i2s; // Output to I2S
@@ -34,7 +34,7 @@ void setup(){
3434
}
3535

3636
void loop(){
37-
if (!copier.copy2()){
37+
if (!copier.copy()){
3838
i2s.end();
3939
stop();
4040
}

src/AudioTools/AudioCopy.h

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class StreamCopyT {
8686
delete[] buffer;
8787
}
8888

89-
// copies the data from one channel from the source to 2 channels on the destination - the result is in bytes
89+
// copies the data from the source to the destination - the result is in bytes
9090
inline size_t copy(){
9191
TRACED();
9292
// if not initialized we do nothing
@@ -144,44 +144,6 @@ class StreamCopyT {
144144
}
145145

146146

147-
// copies the data from one channel from the source to 2 channels on the destination - the result is in bytes
148-
size_t copy2(){
149-
if (from==nullptr || to == nullptr)
150-
return 0;
151-
size_t result = 0;
152-
size_t delayCount = 0;
153-
size_t bytes_read;
154-
size_t len = available();
155-
size_t bytes_to_read;
156-
157-
if (len>0){
158-
bytes_to_read = min(len, static_cast<size_t>(buffer_size / 2));
159-
size_t samples = bytes_to_read / sizeof(T);
160-
bytes_to_read = samples * sizeof(T);
161-
162-
T temp_data[samples];
163-
bytes_read = from->readBytes((uint8_t*)temp_data, bytes_to_read);
164-
// callback with unconverted data
165-
if (onWrite!=nullptr) onWrite(onWriteObj, temp_data, bytes_read);
166-
167-
T* bufferT = (T*) buffer;
168-
for (size_t j=0;j<samples;j++){
169-
*bufferT = temp_data[j];
170-
bufferT++;
171-
*bufferT = temp_data[j];
172-
bufferT++;
173-
}
174-
result = write(samples * sizeof(T)*2, delayCount);
175-
#ifndef COPY_LOG_OFF
176-
LOGI("StreamCopy::copy %u -> %u bytes - in %d hops", (unsigned int)bytes_to_read, (unsigned int)result, delayCount);
177-
#endif
178-
CHECK_MEMORY();
179-
} else {
180-
delay(delay_on_no_data);
181-
}
182-
return result;
183-
}
184-
185147
/// available bytes in the data source
186148
int available() {
187149
return from == nullptr ? 0 : from->available();
@@ -370,10 +332,11 @@ class StreamCopy : public StreamCopyT<uint8_t> {
370332
return result;
371333
}
372334

373-
inline size_t copy() {
335+
/// Copies all bytes from the input to the output
336+
inline size_t copy() {
374337
return StreamCopyT<uint8_t>::copy();
375338
}
376-
339+
377340
int available() {
378341
return from == nullptr ? 0 : from->available();
379342
}

0 commit comments

Comments
 (0)