Skip to content

Commit

Permalink
Compile error AudioSourceSD for UNO R4
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Oct 6, 2024
1 parent ec98def commit 90e4088
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
5 changes: 4 additions & 1 deletion src/AudioConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
# define USE_PDM
#endif

// for all ESP32 families
#if defined(ESP32)
// We need to use accept instead of available
# if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
Expand All @@ -245,6 +246,7 @@
# else
# define USE_PRINT_FLUSH false
# endif
# define USE_SD_SUPPORTS_SPI
#endif

// ----- Regular ESP32 -----
Expand Down Expand Up @@ -405,6 +407,7 @@ typedef uint32_t eps32_i2s_sample_rate_type;

#define URL_CLIENT_TIMEOUT 60000;
#define URL_HANDSHAKE_TIMEOUT 120000
#define USE_SD_SUPPORTS_SPI

#endif

Expand Down Expand Up @@ -505,6 +508,7 @@ typedef uint32_t eps32_i2s_sample_rate_type;
#endif

#define USE_CONCURRENCY
#define USE_SD_SUPPORTS_SPI

// default pins for VS1053 shield
#define VS1053_CS 17
Expand All @@ -513,7 +517,6 @@ typedef uint32_t eps32_i2s_sample_rate_type;
#define VS1053_CS_SD -1
#define VS1053_RESET 11
#define VS1053_DEFINED

#endif

// The Pico W has WIFI support: but platformio is messing up, so we support NO_WIFI
Expand Down
22 changes: 10 additions & 12 deletions src/AudioTools/AudioLibs/AudioEffectsSuite.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
#include <cmath>
#include <cstdint>
#include <iostream>
#include "AudioEffect.h"
#include "AudioTools/CoreAudio/AudioEffects/AudioEffect.h"

#ifndef PI
# define PI 3.141592653589793f
#endif

namespace audio_tools {

Expand Down Expand Up @@ -728,8 +732,8 @@ class FilterEffectBase : public EffectSuiteBase {
Kx = 1;
}

const effectsuite_t T = 2 * tan(.5);
const effectsuite_t W = 2 * pi * cutFreq;
const effectsuite_t T = 2.0f * tan(.5f);
const effectsuite_t W = 2.0f * PI * cutFreq;

effectsuite_t K;

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

effectsuite_t Rp, Ip;
if (ripple != 0) {
Expand Down Expand Up @@ -956,7 +960,6 @@ class FilterEffectBase : public EffectSuiteBase {
return rmsValue;
}

public:
protected:
/** Numerator coefficients in delay filter
firCoefficients[0] z^0 coeffcieint
Expand Down Expand Up @@ -990,8 +993,6 @@ class FilterEffectBase : public EffectSuiteBase {
/** RMS window buffer */
effectsuite_t *rmsBuffer = new effectsuite_t[rmsWindowSize];

protected: // variables
constexpr static const effectsuite_t pi = 3.141592653589793;
};

/**
Expand Down Expand Up @@ -1516,7 +1517,7 @@ class SimpleFlanger : public DelayEffectBase, public EffectSuiteBase {
**/
void setAngleDelta() {
const effectsuite_t cyclesPerSample = modulationRate * timeStep;
angleDelta = cyclesPerSample * 2.0 * internal_Pi;
angleDelta = cyclesPerSample * 2.0f * PI;
}

/**
Expand All @@ -1533,9 +1534,6 @@ class SimpleFlanger : public DelayEffectBase, public EffectSuiteBase {
}

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

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

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

// const effectsuite_t cyclesPerSample = modulationRate * timeStep;
/**increment value for modulation signal*/
effectsuite_t angleDelta = 2 * internal_Pi * timeStep;
effectsuite_t angleDelta = 2.0f * PI * timeStep;
};

/**
Expand Down
11 changes: 10 additions & 1 deletion src/AudioTools/AudioLibs/AudioSourceIdxSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class AudioSourceIdxSD : public AudioSource {
cs = chipSelect;
}

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

virtual void begin() override {
TRACED();
if (!is_sd_setup) {
while (!SD.begin(cs, *p_spi)) {
while (!start_sd()) {
LOGW("SD.begin cs=%d failed", cs);
delay(500);
}
Expand Down Expand Up @@ -126,6 +128,13 @@ class AudioSourceIdxSD : public AudioSource {
SPIClass *p_spi = nullptr;
int cs;

bool start_sd(){
#ifdef USE_SD_SUPPORTS_SPI
return SD.begin(cs, *p_spi);
#else
return SD.begin(cs);
#endif

};

} // namespace audio_tools
22 changes: 17 additions & 5 deletions src/AudioTools/AudioLibs/AudioSourceSD.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#pragma once

#include "AudioTools/CoreAudio/AudioBasic/StrExt.h"
#include "SD.h"
#include "SPI.h"
#include "AudioLogger.h"
#include "AudioTools/CoreAudio/AudioBasic/StrExt.h"
#include "AudioTools/CoreAudio/AudioSource.h"
#include "AudioTools/AudioLibs/SDDirect.h"
#include "SD.h"
#include "SPI.h"

namespace audio_tools {

Expand Down Expand Up @@ -42,6 +41,8 @@ class AudioSourceSD : public AudioSource {
cs = chipSelect;
}

#ifdef USE_SD_SUPPORTS_SPI

// Pass your own spi instance, in case you need a dedicated one
AudioSourceSD(const char *startFilePath, const char *ext, int chipSelect, SPIClass &spiInstance, bool setupIndex=true) {
start_path = startFilePath;
Expand All @@ -51,10 +52,12 @@ class AudioSourceSD : public AudioSource {
cs = chipSelect;
}

#endif

virtual void begin() override {
TRACED();
if (!is_sd_setup) {
while (!SD.begin(cs, *p_spi)) {
while (!start_sd()) {
LOGE("SD.begin cs=%d failed", cs);
delay(1000);
}
Expand Down Expand Up @@ -127,6 +130,15 @@ class AudioSourceSD : public AudioSource {
bool is_sd_setup = false;
int cs;
SPIClass *p_spi = nullptr;

bool start_sd(){
#ifdef USE_SD_SUPPORTS_SPI
return SD.begin(cs, *p_spi);
#else
return SD.begin(cs);
#endif
}

};

} // namespace audio_tools

0 comments on commit 90e4088

Please sign in to comment.