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:
parent
a6f31a577a
commit
bc67bf6826
@ -403,7 +403,6 @@ class AudioReactive : public Usermod {
|
|||||||
|
|
||||||
struct audioSyncPacket {
|
struct audioSyncPacket {
|
||||||
char header[6];
|
char header[6];
|
||||||
uint8_t myVals[32]; // 32 Bytes
|
|
||||||
int sampleAgc; // 04 Bytes
|
int sampleAgc; // 04 Bytes
|
||||||
int sample; // 04 Bytes
|
int sample; // 04 Bytes
|
||||||
float sampleAvg; // 04 Bytes
|
float sampleAvg; // 04 Bytes
|
||||||
@ -423,7 +422,6 @@ class AudioReactive : public Usermod {
|
|||||||
// variables used in effects
|
// variables used in effects
|
||||||
uint8_t maxVol = 10; // Reasonable value for constant volume for 'peak detector', as it won't always trigger
|
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 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
|
bool samplePeak = 0; // Boolean flag for peak. Responding routine must reset this flag
|
||||||
int16_t sample; // either sampleRaw or rawSampleAgc depending on soundAgc
|
int16_t sample; // either sampleRaw or rawSampleAgc depending on soundAgc
|
||||||
float sampleSmth; // either sampleAvg or sampleAgc depending on soundAgc; smoothed sample
|
float sampleSmth; // either sampleAvg or sampleAgc depending on soundAgc; smoothed sample
|
||||||
@ -742,10 +740,6 @@ class AudioReactive : public Usermod {
|
|||||||
audioSyncPacket transmitData;
|
audioSyncPacket transmitData;
|
||||||
strncpy_P(transmitData.header, PSTR(UDP_SYNC_HEADER), 6);
|
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.sampleAgc = sampleAgc;
|
||||||
transmitData.sample = sampleRaw;
|
transmitData.sample = sampleRaw;
|
||||||
transmitData.sampleAvg = sampleAvg;
|
transmitData.sampleAvg = sampleAvg;
|
||||||
@ -786,8 +780,6 @@ class AudioReactive : public Usermod {
|
|||||||
if (packetSize == sizeof(audioSyncPacket) && !(isValidUdpSyncVersion((const char *)fftBuff))) {
|
if (packetSize == sizeof(audioSyncPacket) && !(isValidUdpSyncVersion((const char *)fftBuff))) {
|
||||||
audioSyncPacket *receivedPacket = reinterpret_cast<audioSyncPacket*>(fftBuff);
|
audioSyncPacket *receivedPacket = reinterpret_cast<audioSyncPacket*>(fftBuff);
|
||||||
|
|
||||||
for (int i = 0; i < 32; i++) myVals[i] = receivedPacket->myVals[i];
|
|
||||||
|
|
||||||
sampleAgc = receivedPacket->sampleAgc;
|
sampleAgc = receivedPacket->sampleAgc;
|
||||||
rawSampleAgc = receivedPacket->sampleAgc;
|
rawSampleAgc = receivedPacket->sampleAgc;
|
||||||
sampleRaw = receivedPacket->sample;
|
sampleRaw = receivedPacket->sample;
|
||||||
@ -854,8 +846,8 @@ class AudioReactive : public Usermod {
|
|||||||
um_data->u_type[12] = UMT_FLOAT;
|
um_data->u_type[12] = UMT_FLOAT;
|
||||||
um_data->u_data[13] = &sampleGain; //*used (for debugging) (Gravimeter, Binmap)
|
um_data->u_data[13] = &sampleGain; //*used (for debugging) (Gravimeter, Binmap)
|
||||||
um_data->u_type[13] = UMT_FLOAT;
|
um_data->u_type[13] = UMT_FLOAT;
|
||||||
um_data->u_data[14] = myVals; //*used (only once, Pixels)
|
um_data->u_data[14] = 0; //*free (used for myVals / Pixels before)
|
||||||
um_data->u_type[14] = UMT_UINT16_ARR;
|
um_data->u_type[14] = UMT_BYTE;
|
||||||
um_data->u_data[15] = &soundSquelch; //*used (for debugging) (only once, Binmap)
|
um_data->u_data[15] = &soundSquelch; //*used (for debugging) (only once, Binmap)
|
||||||
um_data->u_type[15] = UMT_BYTE;
|
um_data->u_type[15] = UMT_BYTE;
|
||||||
um_data->u_data[16] = fftBin; //*used (for debugging) (only once, Binmap)
|
um_data->u_data[16] = fftBin; //*used (for debugging) (only once, Binmap)
|
||||||
@ -1011,8 +1003,6 @@ class AudioReactive : public Usermod {
|
|||||||
getSample(); // Sample the microphone
|
getSample(); // Sample the microphone
|
||||||
agcAvg(); // Calculated the PI adjusted value as sampleAvg
|
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
|
uint8_t knownMode = strip.getFirstSelectedSeg().mode; // 1st selected segment is more appropriate than main segment
|
||||||
|
|
||||||
if (lastMode != knownMode) { // only execute if mode changes
|
if (lastMode != knownMode) { // only execute if mode changes
|
||||||
|
@ -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 sampleAgc = 0.0f, sampleAgv = 0.0f, multAgc = 0.0f, sampleReal = 0.0f;
|
||||||
float FFT_MajorPeak = 0.0, FFT_Magnitude = 0.0;
|
float FFT_MajorPeak = 0.0, FFT_Magnitude = 0.0;
|
||||||
uint8_t *fftResult = nullptr;
|
uint8_t *fftResult = nullptr;
|
||||||
uint16_t *myVals = nullptr;
|
|
||||||
float *fftBin = nullptr;
|
float *fftBin = nullptr;
|
||||||
um_data_t *um_data;
|
um_data_t *um_data;
|
||||||
if (usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
|
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];
|
multAgc = *(float*) um_data->u_data[11];
|
||||||
sampleReal = *(float*) um_data->u_data[12];
|
sampleReal = *(float*) um_data->u_data[12];
|
||||||
sampleGain = *(float*) um_data->u_data[13];
|
sampleGain = *(float*) um_data->u_data[13];
|
||||||
myVals = (uint16_t*)um_data->u_data[14];
|
|
||||||
soundSquelch = *(uint8_t*) um_data->u_data[15];
|
soundSquelch = *(uint8_t*) um_data->u_data[15];
|
||||||
fftBin = (float*) um_data->u_data[16];
|
fftBin = (float*) um_data->u_data[16];
|
||||||
inputLevel = (uint8_t*) um_data->u_data[17]; // requires UI element (SEGMENT.customX?), changes source element
|
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
|
// add support for no audio data
|
||||||
um_data = simulateSound(SEGMENT.soundSim);
|
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.
|
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;
|
um_data_t *um_data;
|
||||||
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
|
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
|
||||||
um_data = simulateSound(SEGMENT.soundSim);
|
um_data = simulateSound(SEGMENT.soundSim);
|
||||||
}
|
}
|
||||||
float sampleAgc = *(float*) um_data->u_data[2];
|
float sampleAgc = *(float*) um_data->u_data[2];
|
||||||
uint16_t *myVals = (uint16_t*)um_data->u_data[14];
|
myVals[millis()%32] = sampleAgc; // filling values semi randomly
|
||||||
if (!myVals) return mode_static();
|
|
||||||
|
|
||||||
SEGMENT.fade_out(64+(SEGMENT.speed>>1));
|
SEGMENT.fade_out(64+(SEGMENT.speed>>1));
|
||||||
|
|
||||||
|
@ -415,7 +415,6 @@ um_data_t* simulateSound(uint8_t simulationId)
|
|||||||
|
|
||||||
//arrays
|
//arrays
|
||||||
uint8_t *fftResult;
|
uint8_t *fftResult;
|
||||||
uint8_t *myVals;
|
|
||||||
float *fftBin;
|
float *fftBin;
|
||||||
|
|
||||||
static um_data_t* um_data = nullptr;
|
static um_data_t* um_data = nullptr;
|
||||||
@ -423,7 +422,6 @@ um_data_t* simulateSound(uint8_t simulationId)
|
|||||||
if (!um_data) {
|
if (!um_data) {
|
||||||
//claim storage for arrays
|
//claim storage for arrays
|
||||||
fftResult = (uint8_t *)malloc(sizeof(uint8_t) * 16);
|
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)
|
fftBin = (float *)malloc(sizeof(float) * 256); // not used (for debugging purposes)
|
||||||
|
|
||||||
// initialize um_data pointer structure
|
// 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[ 9] = &maxVol;
|
||||||
um_data->u_data[10] = &binNum;
|
um_data->u_data[10] = &binNum;
|
||||||
um_data->u_data[11] = &multAgc;
|
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[13] = &sampleGain;
|
||||||
um_data->u_data[15] = &soundSquelch;
|
um_data->u_data[15] = &soundSquelch;
|
||||||
um_data->u_data[16] = fftBin; //only used in binmap
|
um_data->u_data[16] = fftBin; //only used in binmap
|
||||||
@ -453,7 +451,6 @@ um_data_t* simulateSound(uint8_t simulationId)
|
|||||||
} else {
|
} else {
|
||||||
// get arrays from um_data
|
// get arrays from um_data
|
||||||
fftResult = (uint8_t*)um_data->u_data[8];
|
fftResult = (uint8_t*)um_data->u_data[8];
|
||||||
myVals = (uint8_t*)um_data->u_data[14];
|
|
||||||
fftBin = (float*)um_data->u_data[16];
|
fftBin = (float*)um_data->u_data[16];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,7 +520,6 @@ um_data_t* simulateSound(uint8_t simulationId)
|
|||||||
FFT_MajorPeak = sampleAvg;
|
FFT_MajorPeak = sampleAvg;
|
||||||
FFT_Magnitude = sampleAvg;
|
FFT_Magnitude = sampleAvg;
|
||||||
multAgc = sampleAvg;
|
multAgc = sampleAvg;
|
||||||
myVals[millis()%32] = sampleAvg; // filling values semi randomly (why?)
|
|
||||||
sampleGain = 40;
|
sampleGain = 40;
|
||||||
soundSquelch = 10;
|
soundSquelch = 10;
|
||||||
maxVol = 10; // this gets feedback fro UI
|
maxVol = 10; // this gets feedback fro UI
|
||||||
|
Loading…
Reference in New Issue
Block a user