forked from marcelmaatkamp/java-sdr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphase.java
More file actions
75 lines (68 loc) · 1.95 KB
/
phase.java
File metadata and controls
75 lines (68 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Display signal phase diagram from FCD :)
import javax.sound.sampled.AudioFormat;
import java.nio.ByteBuffer;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class phase extends JPanel implements jsdr.JsdrTab {
private jsdr parent;
private AudioFormat fmt;
private int[] dpy;
private int max=1;
public phase(jsdr p, AudioFormat af, int bufsize) {
parent = p;
fmt = af;
int sbytes = (af.getSampleSizeInBits()+7)/8;
dpy = new int[bufsize/sbytes/af.getChannels()*2];
}
public void paintComponent(Graphics g) {
// Get constraining dimension and box offsets
int size = getWidth();
if (getHeight()<size)
size = getHeight();
int bx = (getWidth()-size)/2;
int by = (getHeight()-size)/2;
// Background..
g.setColor(Color.BLACK);
g.fillRect(0,0,getWidth(),getHeight());
// Reticle..
g.setColor(Color.DARK_GRAY);
g.drawOval(bx+10, by+10, size-20, size-20);
g.drawLine(bx+size/2, by+5, bx+size/2, by+size-5);
g.drawLine(bx+5, by+size/2, bx+size-5, by+size/2);
// I/Q offsets
g.setColor(Color.RED);
g.drawString("I: "+parent.ic, bx+2, by+12);
g.setColor(Color.BLUE);
g.drawString("Q: "+parent.qc, bx+2, by+22);
// Data points from buffer..
g.setColor(Color.YELLOW);
for(int s=0; s<dpy.length; s+=2) {
g.drawRect(bx+size/2+(dpy[s]*size/max), by+size/2-(dpy[s+1]*size/max), 0, 0);
}
g.drawString(""+max,getWidth()/2+2,12);
}
public void newBuffer(ByteBuffer buf) {
// Skip unless we are visible
if (!isVisible())
return;
// determine maxima of either axis for scaling
max=1;
for(int s=0; s<dpy.length; s+=2) {
dpy[s] = buf.getShort()+parent.ic;
if (fmt.getChannels()>1)
dpy[s+1] = buf.getShort()+parent.qc;
else
dpy[s+1] = 0;
max = Math.max(max, Math.abs(dpy[s]));
max = Math.max(max, Math.abs(dpy[s+1]));
}
// double maxima to get a nice graph..
max = Math.max(max*2,1);
repaint();
}
public void hotKey(char c) {
;
}
}