Replace myVals from audio_reactive.h to SEGMENT.data

(position in um_data reserved as free, could be cleaned up later)
This commit is contained in:
ewowi 2022-07-29 10:04:10 +02:00
parent a6f31a577a
commit bc67bf6826
3 changed files with 7 additions and 22 deletions

View File

@ -403,7 +403,6 @@ class AudioReactive : public Usermod {
struct audioSyncPacket {
char header[6];
uint8_t myVals[32]; // 32 Bytes
int sampleAgc; // 04 Bytes
int sample; // 04 Bytes
float sampleAvg; // 04 Bytes
@ -423,7 +422,6 @@ class AudioReactive : public Usermod {
// variables used in effects
uint8_t maxVol = 10; // Reasonable value for constant volume for 'peak detector', as it won't always trigger
uint8_t binNum = 8; // Used to select the bin for FFT based beat detection.
uint8_t myVals[32]; // Used to store a pile of samples because WLED frame rate and WLED sample rate are not synchronized. Frame rate is too low.
bool samplePeak = 0; // Boolean flag for peak. Responding routine must reset this flag
int16_t sample; // either sampleRaw or rawSampleAgc depending on soundAgc
float sampleSmth; // either sampleAvg or sampleAgc depending on soundAgc; smoothed sample
@ -742,10 +740,6 @@ class AudioReactive : public Usermod {
audioSyncPacket transmitData;
strncpy_P(transmitData.header, PSTR(UDP_SYNC_HEADER), 6);
for (int i = 0; i < 32; i++) {
transmitData.myVals[i] = myVals[i];
}
transmitData.sampleAgc = sampleAgc;
transmitData.sample = sampleRaw;
transmitData.sampleAvg = sampleAvg;
@ -786,8 +780,6 @@ class AudioReactive : public Usermod {
if (packetSize == sizeof(audioSyncPacket) && !(isValidUdpSyncVersion((const char *)fftBuff))) {
audioSyncPacket *receivedPacket = reinterpret_cast<audioSyncPacket*>(fftBuff);
for (int i = 0; i < 32; i++) myVals[i] = receivedPacket->myVals[i];
sampleAgc = receivedPacket->sampleAgc;
rawSampleAgc = receivedPacket->sampleAgc;
sampleRaw = receivedPacket->sample;
@ -854,8 +846,8 @@ class AudioReactive : public Usermod {
um_data->u_type[12] = UMT_FLOAT;
um_data->u_data[13] = &sampleGain; //*used (for debugging) (Gravimeter, Binmap)
um_data->u_type[13] = UMT_FLOAT;
um_data->u_data[14] = myVals; //*used (only once, Pixels)
um_data->u_type[14] = UMT_UINT16_ARR;
um_data->u_data[14] = 0; //*free (used for myVals / Pixels before)
um_data->u_type[14] = UMT_BYTE;
um_data->u_data[15] = &soundSquelch; //*used (for debugging) (only once, Binmap)
um_data->u_type[15] = UMT_BYTE;
um_data->u_data[16] = fftBin; //*used (for debugging) (only once, Binmap)
@ -1011,8 +1003,6 @@ class AudioReactive : public Usermod {
getSample(); // Sample the microphone
agcAvg(); // Calculated the PI adjusted value as sampleAvg
myVals[millis()%32] = sampleAgc; // filling values semi randomly (why?)
uint8_t knownMode = strip.getFirstSelectedSeg().mode; // 1st selected segment is more appropriate than main segment
if (lastMode != knownMode) { // only execute if mode changes

View File

@ -5972,7 +5972,6 @@ static const char *_data_FX_MODE_2DDRIFTROSE PROGMEM = "2D Drift Rose@Fade,Blur;
float sampleAgc = 0.0f, sampleAgv = 0.0f, multAgc = 0.0f, sampleReal = 0.0f;
float FFT_MajorPeak = 0.0, FFT_Magnitude = 0.0;
uint8_t *fftResult = nullptr;
uint16_t *myVals = nullptr;
float *fftBin = nullptr;
um_data_t *um_data;
if (usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
@ -5990,7 +5989,6 @@ static const char *_data_FX_MODE_2DDRIFTROSE PROGMEM = "2D Drift Rose@Fade,Blur;
multAgc = *(float*) um_data->u_data[11];
sampleReal = *(float*) um_data->u_data[12];
sampleGain = *(float*) um_data->u_data[13];
myVals = (uint16_t*)um_data->u_data[14];
soundSquelch = *(uint8_t*) um_data->u_data[15];
fftBin = (float*) um_data->u_data[16];
inputLevel = (uint8_t*) um_data->u_data[17]; // requires UI element (SEGMENT.customX?), changes source element
@ -5998,7 +5996,6 @@ static const char *_data_FX_MODE_2DDRIFTROSE PROGMEM = "2D Drift Rose@Fade,Blur;
// add support for no audio data
um_data = simulateSound(SEGMENT.soundSim);
}
if (!myVals || !fftBin || ...) return mode_static();
*/
@ -6678,13 +6675,15 @@ static const char *_data_FX_MODE_PUDDLES PROGMEM = "Puddles ♪@Fade rate,Puddle
//////////////////////
uint16_t mode_pixels(void) { // Pixels. By Andrew Tuline.
if (!SEGENV.allocateData(32*sizeof(uint8_t))) return mode_static(); //allocation failed
uint8_t *myVals = reinterpret_cast<uint8_t*>(SEGENV.data); // Used to store a pile of samples because WLED frame rate and WLED sample rate are not synchronized. Frame rate is too low.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAgc = *(float*) um_data->u_data[2];
uint16_t *myVals = (uint16_t*)um_data->u_data[14];
if (!myVals) return mode_static();
myVals[millis()%32] = sampleAgc; // filling values semi randomly
SEGMENT.fade_out(64+(SEGMENT.speed>>1));

View File

@ -415,7 +415,6 @@ um_data_t* simulateSound(uint8_t simulationId)
//arrays
uint8_t *fftResult;
uint8_t *myVals;
float *fftBin;
static um_data_t* um_data = nullptr;
@ -423,7 +422,6 @@ um_data_t* simulateSound(uint8_t simulationId)
if (!um_data) {
//claim storage for arrays
fftResult = (uint8_t *)malloc(sizeof(uint8_t) * 16);
myVals = (uint8_t *)malloc(sizeof(uint8_t) * 32);
fftBin = (float *)malloc(sizeof(float) * 256); // not used (for debugging purposes)
// initialize um_data pointer structure
@ -445,7 +443,7 @@ um_data_t* simulateSound(uint8_t simulationId)
um_data->u_data[ 9] = &maxVol;
um_data->u_data[10] = &binNum;
um_data->u_data[11] = &multAgc;
um_data->u_data[14] = myVals; //*used (only once, Pixels)
um_data->u_data[14] = 0; //free
um_data->u_data[13] = &sampleGain;
um_data->u_data[15] = &soundSquelch;
um_data->u_data[16] = fftBin; //only used in binmap
@ -453,7 +451,6 @@ um_data_t* simulateSound(uint8_t simulationId)
} else {
// get arrays from um_data
fftResult = (uint8_t*)um_data->u_data[8];
myVals = (uint8_t*)um_data->u_data[14];
fftBin = (float*)um_data->u_data[16];
}
@ -523,7 +520,6 @@ um_data_t* simulateSound(uint8_t simulationId)
FFT_MajorPeak = sampleAvg;
FFT_Magnitude = sampleAvg;
multAgc = sampleAvg;
myVals[millis()%32] = sampleAvg; // filling values semi randomly (why?)
sampleGain = 40;
soundSquelch = 10;
maxVol = 10; // this gets feedback fro UI