New way of dealing with recursive mixers and Flight Phases which saves ram...

This commit is contained in:
bsongis
2012-02-25 10:57:02 +00:00
parent a88e168b69
commit e91ac3d7cf
2 changed files with 15 additions and 26 deletions
+15 -25
View File
@@ -1400,16 +1400,12 @@ void perMain()
tick10ms = (tmr10ms != lastTMR);
lastTMR = tmr10ms;
#define MAX_ACT 0xffff
#define MAX_ACT 0xffff
static int16_t s_fp_chans[NUM_CHNOUT];
static uint16_t fp_act[MAX_PHASES] = {0};
static uint16_t delta = 0;
static uint8_t s_fade_flight_phases = 0;
static uint8_t s_last_phase = 255;
#ifdef PCBV4
static int16_t s_fp_chans[NUM_CHNOUT][MAX_PHASES];
#else
static int8_t s_fp_chans[NUM_CHNOUT][MAX_PHASES];
#endif
uint8_t phase = getFlightPhase();
if (s_last_phase != phase) {
@@ -1418,9 +1414,13 @@ void perMain()
}
else {
uint8_t fadeTime = max(g_model.phaseData[s_last_phase].fadeOut, g_model.phaseData[phase].fadeIn);
if (fadeTime) {
if (fadeTime) {
if (!s_fade_flight_phases) {
for (uint8_t i=0; i<NUM_CHNOUT; i++)
s_fp_chans[i] = chans[i];
}
s_fade_flight_phases |= (1<<s_last_phase) + (1<<phase);
delta = (MAX_ACT / 100) / fadeTime;
delta = (MAX_ACT / 100) / fadeTime;
}
else {
fp_act[s_last_phase] = 0;
@@ -1435,32 +1435,22 @@ void perMain()
if (s_fade_flight_phases) {
int32_t sum_chans512[NUM_CHNOUT] = {0};
int32_t weight = 0;
int32_t weight = 0;
for (uint8_t p=0; p<MAX_PHASES; p++) {
if (s_fade_flight_phases & (1<<p)) {
for (uint8_t i=0; i<NUM_CHNOUT; i++) {
#ifdef PCBV4
chans[i] = ((int32_t)s_fp_chans[i][p]) << 2;
#else
chans[i] = ((int32_t)s_fp_chans[i][p]) << 10;
#endif
}
for (uint8_t i=0; i<NUM_CHNOUT; i++)
chans[i] = s_fp_chans[i];
perOut(next_chans512, p);
for (uint8_t i=0; i<NUM_CHNOUT; i++) {
#ifdef PCBV4
s_fp_chans[i][p] = chans[i] >> 2;
#else
s_fp_chans[i][p] = chans[i] >> 10;
#endif
sum_chans512[i] += (int32_t)next_chans512[i] * fp_act[p];
}
for (uint8_t i=0; i<NUM_CHNOUT; i++)
sum_chans512[i] += (int32_t)next_chans512[i] * fp_act[p];
weight += fp_act[p];
}
}
// printf("sum=%d, weight=%d ", sum_chans512[2], weight); fflush(stdout);
assert(weight);
for (uint8_t i=0; i<NUM_CHNOUT; i++) {
next_chans512[i] = ((int32_t)sum_chans512[i] / weight);
next_chans512[i] = ((int32_t)sum_chans512[i] / weight);
s_fp_chans[i] = next_chans512[i];
}
// printf("output = %d\n", next_chans512[2]); fflush(stdout);
}
-1
View File
@@ -65,7 +65,6 @@
#endif
#include "file.h"
#include "lcd.h"
#include "myeeprom.h"