Skip to content

Commit a2d7ae0

Browse files
committed
Resolve conflicts for PI and support compile for RP2040
1 parent 9ebec50 commit a2d7ae0

28 files changed

+65
-166
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"concepts": "cpp",
8080
"memory_resource": "cpp",
8181
"ranges": "cpp",
82-
"stop_token": "cpp"
82+
"stop_token": "cpp",
83+
"math": "cpp"
8384
}
8485
}

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This project has been implemented as Arduino Library and runs on ESP32 processor
1313

1414
## Further information
1515

16-
The oringial STK library is asking to include each used header file separately. For convinence I have added the StkAll.h which provides all header files.
16+
The oringial STK library is asking to include each used header file separately. For convinence I have added the StkAll.h which provides all header files. It also provides the related use namespace.
1717

1818
Further information can be found in my Blogs
1919
- [Overview](https://www.pschatzmann.ch/home/2020/09/24/the-synthesis-toolkit-skt-library-for-the-arduino-esp32/)
@@ -23,6 +23,7 @@ Further information can be found in my Blogs
2323

2424

2525
## Installation
26+
2627
Download the project as zip and install the file in the Arduino IDE via -> Sketch -> Include Library -> Add ZIP Library or execute the following command in the Arduino Library Folder
2728

2829
```
@@ -32,7 +33,9 @@ git clone https://github.com/pschatzmann/Arduino-STK.git
3233
## Supported Processors
3334

3435
- ESP32 - The deveopment and testing has been done with the ESP32 so this will be the most stable and complete platform.
35-
- ESP8266 - I managed to have the code base compiling with the ESP8266 as well. This environment does not support Bluetooth.
36+
- I managed to have the code to compile with the following processors the as well:
37+
- ESP8266
38+
- RP2040
3639

3740
You can consult the ArdConig.h file for the available functionality for your processor!
3841

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ sentence=The Synthesis ToolKit in C++ (STK)
66
paragraph=Syntheizer which plays on an I2S DAC or a software-driven delta-sigma DAC and 1-transistor amplifier.
77
category=Signal Input/Output
88
url=https://github.com/pschatzmann/Arduino-STK
9-
architectures=esp8266,esp32
9+
architectures=esp8266,esp32,rp2040
1010

src/ArdConfig.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "ArdConfig.h"
2+
3+
#ifdef STK_ERROR_MSG_LEN
4+
char stk_error_msg[STK_ERROR_MSG_LEN];
5+
#endif
6+
7+
8+
#ifdef ARDUINO_ARCH_RP2040
9+
extern "C" void __sync_synchronize() {
10+
}
11+
#endif

src/ArdConfig.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#pragma once
12
/**
23
ArdConfig.h
34
@@ -18,9 +19,6 @@
1819
// Uncomment after installing https://github.com/pschatzmann/ESP32-A2DP
1920
// #define __BT_A2DP__ // output to A2DP sink
2021

21-
#undef PI
22-
#undef TWO_PI
23-
2422
#elif defined(ESP8266)
2523
#define __RAW_ARRAYS__
2624
#define __STREAMS__
@@ -29,8 +27,6 @@
2927
#define __NO_FSTREAM__ // No Messanger, MidiFileIn and Skini and FileRead
3028

3129
#include "FS.h"
32-
#undef PI
33-
#undef TWO_PI
3430
#undef round(x)
3531

3632
#elif defined(ARDUINO)
@@ -42,10 +38,10 @@
4238
#define __NO_FSTREAM__ // No Messanger, MidiFileIn and Skini and FileRead
4339
#define __NO_RT__ // no STK RT functions
4440

45-
#include <ArduinoSTL.h>
46-
47-
#undef PI
48-
#undef TWO_PI
41+
// Logging support
42+
#define STK_ERROR_MSG_LEN 200
43+
extern char stk_error_msg[STK_ERROR_MSG_LEN];
44+
#define ESP_LOGD(APP,...) { snprintf(stk_error_msg, STK_ERROR_MSG_LEN, __VA_ARGS__); Serial.println(stk_error_msg); }
4945

5046
#endif
5147

src/BandedWG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void BandedWG :: setFrequency( StkFloat frequency )
199199
// std::cerr << std::endl;
200200

201201
// Set the bandpass filter resonances
202-
radius = 1.0 - PI * 32 / Stk::sampleRate(); //frequency_ * modes_[i] / Stk::sampleRate()/32;
202+
radius = 1.0 - STK_PI * 32 / Stk::sampleRate(); //frequency_ * modes_[i] / Stk::sampleRate()/32;
203203
if ( radius < 0.0 ) radius = 0.0;
204204
bandpass_[i].setResonance(frequency * modes_[i], radius, true);
205205

src/BiQuad.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void BiQuad :: setResonance( StkFloat frequency, StkFloat radius, bool normalize
6565
#endif
6666

6767
a_[2] = radius * radius;
68-
a_[1] = -2.0 * radius * cos( TWO_PI * frequency / Stk::sampleRate() );
68+
a_[1] = -2.0 * radius * cos( STK_TWO_PI * frequency / Stk::sampleRate() );
6969

7070
if ( normalize ) {
7171
// Use zeros at +- 1 and normalize the filter peak gain.
@@ -90,7 +90,7 @@ void BiQuad :: setNotch( StkFloat frequency, StkFloat radius )
9090

9191
// This method does not attempt to normalize the filter gain.
9292
b_[2] = radius * radius;
93-
b_[1] = (StkFloat) -2.0 * radius * cos( TWO_PI * (double) frequency / Stk::sampleRate() );
93+
b_[1] = (StkFloat) -2.0 * radius * cos( STK_TWO_PI * (double) frequency / Stk::sampleRate() );
9494
}
9595

9696
void BiQuad :: setEqualGainZeroes( void )

src/Blit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void Blit :: setFrequency( StkFloat frequency )
5555
}
5656

5757
p_ = Stk::sampleRate() / frequency;
58-
rate_ = PI / p_;
58+
rate_ = STK_PI / p_;
5959
this->updateHarmonics();
6060
}
6161

src/Blit.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ class Blit: public Generator
4646
/*!
4747
Set the phase of the signal, in the range 0 to 1.
4848
*/
49-
void setPhase( StkFloat phase ) { phase_ = PI * phase; };
49+
void setPhase( StkFloat phase ) { phase_ = STK_PI * phase; };
5050

5151
//! Get the current phase of the signal.
5252
/*!
5353
Get the phase of the signal, in the range [0 to 1.0).
5454
*/
55-
StkFloat getPhase() const { return phase_ / PI; };
55+
StkFloat getPhase() const { return phase_ / STK_PI; };
5656

5757
//! Set the impulse train rate in terms of a frequency in Hz.
5858
void setFrequency( StkFloat frequency );
@@ -123,7 +123,7 @@ inline StkFloat Blit :: tick( void )
123123
}
124124

125125
phase_ += rate_;
126-
if ( phase_ >= PI ) phase_ -= PI;
126+
if ( phase_ >= STK_PI ) phase_ -= STK_PI;
127127

128128
lastFrame_[0] = tmp;
129129
return lastFrame_[0];

src/BlitSaw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void BlitSaw :: setFrequency( StkFloat frequency )
5555

5656
p_ = Stk::sampleRate() / frequency;
5757
C2_ = 1 / p_;
58-
rate_ = PI * C2_;
58+
rate_ = STK_PI * C2_;
5959
this->updateHarmonics();
6060
}
6161

src/BlitSaw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ inline StkFloat BlitSaw :: tick( void )
119119
state_ = tmp * 0.995;
120120

121121
phase_ += rate_;
122-
if ( phase_ >= PI ) phase_ -= PI;
122+
if ( phase_ >= STK_PI ) phase_ -= STK_PI;
123123

124124
lastFrame_[0] = tmp;
125125
return lastFrame_[0];

src/BlitSquare.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void BlitSquare :: setFrequency( StkFloat frequency )
6969
// waveform at half the blit frequency. Thus, we need to scale the
7070
// frequency value here by 0.5. (GPS, 2006).
7171
p_ = 0.5 * Stk::sampleRate() / frequency;
72-
rate_ = PI / p_;
72+
rate_ = STK_PI / p_;
7373
this->updateHarmonics();
7474
}
7575

src/BlitSquare.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ class BlitSquare: public Generator
5555
/*!
5656
Set the phase of the signal, in the range 0 to 1.
5757
*/
58-
void setPhase( StkFloat phase ) { phase_ = PI * phase; };
58+
void setPhase( StkFloat phase ) { phase_ = STK_PI * phase; };
5959

6060
//! Get the current phase of the signal.
6161
/*!
6262
Get the phase of the signal, in the range [0 to 1.0).
6363
*/
64-
StkFloat getPhase() const { return phase_ / PI; };
64+
StkFloat getPhase() const { return phase_ / STK_PI; };
6565

6666
//! Set the impulse train rate in terms of a frequency in Hz.
6767
void setFrequency( StkFloat frequency );
@@ -126,7 +126,7 @@ inline StkFloat BlitSquare :: tick( void )
126126
StkFloat denominator = sin( phase_ );
127127
if ( fabs( denominator ) < std::numeric_limits<StkFloat>::epsilon() ) {
128128
// Inexact comparison safely distinguishes betwen *close to zero*, and *close to PI*.
129-
if ( phase_ < 0.1f || phase_ > TWO_PI - 0.1f )
129+
if ( phase_ < 0.1f || phase_ > STK_TWO_PI - 0.1f )
130130
lastBlitOutput_ = a_;
131131
else
132132
lastBlitOutput_ = -a_;
@@ -143,7 +143,7 @@ inline StkFloat BlitSquare :: tick( void )
143143
dcbState_ = lastBlitOutput_;
144144

145145
phase_ += rate_;
146-
if ( phase_ >= TWO_PI ) phase_ -= TWO_PI;
146+
if ( phase_ >= STK_TWO_PI ) phase_ -= STK_TWO_PI;
147147

148148
return lastFrame_[0];
149149
}

src/BlowHole.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ BlowHole :: BlowHole( StkFloat lowestFrequency )
7474
double r_rh = 0.0015; // register vent radius
7575
te = 1.4 * r_rh; // effective length of the open hole
7676
double xi = 0.0; // series resistance term
77-
double zeta = 347.23 + 2*PI*pow(rb,2)*xi/1.1769;
78-
double psi = 2*PI*pow(rb,2)*te / (PI*pow(r_rh,2));
77+
double zeta = 347.23 + 2*STK_PI*pow(rb,2)*xi/1.1769;
78+
double psi = 2*STK_PI*pow(rb,2)*te / (STK_PI*pow(r_rh,2));
7979
StkFloat rhCoeff = (zeta - 2 * Stk::sampleRate() * psi) / (zeta + 2 * Stk::sampleRate() * psi);
8080
rhGain_ = -347.23 / (zeta + 2 * Stk::sampleRate() * psi);
8181
vent_.setA1( rhCoeff );

src/Filter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ inline StkFloat Filter :: phaseDelay( StkFloat frequency )
9797
handleError( StkError::WARNING ); return 0.0;
9898
}
9999

100-
StkFloat omegaT = 2 * PI * frequency / Stk::sampleRate();
100+
StkFloat omegaT = 2 * STK_PI * frequency / Stk::sampleRate();
101101
StkFloat real = 0.0, imag = 0.0;
102102
for ( unsigned int i=0; i<b_.size(); i++ ) {
103103
real += b_[i] * std::cos( i * omegaT );
@@ -115,7 +115,7 @@ inline StkFloat Filter :: phaseDelay( StkFloat frequency )
115115
}
116116

117117
phase -= std::atan2( imag, real );
118-
phase = std::fmod( -phase, 2 * PI );
118+
phase = std::fmod( -phase, 2 * STK_PI );
119119
return phase / omegaT;
120120
}
121121

src/FormSwep.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void FormSwep :: setResonance( StkFloat frequency, StkFloat radius )
6868
frequency_ = frequency;
6969

7070
a_[2] = radius * radius;
71-
a_[1] = -2.0 * radius * cos( TWO_PI * frequency / Stk::sampleRate() );
71+
a_[1] = -2.0 * radius * cos( STK_TWO_PI * frequency / Stk::sampleRate() );
7272

7373
// Use zeros at +- 1 and normalize the filter peak gain.
7474
b_[0] = 0.5 - 0.5 * a_[2];

src/Guitar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void Guitar :: setBodyFile( std::string bodyfile )
9494
// Smooth the start and end of the noise.
9595
unsigned int N = (unsigned int) M * 0.2; // arbitrary value
9696
for ( unsigned int n=0; n<N; n++ ) {
97-
StkFloat weight = 0.5 * ( 1.0 - cos( n * PI / (N-1) ) );
97+
StkFloat weight = 0.5 * ( 1.0 - cos( n * STK_PI / (N-1) ) );
9898
excitation_[n] *= weight;
9999
excitation_[M-n-1] *= weight;
100100
}

src/LentPitShift.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ inline void LentPitShift::process()
173173

174174
// Initialization of the Hamming window used in the algorithm
175175
for ( int n=-(int)lastPeriod_; n<(int)lastPeriod_; n++ )
176-
window[n+lastPeriod_] = (1 + cos(PI*n/lastPeriod_)) / 2 ;
176+
window[n+lastPeriod_] = (1 + cos(STK_PI*n/lastPeriod_)) / 2 ;
177177

178178
long M; // Index of reading in the input delay line
179179
long N; // Index of writing in the output delay line

src/Makefile.in

Lines changed: 0 additions & 115 deletions
This file was deleted.

src/MemoryFS.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "pgmspace.h"
1919
#elif defined(ESP8266)
2020
#include "pgmspace.h"
21+
#elif defined(ARDUINO)
22+
#include "pgmspace.h"
2123
#endif
2224

2325
#define VFS_INC_SIZE 10

0 commit comments

Comments
 (0)