Arduino STK  4.6.2
MemoryFS.h
1 #include "Stk.h"
2 #ifdef __RAW_ARRAYS__
3 #ifndef MEMORYFS_H
4 #define MEMORYFS_H
5 
6 #include "Stk.h"
7 #if defined(ESP32)
8 #include "esp_system.h"
9 #include "esp32-hal-log.h"
10 #include "pgmspace.h"
11 #elif defined(ESP8266)
12 #include "pgmspace.h"
13 #elif defined(ARDUINO) && __has_include(<pgmspace.h>)
14 #include <pgmspace.h>
15 #endif
16 
17 #define VFS_INC_SIZE 10
18 #ifndef MIN
19 #define MIN(a,b) ((a) < (b) ? (a) : (b))
20 #endif
21 
22 namespace stk {
23 
25 struct VFS_FD {
26  const char *name;
27  const unsigned char *data;
28  size_t size; // in bytes
29  bool is_open;
30 };
31 
32 /***************************************************/
45 /***************************************************/
46 class MemoryFS {
47  public:
48  MemoryFS(const unsigned char *raw=NULL, unsigned int size=0, int bytesPerSample=2, bool swapBytes=true);
49  MemoryFS (const char* fileName);
50 
52  static VFS_FD * registerFile(const char* fileName, const unsigned char *raw, unsigned int size);
54  bool open(const char* fileName, int bytesPerSample=2);
58  size_t getSize();
60  void close();
62  bool isOpen();
64  bool fileRead( StkFrames& buffer, unsigned long startFrame, bool doNormalize) ;
65 
66  size_t current_pos_; // current read position in the memory in samples
67 
68 
69  protected:
70  static int findByName(const char * path);
71  VFS_FD *fd;
72  long fileSize_;
73  bool swapBytes;
74 };
75 
76 }
77 
78 #endif
79 #endif
STK in memory File An instance is representing an individual memory array which can be registered wit...
Definition: MemoryFS.h:46
VFS_FD * getFD()
Returns a descriptor with additional information.
static VFS_FD * registerFile(const char *fileName, const unsigned char *raw, unsigned int size)
makes the file available so that the open (by name) operation is working
void close()
sets to open flag to false
size_t getSize()
Determines the size (in samples)
bool fileRead(StkFrames &buffer, unsigned long startFrame, bool doNormalize)
Reads the data into the buffer at the indicated start frame.
bool open(const char *fileName, int bytesPerSample=2)
opens the indicated file
bool isOpen()
checks if the file has been opened
An STK class to handle vectorized audio data.
Definition: Stk.h:287
The STK namespace.
Definition: ADSR.h:8
Simulated File Descriptor of registered virtual "Memory" files.
Definition: MemoryFS.h:25