Skip to content

Commit 122aaee

Browse files
committed
ESP8266 support
1 parent 03e3287 commit 122aaee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+89
-51
lines changed

examples/PerformanceInstruments/PerformanceInstruments.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ InstrumentInfo instrumentArray[] = {
2828
{"BlowHole", []() { return new BlowHole(200); }},
2929
{"Bowed", []() { return new Bowed(); }},
3030
{"Clarinet", []() { return new Clarinet(); }},
31-
{"Drummer", []() { return new Drummer(); }}, // comment out for STM32
31+
{"Drummer", []() { return new Drummer(); }}, // comment out for STM32 or ESP8266
3232
{"Flute", []() { return new Flute(200); }},
3333
{"Rhodey", []() { return new Rhodey(); }},
3434
{"TubeBell", []() { return new TubeBell(); }},
@@ -62,6 +62,8 @@ void measure(const char*title, Instrmnt *src) {
6262
// pull samples for 10 seconds at 44100
6363
for (int j=0;j<sampleRate*sec;j++){
6464
float f = src->tick();
65+
// for ESP8266 to feed the watchdog
66+
if (j%5000==0) yield();
6567
}
6668
snprintf(msg, 80, "%s: %f sec",title, static_cast<float>(millis()-start)/1000.0);
6769
Serial.println(msg);

src/ArdConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#if defined(ESP32)
1717
// #define __MIDI__ // support Midi
1818
#define __I2S__
19+
#define __NO_EXCEPTIONS__
1920
#define __STREAMS__ // output to Ardiono Streams
2021
#define __RTOS__ // supports Free RTOS
2122
#define __LWIP__ // use lwip socket implementation
@@ -61,6 +62,7 @@
6162
// #define __MIDI__ // support Midi
6263
#define __ARDUINO__ // exclude standard c++ h files
6364
#define __STREAMS__ // output to Ardiono Streams
65+
#define _STK_DEBUG_
6466
// #define __NO_EXCEPTIONS__ // comment out exceptions
6567
// #define __NO_FSTREAM__ // No Messanger, MidiFileIn and Skini and FileRead
6668
// #define __NO_RT__ // no STK RT functions

src/MemoryFS.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace stk {
99
//! Simulated File Descriptor of registered virtual "Memory" files
1010
struct 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";
2425
static const int registry_size = 30;
2526
VFS_FD **registry = nullptr;
2627
int registry_last_entry = 0;
27-
bool registry_use_ram = false;
28+
bool registry_use_ram = USE_RAM_DEFAUT;
2829

2930
MemoryFS :: 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;

src/MemoryFS.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
# include <pgmspace.h>
1919
#endif
2020

21+
#ifndef USE_RAM_DEFAUT
22+
# define USE_RAM_DEFAUT false
23+
#endif
24+
2125
#define VFS_INC_SIZE 10
2226
#ifndef MIN
2327
#define MIN(a,b) ((a) < (b) ? (a) : (b))

src/Stk.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ void StkFrames :: resize( size_t nFrames, unsigned int nChannels )
314314
if ( size_ > bufferSize_ ) {
315315
if ( data_ ) free( data_ );
316316
data_ = (StkFloat *) malloc( size_ * sizeof( StkFloat ) );
317+
if (data_==nullptr){
318+
STK_LOGE("resize: Not enough memory for %lu frames", nFrames);
319+
}
317320
#if defined(_STK_DEBUG_)
318321
if ( data_ == NULL ) {
319322
std::string error = "StkFrames::resize: memory allocation error!";
@@ -327,8 +330,9 @@ void StkFrames :: resize( size_t nFrames, unsigned int nChannels )
327330
void StkFrames :: resize( size_t nFrames, unsigned int nChannels, StkFloat value )
328331
{
329332
this->resize( nFrames, nChannels );
330-
331-
for ( size_t i=0; i<size_; i++ ) data_[i] = value;
333+
if (data_ !=nullptr) {
334+
for ( size_t i=0; i<size_; i++ ) data_[i] = value;
335+
}
332336
}
333337

334338
StkFrames& StkFrames::getChannel(unsigned int sourceChannel,StkFrames& destinationFrames, unsigned int destinationChannel) const

src/Stk.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define STK_STK_H
33

44
#include "ArdConfig.h"
5+
#include "ArdStkLogger.h"
56
#include <string>
67
#include <cstring>
78
#include <vector>
@@ -143,7 +144,6 @@ class StkError
143144
class Stk
144145
{
145146
public:
146-
147147
typedef unsigned long StkFormat;
148148
static const StkFormat STK_SINT8; /*!< -128 to +127 */
149149
static const StkFormat STK_SINT16; /*!< -32768 to +32767 */
@@ -432,6 +432,7 @@ class StkFrames
432432
StkFloat dataRate( void ) const { return dataRate_; };
433433

434434
private:
435+
StkFloat EMPTY_RESULT = 0.0f; // returned result if data_ is null
435436

436437
StkFloat *data_;
437438
StkFloat dataRate_;
@@ -458,7 +459,7 @@ inline StkFloat& StkFrames :: operator[] ( size_t n )
458459
}
459460
#endif
460461

461-
return data_[n];
462+
return data_==nullptr ? EMPTY_RESULT : data_[n];
462463
}
463464

464465
inline StkFloat StkFrames :: operator[] ( size_t n ) const
@@ -471,7 +472,7 @@ inline StkFloat StkFrames :: operator[] ( size_t n ) const
471472
}
472473
#endif
473474

474-
return data_[n];
475+
return data_==nullptr ? EMPTY_RESULT : data_[n];
475476
}
476477

477478
inline StkFloat& StkFrames :: operator() ( size_t frame, unsigned int channel )
@@ -484,7 +485,7 @@ inline StkFloat& StkFrames :: operator() ( size_t frame, unsigned int channel )
484485
}
485486
#endif
486487

487-
return data_[ frame * nChannels_ + channel ];
488+
return data_==nullptr? EMPTY_RESULT : data_[ frame * nChannels_ + channel ];
488489
}
489490

