Skip to content

Commit 90e4088

Browse files
committed
Compile error AudioSourceSD for UNO R4
1 parent ec98def commit 90e4088

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

src/AudioConfig.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@
233233
# define USE_PDM
234234
#endif
235235

236+
// for all ESP32 families
236237
#if defined(ESP32)
237238
// We need to use accept instead of available
238239
# if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
@@ -245,6 +246,7 @@
245246
# else
246247
# define USE_PRINT_FLUSH false
247248
# endif
249+
# define USE_SD_SUPPORTS_SPI
248250
#endif
249251

250252
// ----- Regular ESP32 -----
@@ -405,6 +407,7 @@ typedef uint32_t eps32_i2s_sample_rate_type;
405407

406408
#define URL_CLIENT_TIMEOUT 60000;
407409
#define URL_HANDSHAKE_TIMEOUT 120000
410+
#define USE_SD_SUPPORTS_SPI
408411

409412
#endif
410413

@@ -505,6 +508,7 @@ typedef uint32_t eps32_i2s_sample_rate_type;
505508
#endif
506509

507510
#define USE_CONCURRENCY
511+
#define USE_SD_SUPPORTS_SPI
508512

509513
// default pins for VS1053 shield
510514
#define VS1053_CS 17
@@ -513,7 +517,6 @@ typedef uint32_t eps32_i2s_sample_rate_type;
513517
#define VS1053_CS_SD -1
514518
#define VS1053_RESET 11
515519
#define VS1053_DEFINED
516-
517520
#endif
518521

519522
// The Pico W has WIFI support: but platformio is messing up, so we support NO_WIFI

src/AudioTools/AudioLibs/AudioEffectsSuite.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
#include <cmath>
2121
#include <cstdint>
2222
#include <iostream>
23-
#include "AudioEffect.h"
23+
#include "AudioTools/CoreAudio/AudioEffects/AudioEffect.h"
24+
25+
#ifndef PI
26+
# define PI 3.141592653589793f
27+
#endif
2428

