Skip to content

Commit a03a1da

Browse files
committed
somethings fishy
1 parent 9af03fd commit a03a1da

4 files changed

Lines changed: 44 additions & 42 deletions

File tree

JavaGUI/src/martin/tempest/ImageVisualizer.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@ public class ImageVisualizer extends JPanel {
2121
private int count = 0;
2222
private int fps;
2323

24-
private int color = 255;
25-
2624
public void drawImage(final BufferedImage image) {
27-
if (image != null) color = 0;
28-
if (todraw == null) todraw = image;
2925

30-
if (todraw != null && image != null) {
26+
if (todraw != null) {
3127
synchronized (todraw) {
3228
todraw = image;
3329
}
34-
35-
}
30+
} else
31+
todraw = image;
3632

33+
repaint();
34+
}
35+
36+
@Override
37+
public void paint(Graphics g) {
38+
3739
count++;
3840
if (count > COUNT_TO_AVG) {
3941
final long now = System.currentTimeMillis();
@@ -42,21 +44,13 @@ public void drawImage(final BufferedImage image) {
4244
prev = now;
4345
}
4446

45-
repaint();
46-
}
47-
48-
@Override
49-
public void paint(Graphics g) {
50-
51-
5247
if (todraw != null) {
5348
synchronized (todraw) {
5449
g.drawImage(todraw, 0, 0, getWidth(), getHeight(), null);
5550
}
5651
}
5752

58-
g.setColor(new Color(color, 255, color));
59-
color += 80; if (color > 255) color = 255;
53+
g.setColor(Color.white);
6054
g.fillRect(0, 0, 40, 20);
6155
g.setColor(Color.black);
6256
g.drawString(fps+" fps", 10, 15);

JavaGUI/src/martin/tempest/Main.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import java.awt.BorderLayout;
44
import java.awt.image.BufferedImage;
5+
import java.io.IOException;
56

7+
import javax.imageio.ImageIO;
68
import javax.swing.JFrame;
79

810
import martin.tempest.core.TSDRLibrary;
@@ -49,10 +51,13 @@ public void run() {
4951

5052
}
5153

54+
int fid = 0;
5255
@Override
5356
public void onFrameReady(TSDRLibrary lib, BufferedImage frame) {
54-
viz.drawImage(frame);
55-
try { lib.setSampleRate(0); } catch (Exception e) {};
57+
//viz.drawImage(frame);
58+
try {
59+
ImageIO.write(frame, "bmp", new java.io.File("D:\\temp\\"+(fid++)+".bmp"));
60+
} catch (IOException e) {}
5661
}
5762

5863
@Override

TSDRPlugin_RawFile/src/TSDRPlugin_RawFile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define TYPE_SHORT (2)
1717

1818
#define PERFORMANCE_BENCHMARK (0)
19-
#define ENABLE_LOOP (1)
19+
#define ENABLE_LOOP (0)
2020

2121
#define SAMPLES_TO_READ_AT_ONCE (512*1024)
2222

TempestSDR/src/TSDRLibrary.c

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ struct tsdr_context {
2626
void *ctx;
2727
CircBuff_t circbuf;
2828
double offset;
29-
double contributionfromlast;
30-
double max;
31-
double min;
29+
float contributionfromlast;
30+
float max;
31+
float min;
3232
} typedef tsdr_context_t;
3333

3434
int tsdr_setsamplerate(tsdr_lib_t * tsdr, uint32_t rate) {
@@ -122,6 +122,7 @@ void process(float *buf, uint32_t len, void *ctx) {
122122
int outbufsize = context->bufsize;
123123

124124
const double post = context->this->pixeltimeoversampletime;
125+
const double post1 = 1.0 / post;
125126
const int pids = (int) ((size - context->offset) / post);
126127

127128
// resize buffer so it fits
@@ -131,45 +132,47 @@ void process(float *buf, uint32_t len, void *ctx) {
131132
}
132133

133134
const double offset = context->offset;
134-
double t = context->offset;
135-
double contrib = context->contributionfromlast;
136-
const double prev_max = context->max;
137-
const double prev_min = context->min;
138-
const double prev_span = (prev_min == prev_max) ? (1) : (1.0f / (prev_max - prev_min));
139-
double max = -1, min = 1;
135+
double t = context->offset + post;
136+
float contrib = context->contributionfromlast;
137+
const float prev_max = context->max;
138+
const float prev_min = context->min;
139+
const float prev_span = (prev_min == prev_max) ? (1) : (1.0f / (prev_max - prev_min));
140+
float max = -1, min = 1;
140141

141142
int pid = 0;
142143
int i = 0;
143144
int id;
144145
int j;
145-
for (id = 0; id < size; id++) {
146-
const double I = buf[i++];
147-
const double Q = buf[i++];
148146

149-
const double val = sqrt(I*I+Q*Q);
147+
for (id = 1; id < size; id++) {
148+
const float I = buf[i++];
149+
const float Q = buf[i++];
150+
151+
const float val = sqrtf(I*I+Q*Q);
150152

151153
const int id1 = id+1;
152154

153-
while (t <= id1-post) {
154-
const double pix = (t >= id) ? (val) : ((contrib + val*(t+post-id))*post);
155+
while (t <= id1) {
156+
const float pix = (t >= id) ? (val) : ((contrib + val*(t-id))*post1);
155157
if (pix > max) max = pix; else if (pix < min) min = pix;
156158
outbuf[pid++] = (pix - prev_min) * prev_span;
157-
t=offset+pid*post;
159+
t+=post;
158160
contrib = 0;
159161
}
160162

161-
const double contrfract = id1-t;
162-
contrib += (contrfract >= 1) ? (val) : (contrfract * val);
163+
const float contrfract = id1-t+post;
164+
contrib += (contrfract < 0) ? (val) : (contrfract * val);
163165
}
164166

165-
if (pid != pids) printf("Pid %d is not pids %d", pid, pids);
166-
167167
context->bufsize = outbufsize;
168168
context->buffer = outbuf;
169-
context->offset = t-size;
169+
context->offset = offset+pid*post-size;
170170
context->contributionfromlast = contrib;
171-
context->max = (context->max+max)/2.0f;
172-
context->min = (context->min+min)/2.0f;
171+
context->max = max;
172+
context->min = min;
173+
174+
// if (pid != pids)
175+
// printf("Pid %d; pids %d; t %.4f, size %d, offset %.4f\n", pid, pids, t, size, context->offset);
173176

174177
cb_add(&context->circbuf, outbuf, pid);
175178
}

0 commit comments

Comments
 (0)