Skip to content

Commit 4fe44c2

Browse files
committed
Compile errors file based buffers
1 parent 9deb6f6 commit 4fe44c2

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

examples/tests/performance/file-speeds-vfssd/file-speeds-vfssd.ino

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#define AUDIOBOARD_SD
22
#include "AudioTools.h"
33
#include "AudioTools/Disk/VFS_SDSPI.h"
4-
#include "AudioTools/Disk/VFS_SDMMC.h"
54
#include "AudioTools/Disk/VFSFile.h"
65

76
#define PIN_AUDIO_KIT_SD_CARD_CS 13
@@ -73,7 +72,6 @@ void setup() {
7372
Serial.begin(115200);
7473

7574
VFS_SDSPI sd;
76-
//VFS_SDMMC sdmmc;
7775

7876
data = new uint8_t[max_len];
7977
assert(data!=nullptr);

examples/tests/performance/file-speeds-vfssdmmc/file-speeds-vfssdmmc.ino

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#define AUDIOBOARD_SD
22
#include "AudioTools.h"
3-
#include "AudioTools/Disk/VFS_SDSPI.h"
4-
#include "AudioTools/Disk/VFS_SDMMC.h"
53
#include "AudioTools/Disk/VFSFile.h"
64

7-
#define PIN_AUDIO_KIT_SD_CARD_CS 13
8-
#define PIN_AUDIO_KIT_SD_CARD_MISO 2
9-
#define PIN_AUDIO_KIT_SD_CARD_MOSI 15
10-
#define PIN_AUDIO_KIT_SD_CARD_CLK 14
115

126
const size_t max_len = 1024 * 100;
137
uint8_t *data = nullptr;
@@ -72,7 +66,6 @@ void testFS(const char* name, SD& sd, Open write, Open read) {
7266
void setup() {
7367
Serial.begin(115200);
7468

75-
VFS_SDSPI sd;
7669
VFS_SDMMC sdmmc;
7770

7871
data = new uint8_t[max_len];

src/AudioTools/CoreAudio/Buffers.h

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class BaseBuffer {
8585
virtual bool peek(T &result) = 0;
8686

8787
/// checks if the buffer is full
88-
virtual bool isFull() = 0;
88+
virtual bool isFull() { return availableForWrite() == 0; }
8989

9090
bool isEmpty() { return available() == 0; }
9191

@@ -409,7 +409,7 @@ class RingBuffer : public BaseBuffer<T> {
409409
*
410410
* @ingroup buffers
411411
* @tparam File: file class
412-
* @tparam T: the buffered object type
412+
* @tparam T: the buffered object type
413413
*/
414414
template <class File, typename T>
415415
class RingBufferFile : public BaseBuffer<T> {
@@ -548,7 +548,8 @@ class RingBufferFile : public BaseBuffer<T> {
548548
int len1 = 0; // length of second part on overflow
549549
};
550550

551-
/// Get positons and sizes to handle overflow wrapping to prevent writing past max_size
551+
/// Get positons and sizes to handle overflow wrapping to prevent writing past
552+
/// max_size
552553
OffsetInfo getOffset(int pos, int len) {
553554
OffsetInfo result;
554555
result.pos = pos;
@@ -596,7 +597,7 @@ class RingBufferFile : public BaseBuffer<T> {
596597
int file_read(T *result, int count) {
597598
LOGD("file_read: %d", count);
598599
int read_bytes = count * sizeof(T);
599-
int result_bytes = p_file->read((uint8_t *)result, read_bytes);
600+
int result_bytes = p_file->readBytes((char *)result, read_bytes);
600601
int result_count = result_bytes / sizeof(T);
601602
if (result_count != count) {
602603
LOGE("readBytes: %d -> %d", read_bytes, result_bytes);
@@ -844,6 +845,7 @@ class NBuffer : public BaseBuffer<T> {
844845
*/
845846
template <class File, typename T>
846847
class NBufferFile : public BaseBuffer<T> {
848+
public:
847849
/// Provide the file size in objects!
848850
NBufferFile(int fileSize) { number_of_objects_per_file = fileSize; }
849851
/// RAII close the files
@@ -868,7 +870,7 @@ class NBufferFile : public BaseBuffer<T> {
868870
return true;
869871
}
870872

871-
bool read(T &result) override { return readArray(result, 1) == 1; }
873+
bool read(T &result) override { return readArray(&result, 1) == 1; }
872874

873875
int readArray(T data[], int len) override {
874876
// make sure we have a read file
@@ -900,7 +902,7 @@ class NBufferFile : public BaseBuffer<T> {
900902

901903
bool write(T sample) override { return writeArray(&sample, 1) == 1; }
902904

903-
int writeArray(T data[], int len) override {
905+
int writeArray(const T data[], int len) override {
904906
if (!write_file || write_file.size() + len > number_of_objects_per_file) {
905907
// moved to filled files
906908
if (write_file) {
@@ -927,7 +929,7 @@ class NBufferFile : public BaseBuffer<T> {
927929
write_file.available() + open_current;
928930
}
929931

930-
int size() { return number_of_objects_per_file * file_count; }
932+
size_t size() override { return number_of_objects_per_file * file_count; }
931933

932934
/// clean up files
933935
void end() {
@@ -943,6 +945,26 @@ class NBufferFile : public BaseBuffer<T> {
943945
file_delete_callback = cb;
944946
}
945947

948+
void reset() {
949+
if (read_file) {
950+
read_file.seek(0);
951+
empty_files.enqueue(read_file);
952+
read_file = empty;
953+
}
954+
if (write_file) {
955+
write_file.seek(0);
956+
empty_files.enqueue(write_file);
957+
write_file = empty;
958+
}
959+
File file;
960+
while (filled_files.dequeue(file)) {
961+
file.seek(0);
962+
empty_files.enqueue(file);
963+
}
964+
}
965+
/// not supported
966+
T *address() { return nullptr; }
967+
946968
protected:
947969
Queue<File> empty_files;
948970
Queue<File> filled_files;

src/AudioTools/Disk/VFSFile.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,15 @@ class VFSFile : public Stream {
9393

9494
virtual void flush() override { stream.flush(); }
9595

96-
virtual void write(uint8_t* str, int len) {
97-
stream.write((const char*)str, len);
96+
97+
virtual size_t write(uint8_t* str, size_t len) {
98+
stream.write((const char*)str, len);
99+
return len;
100+
}
101+
102+
virtual size_t write(const uint8_t* str, size_t len) {
103+
stream.write((const char*)str, len);
104+
return len;
98105
}
99106

100107
virtual size_t write(int32_t value) {
@@ -114,6 +121,10 @@ class VFSFile : public Stream {
114121

115122
virtual int read() override { return stream.get(); }
116123

124+
virtual size_t readBytes(char* data, size_t len) override {
125+
return readBytes((uint8_t*)data, len);
126+
}
127+
117128
virtual size_t readBytes(uint8_t* data, size_t len) override {
118129
stream.read((char*)data, len);
119130
return stream ? len : stream.gcount();

0 commit comments

Comments
 (0)