2529
namespace audio_tools {
2630

@@ -728,8 +732,8 @@ class FilterEffectBase : public EffectSuiteBase {
728732
Kx = 1;
729733
}
730734

731-
const effectsuite_t T = 2 * tan(.5);
732-
const effectsuite_t W = 2 * pi * cutFreq;
735+
const effectsuite_t T = 2.0f * tan(.5f);
736+
const effectsuite_t W = 2.0f * PI * cutFreq;
733737

734738
effectsuite_t K;
735739

@@ -745,7 +749,7 @@ class FilterEffectBase : public EffectSuiteBase {
745749
////// main algorithm
746750
for (int i = 0; i < (order / 2); i++) {
747751
////// Sub routine
748-
const effectsuite_t alpha = pi / (2 * poles) + (i - 1) * (pi / poles);
752+
const effectsuite_t alpha = PI / (2 * poles) + (i - 1) * (PI / poles);
749753

750754
effectsuite_t Rp, Ip;
751755
if (ripple != 0) {
@@ -956,7 +960,6 @@ class FilterEffectBase : public EffectSuiteBase {
956960
return rmsValue;
957961
}
958962

959-
public:
960963
protected:
961964
/** Numerator coefficients in delay filter
962965
firCoefficients[0] z^0 coeffcieint
@@ -990,8 +993,6 @@ class FilterEffectBase : public EffectSuiteBase {
990993
/** RMS window buffer */
991994
effectsuite_t *rmsBuffer = new effectsuite_t[rmsWindowSize];
992995

993-
protected: // variables
994-
constexpr static const effectsuite_t pi = 3.141592653589793;
995996
};
996997

997998
/**
@@ -1516,7 +1517,7 @@ class SimpleFlanger : public DelayEffectBase, public EffectSuiteBase {
15161517
**/
15171518
void setAngleDelta() {
15181519
const effectsuite_t cyclesPerSample = modulationRate * timeStep;
1519-
angleDelta = cyclesPerSample * 2.0 * internal_Pi;
1520+
angleDelta = cyclesPerSample * 2.0f * PI;
15201521
}
15211522

15221523
/**
@@ -1533,9 +1534,6 @@ class SimpleFlanger : public DelayEffectBase, public EffectSuiteBase {
15331534
}
15341535

15351536
protected:
1536-
/** internal class declaration of pi it would likely make sense to have this
1537-
* moved to a higher class */
1538-
constexpr static const effectsuite_t internal_Pi = 3.141592653589793;
15391537

15401538
effectsuite_t modulationDepth = 1000, modulationRate = 0, effectGain = .01;
15411539

@@ -1549,7 +1547,7 @@ class SimpleFlanger : public DelayEffectBase, public EffectSuiteBase {
15491547

15501548
// const effectsuite_t cyclesPerSample = modulationRate * timeStep;
15511549
/**increment value for modulation signal*/
1552-
effectsuite_t angleDelta = 2 * internal_Pi * timeStep;
1550+
effectsuite_t angleDelta = 2.0f * PI * timeStep;
15531551
};
15541552

15551553
/**

src/AudioTools/AudioLibs/AudioSourceIdxSD.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class AudioSourceIdxSD : public AudioSource {
4040
cs = chipSelect;
4141
}
4242

43+
#ifdef USE_SD_SUPPORTS_SPI
4344
// Pass your own spi instance, in case you need a dedicated one
4445
AudioSourceSD(const char *startFilePath, const char *ext, int chipSelect, SPIClass &spiInstance, bool setupIndex=true) {
4546
start_path = startFilePath;
@@ -48,11 +49,12 @@ class AudioSourceIdxSD : public AudioSource {
4849
p_spi = &spiInstance;
4950
cs = chipSelect;
5051
}
52+
#endif
5153

5254
virtual void begin() override {
5355
TRACED();
5456
if (!is_sd_setup) {
55-
while (!SD.begin(cs, *p_spi)) {
57+
while (!start_sd()) {
5658
LOGW("SD.begin cs=%d failed", cs);
5759
delay(500);
5860
}
@@ -126,6 +128,13 @@ class AudioSourceIdxSD : public AudioSource {
126128
SPIClass *p_spi = nullptr;
127129
int cs;
128130

131+
bool start_sd(){
132+
#ifdef USE_SD_SUPPORTS_SPI
133+
return SD.begin(cs, *p_spi);
134+
#else
135+
return SD.begin(cs);
136+
#endif
137+
129138
};
130139

131140
} // namespace audio_tools

src/AudioTools/AudioLibs/AudioSourceSD.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#pragma once
2-
3-
#include "AudioTools/CoreAudio/AudioBasic/StrExt.h"
2+
#include "SD.h"
3+
#include "SPI.h"
44
#include "AudioLogger.h"
5+
#include "AudioTools/CoreAudio/AudioBasic/StrExt.h"
56
#include "AudioTools/CoreAudio/AudioSource.h"
67
#include "AudioTools/AudioLibs/SDDirect.h"
7-
#include "SD.h"
8-
#include "SPI.h"
98

109
namespace audio_tools {
1110

@@ -42,6 +41,8 @@ class AudioSourceSD : public AudioSource {
4241
cs = chipSelect;
4342
}
4443

44+
#ifdef USE_SD_SUPPORTS_SPI
45+
4546
// Pass your own spi instance, in case you need a dedicated one
4647
AudioSourceSD(const char *startFilePath, const char *ext, int chipSelect, SPIClass &spiInstance, bool setupIndex=true) {
4748
start_path = startFilePath;
@@ -51,10 +52,12 @@ class AudioSourceSD : public AudioSource {
5152
cs = chipSelect;
5253
}
5354

55+
#endif
56+
5457
virtual void begin() override {
5558
TRACED();
5659
if (!is_sd_setup) {
57-
while (!SD.begin(cs, *p_spi)) {
60+
while (!start_sd()) {
5861
LOGE("SD.begin cs=%d failed", cs);
5962
delay(1000);
6063
}
@@ -127,6 +130,15 @@ class AudioSourceSD : public AudioSource {
127130
bool is_sd_setup = false;
128131
int cs;
129132
SPIClass *p_spi = nullptr;
133+
134+
bool start_sd(){
135+
#ifdef USE_SD_SUPPORTS_SPI
136+
return SD.begin(cs, *p_spi);
137+
#else
138+
return SD.begin(cs);
139+
#endif
140+
}
141+
130142
};
131143

132144
} // namespace audio_tools

0 commit comments

Comments
 (0)