Skip to content

Commit dd225c9

Browse files
committed
Improved autobalance using a third array
1 parent 9776a55 commit dd225c9

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

TempestSDR/src/TSDRLibrary.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ void videodecodingthread(void * ctx) {
121121
int sizetopoll = height * width;
122122
float * buffer = (float *) malloc(sizeof(float) * bufsize);
123123
float * screenbuffer = (float *) malloc(sizeof(float) * bufsize);
124+
float * sendbuffer = (float *) malloc(sizeof(float) * bufsize);
124125
for (i = 0; i < bufsize; i++) screenbuffer[i] = 0.0f;
125126

126127
while (context->this->running) {
@@ -137,6 +138,7 @@ void videodecodingthread(void * ctx) {
137138
bufsize = sizetopoll;
138139
buffer = (float *) realloc(buffer, sizeof(float) * bufsize);
139140
screenbuffer = (float *) realloc(screenbuffer, sizeof(float) * bufsize);
141+
sendbuffer = (float *) realloc(sendbuffer, sizeof(float) * bufsize);
140142
for (i = 0; i < bufsize; i++) screenbuffer[i] = 0.0f;
141143
}
142144
}
@@ -146,18 +148,17 @@ void videodecodingthread(void * ctx) {
146148
float max = buffer[0];
147149
float min = max;
148150
for (i = 1; i < sizetopoll; i++) {
149-
const float val = buffer[i];
151+
const float val = screenbuffer[i] * lowpassvalue + buffer[i] * antilowpassvalue;
150152
if (val > max) max = val; else if (val < min) min = val;
153+
screenbuffer[i] = val;
151154
}
152155

153156
const float span = max - min;
154157

155-
for (i = 0; i < sizetopoll; i++) {
156-
const float val = (buffer[i] - min) / span;
157-
screenbuffer[i] = screenbuffer[i] * lowpassvalue + val * antilowpassvalue;
158-
}
158+
for (i = 0; i < sizetopoll; i++)
159+
sendbuffer[i] = (screenbuffer[i] - min) / span;
159160

160-
context->cb(screenbuffer, width, height, context->ctx);
161+
context->cb(sendbuffer, width, height, context->ctx);
161162
}
162163
}
163164

0 commit comments

Comments
 (0)