Merge branch 'MoonModules:mdev' into downsample4x
This commit is contained in:
@@ -145,7 +145,11 @@ static float fftAvg[NUM_GEQ_CHANNELS] = {0.0f}; // Calculated frequency chann
|
||||
static float agcSensitivity = 128; // AGC sensitivity estimation, based on agc gain (multAgc). calculated by getSensitivity(). range 0..255
|
||||
|
||||
// user settable parameters for limitSoundDynamics()
|
||||
static bool limiterOn = true; // bool: enable / disable dynamics limiter
|
||||
#ifdef UM_AUDIOREACTIVE_DYNAMICS_LIMITER_OFF
|
||||
static bool limiterOn = false; // bool: enable / disable dynamics limiter
|
||||
#else
|
||||
static bool limiterOn = true;
|
||||
#endif
|
||||
static uint16_t attackTime = 50; // int: attack time in milliseconds. Default 0.08sec
|
||||
static uint16_t decayTime = 300; // int: decay time in milliseconds. New default 300ms. Old default was 1.40sec
|
||||
|
||||
@@ -994,19 +998,21 @@ class AudioReactive : public Usermod {
|
||||
int8_t mclkPin = MCLK_PIN;
|
||||
#endif
|
||||
#endif
|
||||
// new "V2" audiosync struct - 40 Bytes
|
||||
struct audioSyncPacket {
|
||||
char header[6]; // 06 Bytes
|
||||
float sampleRaw; // 04 Bytes - either "sampleRaw" or "rawSampleAgc" depending on soundAgc setting
|
||||
float sampleSmth; // 04 Bytes - either "sampleAvg" or "sampleAgc" depending on soundAgc setting
|
||||
uint8_t samplePeak; // 01 Bytes - 0 no peak; >=1 peak detected. In future, this will also provide peak Magnitude
|
||||
uint8_t frameCounter; // 01 Bytes - track duplicate/out of order packets
|
||||
uint8_t fftResult[16]; // 16 Bytes
|
||||
float FFT_Magnitude; // 04 Bytes
|
||||
float FFT_MajorPeak; // 04 Bytes
|
||||
// new "V2" audiosync struct - 44 Bytes
|
||||
struct __attribute__ ((packed)) audioSyncPacket { // WLEDMM "packed" ensures that there are no additional gaps
|
||||
char header[6]; // 06 Bytes offset 0
|
||||
uint8_t gap1[2]; // gap added by compiler: 02 Bytes, offset 6
|
||||
float sampleRaw; // 04 Bytes offset 8 - either "sampleRaw" or "rawSampleAgc" depending on soundAgc setting
|
||||
float sampleSmth; // 04 Bytes offset 12 - either "sampleAvg" or "sampleAgc" depending on soundAgc setting
|
||||
uint8_t samplePeak; // 01 Bytes offset 16 - 0 no peak; >=1 peak detected. In future, this will also provide peak Magnitude
|
||||
uint8_t frameCounter; // 01 Bytes offset 17 - track duplicate/out of order packets
|
||||
uint8_t fftResult[16]; // 16 Bytes offset 18
|
||||
uint8_t gap2[2]; // gap added by compiler: 02 Bytes, offset 34
|
||||
float FFT_Magnitude; // 04 Bytes offset 36
|
||||
float FFT_MajorPeak; // 04 Bytes offset 40
|
||||
};
|
||||
|
||||
// old "V1" audiosync struct - 83 Bytes - for backwards compatibility
|
||||
// old "V1" audiosync struct - 83 Bytes payload, 88 bytes total - for backwards compatibility
|
||||
struct audioSyncPacket_v1 {
|
||||
char header[6]; // 06 Bytes
|
||||
uint8_t myVals[32]; // 32 Bytes
|
||||
@@ -1022,7 +1028,7 @@ class AudioReactive : public Usermod {
|
||||
#define UDPSOUND_MAX_PACKET 96 // max packet size for audiosync, with a bit of "headroom"
|
||||
|
||||
// set your config variables to their boot default value (this can also be done in readFromConfig() or a constructor if you prefer)
|
||||
#ifdef SR_ENABLE_DEFAULT
|
||||
#if defined(SR_ENABLE_DEFAULT) || defined(UM_AUDIOREACTIVE_ENABLE)
|
||||
bool enabled = true; // WLEDMM
|
||||
#else
|
||||
bool enabled = false;
|
||||
@@ -1611,6 +1617,9 @@ class AudioReactive : public Usermod {
|
||||
my_magnitude = fmaxf(receivedPacket->FFT_Magnitude, 0.0f);
|
||||
FFT_Magnitude = my_magnitude;
|
||||
FFT_MajorPeak = constrain(receivedPacket->FFT_MajorPeak, 1.0f, 11025.0f); // restrict value to range expected by effects
|
||||
soundPressure = volumeSmth; // substitute - V2 format does not (yet) include this value
|
||||
agcSensitivity = 128.0f; // substitute - V2 format does not (yet) include this value
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1640,6 +1649,8 @@ class AudioReactive : public Usermod {
|
||||
my_magnitude = fmaxf(receivedPacket->FFT_Magnitude, 0.0);
|
||||
FFT_Magnitude = my_magnitude;
|
||||
FFT_MajorPeak = constrain(receivedPacket->FFT_MajorPeak, 1.0, 11025.0); // restrict value to range expected by effects
|
||||
soundPressure = volumeSmth; // substitute - V1 format does not include this value
|
||||
agcSensitivity = 128.0f; // substitute - V1 format does not include this value
|
||||
}
|
||||
|
||||
bool receiveAudioData() // check & process new data. return TRUE in case that new audio data was received.
|
||||
@@ -1897,6 +1908,26 @@ class AudioReactive : public Usermod {
|
||||
DEBUGSR_PRINTLN(enabled ? F("true.") : F("false."));
|
||||
USER_FLUSH();
|
||||
|
||||
// dump audiosync data layout
|
||||
#if defined(SR_DEBUG)
|
||||
{
|
||||
audioSyncPacket data;
|
||||
USER_PRINTF("\naudioSyncPacket_v1 size = %d\n", sizeof(audioSyncPacket_v1)); // size 88
|
||||
USER_PRINTF("audioSyncPacket size = %d\n", sizeof(audioSyncPacket)); // size 44
|
||||
USER_PRINTF("| char header[6] offset = %2d size = %2d\n", offsetof(audioSyncPacket, header[0]), sizeof(data.header)); // offset 0 size 6
|
||||
USER_PRINTF("| uint8_t gap1[2] offset = %2d size = %2d\n", offsetof(audioSyncPacket, gap1[0]), sizeof(data.gap1)); // offset 6 size 2
|
||||
USER_PRINTF("| float sampleRaw offset = %2d size = %2d\n", offsetof(audioSyncPacket, sampleRaw), sizeof(data.sampleRaw)); // offset 8 size 4
|
||||
USER_PRINTF("| float sampleSmth offset = %2d size = %2d\n", offsetof(audioSyncPacket, sampleSmth), sizeof(data.sampleSmth)); // offset 12 size 4
|
||||
USER_PRINTF("| uint8_t samplePeak offset = %2d size = %2d\n", offsetof(audioSyncPacket, samplePeak), sizeof(data.samplePeak)); // offset 16 size 1
|
||||
USER_PRINTF("| uint8_t frameCounter offset = %2d size = %2d\n", offsetof(audioSyncPacket, frameCounter), sizeof(data.frameCounter)); // offset 17 size 1
|
||||
USER_PRINTF("| uint8_t fftResult[16] offset = %2d size = %2d\n", offsetof(audioSyncPacket, fftResult[0]), sizeof(data.fftResult)); // offset 18 size 16
|
||||
USER_PRINTF("| uint8_t gap2[2] offset = %2d size = %2d\n", offsetof(audioSyncPacket, gap2[0]), sizeof(data.gap2)); // offset 34 size 2
|
||||
USER_PRINTF("| float FFT_Magnitude offset = %2d size = %2d\n", offsetof(audioSyncPacket, FFT_Magnitude), sizeof(data.FFT_Magnitude));// offset 36 size 4
|
||||
USER_PRINTF("| float FFT_MajorPeak offset = %2d size = %2d\n", offsetof(audioSyncPacket, FFT_MajorPeak), sizeof(data.FFT_MajorPeak));// offset 40 size 4
|
||||
USER_PRINTLN(); USER_FLUSH();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(SR_DEBUG)
|
||||
DEBUGSR_PRINTF("|| %-9s min free stack %d\n", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL)); //WLEDMM
|
||||
#endif
|
||||
@@ -1993,12 +2024,12 @@ class AudioReactive : public Usermod {
|
||||
DEBUG_PRINTF( " RealtimeMode = %d; RealtimeOverride = %d\n", int(realtimeMode), int(realtimeOverride));
|
||||
}
|
||||
#endif
|
||||
if ((disableSoundProcessing == true) && (audioSyncEnabled < AUDIOSYNC_REC)) lastUMRun = millis(); // just left "realtime mode" - update timekeeping
|
||||
if ((disableSoundProcessing == true) && (audioSyncEnabled != AUDIOSYNC_REC)) lastUMRun = millis(); // just left "realtime mode" - update timekeeping
|
||||
disableSoundProcessing = false;
|
||||
}
|
||||
|
||||
if (audioSyncEnabled == AUDIOSYNC_REC) disableSoundProcessing = true; // make sure everything is disabled IF in audio Receive mode
|
||||
if (audioSyncEnabled & AUDIOSYNC_SEND) disableSoundProcessing = false; // keep running audio IF we're in audio Transmit mode
|
||||
if (audioSyncEnabled == AUDIOSYNC_SEND) disableSoundProcessing = false; // keep running audio IF we're in audio Transmit mode
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
if (!audioSource->isInitialized()) { // no audio source
|
||||
disableSoundProcessing = true;
|
||||
@@ -2110,6 +2141,8 @@ class AudioReactive : public Usermod {
|
||||
volumeSmth =0.0f;
|
||||
volumeRaw =0;
|
||||
my_magnitude = 0.1; FFT_Magnitude = 0.01; FFT_MajorPeak = 2;
|
||||
soundPressure = 1.0f;
|
||||
agcSensitivity = 64.0f;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
multAgc = 1;
|
||||
#endif
|
||||
|
||||
@@ -666,27 +666,26 @@ class WM8978Source : public I2SSource {
|
||||
_wm8978I2cBegin();
|
||||
|
||||
_wm8978I2cWrite( 0,0b000000000); // Reset all settings
|
||||
_wm8978I2cWrite( 1,0b000001011); // Power Management 1 - power off most things
|
||||
_wm8978I2cWrite( 2,0b110110011); // Power Management 2 - enable output and amp stages (amps may lift signal but it works better on the ADCs)
|
||||
_wm8978I2cWrite( 1,0b000111110); // Power Management 1 - power off most things, but enable mic bias and I/O tie-off to help mitigate mic leakage.
|
||||
_wm8978I2cWrite( 2,0b110111111); // Power Management 2 - enable output and amp stages (amps may lift signal but it works better on the ADCs)
|
||||
_wm8978I2cWrite( 3,0b000001100); // Power Management 3 - enable L&R output mixers
|
||||
_wm8978I2cWrite( 4,0b001010000); // Audio Interface - standard I2S, 24-bit
|
||||
_wm8978I2cWrite( 5,0b000000001); // Loopback Enable
|
||||
_wm8978I2cWrite( 6,0b000000000); // Clock generation control - use external mclk
|
||||
_wm8978I2cWrite( 7,0b000000100); // Sets sample rate to ~24kHz (only used for internal calculations, not I2S)
|
||||
_wm8978I2cWrite(14,0b010001000); // 128x ADC oversampling - high pass filter disabled as it kills the bass response
|
||||
_wm8978I2cWrite(43,0b000110000); // Mute signal paths we don't use
|
||||
_wm8978I2cWrite(44,0b000000000); // Disconnect microphones
|
||||
_wm8978I2cWrite(44,0b100000000); // Disconnect microphones
|
||||
_wm8978I2cWrite(45,0b111000000); // Mute signal paths we don't use
|
||||
_wm8978I2cWrite(46,0b111000000); // Mute signal paths we don't use
|
||||
_wm8978I2cWrite(47,0b001000000); // 0dB gain on left line-in
|
||||
_wm8978I2cWrite(48,0b001000000); // 0dB gain on right line-in
|
||||
_wm8978I2cWrite(49,0b000000010); // Mixer thermal shutdown enable
|
||||
_wm8978I2cWrite(49,0b000000011); // Mixer thermal shutdown enable and unused IOs to 30kΩ
|
||||
_wm8978I2cWrite(50,0b000010110); // Output mixer enable only left bypass at 0dB gain
|
||||
_wm8978I2cWrite(51,0b000010110); // Output mixer enable only right bypass at 0dB gain
|
||||
_wm8978I2cWrite(52,0b110111001); // Left line-out enabled at 0dB gain
|
||||
_wm8978I2cWrite(53,0b110111001); // Right line-out enabled at 0db gain
|
||||
_wm8978I2cWrite(54,0b001000000); // Mute left speaker output
|
||||
_wm8978I2cWrite(55,0b101000000); // Mute right speaker output
|
||||
_wm8978I2cWrite(54,0b111000000); // Mute left speaker output
|
||||
_wm8978I2cWrite(55,0b111000000); // Mute right speaker output
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,11 @@ If you want to define default GPIOs during compile time, use the following (defa
|
||||
- `-D ES7243_SDAPIN` : GPIO for I2C SDA pin on ES7243 microphone (-1)
|
||||
- `-D ES7243_SCLPIN` : GPIO for I2C SCL pin on ES7243 microphone (-1)
|
||||
|
||||
Other options:
|
||||
|
||||
- `-D UM_AUDIOREACTIVE_ENABLE` : makes usermod default enabled (not the same as include into build option!)
|
||||
- `-D UM_AUDIOREACTIVE_DYNAMICS_LIMITER_OFF` : disables rise/fall limiter default
|
||||
|
||||
**NOTE** I2S is used for analog audio sampling. Hence, the analog *buttons* (i.e. potentiometers) are disabled when running this usermod with an analog microphone.
|
||||
|
||||
### Advanced Compile-Time Options
|
||||
|
||||
Reference in New Issue
Block a user