@@ -9,6 +9,7 @@ namespace stk {
99// ! Simulated File Descriptor of registered virtual "Memory" files
1010struct VFS_FD {
1111 VFS_FD () = default ;
12+
1213 ~VFS_FD (){
1314 if (is_ram) delete[] data;
1415 }
@@ -24,7 +25,7 @@ const char *APP_VFS ="MemoryFS";
2425static const int registry_size = 30 ;
2526VFS_FD **registry = nullptr ;
2627int registry_last_entry = 0 ;
27- bool registry_use_ram = false ;
28+ bool registry_use_ram = USE_RAM_DEFAUT ;
2829
2930MemoryFS :: MemoryFS(const unsigned char *raw, unsigned int size, int bytesPerSample, bool swapBytes) {
3031 if (raw!=nullptr ){
@@ -80,6 +81,11 @@ bool MemoryFS :: fileRead( StkFrames& frames, unsigned long startFrame, bool doN
8081 // data is available as array of uint16_t
8182 bool is_finished = false ;
8283
84+ if (data_==nullptr ){
85+ STK_LOGE (" data is null" );
86+ return false ;
87+ }
88+
8389 // calculate max size of next batch
8490 this ->current_pos_ = startFrame;
8591 int result_size = MIN (frames.size () , this ->getSize () - startFrame);
@@ -89,6 +95,20 @@ bool MemoryFS :: fileRead( StkFrames& frames, unsigned long startFrame, bool doN
8995 frames.resize ( result_size, 1 );
9096 }
9197
98+ #ifdef ESP8266
99+ // we need to access the progmem on 4byte boundries
100+ for (int j=0 ; j<result_size; j+=2 ) {
101+ int16_t tmp[2 ];
102+ memcmp_P (tmp,(PGM_P) data_+j, 4 );
103+
104+ if (this ->swapBytes ){
105+ Stk::swap16 ((unsigned char *) &tmp[0 ]);
106+ Stk::swap16 ((unsigned char *) &tmp[1 ]);
107+ }
108+ frames[j] = static_cast <float >(tmp[0 ]) / 32768 .0f ;
109+ frames[j+1 ] = static_cast <float >(tmp[1 ]) / 32768 .0f ;
110+ }
111+ #else
92112 for (int j=0 ; j<result_size; j++) {
93113 int16_t tmp = data_[current_pos_];
94114 if (this ->swapBytes ){
@@ -97,6 +117,7 @@ bool MemoryFS :: fileRead( StkFrames& frames, unsigned long startFrame, bool doN
97117 frames[j] = static_cast <float >(tmp) / 32768 .0f ;
98118 this ->current_pos_ ++;
99119 }
120+ #endif
100121
101122 } else {
102123 is_finished = true ;
0 commit comments