490491
inline StkFloat StkFrames :: operator() ( size_t frame, unsigned int channel ) const
@@ -497,7 +498,7 @@ inline StkFloat StkFrames :: operator() ( size_t frame, unsigned int channel ) c
497498
}
498499
#endif
499500

500-
return data_[ frame * nChannels_ + channel ];
501+
return data_==nullptr ? EMPTY_RESULT : data_[ frame * nChannels_ + channel ];
501502
}
502503

503504
inline StkFrames StkFrames::operator+(const StkFrames &f) const

src/raw/all.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#pragma once
2-
2+
#if defined(IS_DESKTOP)
3+
# define PROGMEM
4+
#else
5+
# include "pgmspace.h"
6+
#endif
37
extern const unsigned char bassdrum_raw[];
48
extern const unsigned char britestk_raw[];
59
extern const unsigned char cowbell1_raw[];
6-
extern const unsigned char crashcym_raw[] ;
10+
extern const unsigned char crashcym_raw[];
711
extern const unsigned char dope_raw[];
812
extern const unsigned char eee_raw[];
913
extern const unsigned char fwavblnk_raw[];

src/raw/zz-raw-bassdrum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "all.h"
22

3-
const unsigned char bassdrum_raw[] = {
3+
const unsigned char bassdrum_raw[] PROGMEM = {
44
0x00, 0x28, 0x00, 0x50, 0x00, 0xd7, 0x01, 0xc3, 0x02, 0xe3, 0x03, 0xf9,
55
0x04, 0xbf, 0x05, 0x33, 0x05, 0xc9, 0x06, 0xe6, 0x08, 0x92, 0x0a, 0xc2,
66
0x0c, 0xb9, 0x0d, 0xf5, 0x0f, 0x29, 0x10, 0x54, 0x10, 0xf2, 0x11, 0xa3,

src/raw/zz-raw-britestk.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "all.h"
2-
const unsigned char britestk_raw[] = {
2+
const unsigned char britestk_raw[] PROGMEM = {
33
0x01, 0x62, 0x05, 0x04, 0xf4, 0x9d, 0x0e, 0x3b, 0xff, 0x79, 0x01, 0x02,
44
0xff, 0x54, 0xf7, 0x7e, 0x03, 0xa5, 0xfd, 0x79, 0x09, 0xf5, 0xfb, 0xe9,
55
0x02, 0xaa, 0xf4, 0x5b, 0x0f, 0xcd, 0xeb, 0x84, 0x0c, 0x41, 0xfd, 0x3d,

src/raw/zz-raw-cowbell1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "all.h"
2-
const unsigned char cowbell1_raw[] = {
2+
const unsigned char cowbell1_raw[] PROGMEM = {
33
0x00, 0x00, 0x00, 0x75, 0x04, 0x0c, 0x02, 0xed, 0x01, 0x4a, 0xff, 0xc9,
44
0xff, 0x08, 0x01, 0x23, 0xfd, 0xad, 0x04, 0x98, 0xf9, 0xf6, 0xfd, 0x77,
55
0x06, 0xe4, 0x00, 0x78, 0xf8, 0x2f, 0xfc, 0xd9, 0xfa, 0xe5, 0x09, 0xdd,

0 commit comments

Comments
 (0)