aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sio.c11
-rw-r--r--sio.h3
-rw-r--r--spectrogram.c72
3 files changed, 53 insertions, 33 deletions
diff --git a/sio.c b/sio.c
index a7d520f..0f6e067 100644
--- a/sio.c
+++ b/sio.c
@@ -22,7 +22,6 @@
#define RCHAN 2
#define BITS 16
#define SIGNED 1
-#define ROUND 1024 /* FFT is fastest with powers of two */
#define FPS 24
struct sio {
@@ -34,7 +33,7 @@ struct sio {
};
struct sio *
-init_sio()
+init_sio(int round)
{
struct sio *sio;
size_t bufsz;
@@ -66,7 +65,7 @@ init_sio()
sio->par.sig != SIGNED)
errx(1, "unsupported audio params");
- sio->round = ROUND;
+ sio->round = round;
bufsz = sio->par.rate / FPS; /* 24 pictures/second */
bufsz -= bufsz % sio->par.round; /* round to block size */
@@ -83,12 +82,6 @@ init_sio()
return sio;
}
-unsigned int
-get_round(struct sio *sio)
-{
- return sio->round;
-}
-
int16_t *
read_sio(struct sio *sio, size_t n)
{
diff --git a/sio.h b/sio.h
index 7e085d8..ae375a9 100644
--- a/sio.h
+++ b/sio.h
@@ -20,8 +20,7 @@
struct sio;
-struct sio *init_sio(void);
-unsigned int get_round(struct sio *);
+struct sio *init_sio(int);
int16_t *read_sio(struct sio *, size_t);
void del_sio(struct sio *);
diff --git a/spectrogram.c b/spectrogram.c
index b1b7720..d22b959 100644
--- a/spectrogram.c
+++ b/spectrogram.c
@@ -136,6 +136,7 @@ usage(void)
{
fprintf(stderr, "Usage: %s [-dh]\n", __progname);
fprintf(stderr, "\t-d\tdaemonize\n");
+ fprintf(stderr, "\t-f\tfullscreen\n");
fprintf(stderr, "\t-h\tthis help\n");
exit(0);
@@ -371,6 +372,26 @@ move(Display *dsp, Window win, Window container)
return 0;
}
+int
+gofullscreen(Display *d, Window win)
+{
+ XEvent xev;
+ Atom wm_state = XInternAtom(d, "_NET_WM_STATE", False);
+ Atom fullscreen = XInternAtom(d, "_NET_WM_STATE_FULLSCREEN", False);
+
+ memset(&xev, 0, sizeof(xev));
+ xev.type = ClientMessage;
+ xev.xclient.window = win;
+ xev.xclient.message_type = wm_state;
+ xev.xclient.format = 32;
+ xev.xclient.data.l[0] = 1;
+ xev.xclient.data.l[1] = fullscreen;
+ xev.xclient.data.l[2] = 0;
+
+ return XSendEvent(d, DefaultRootWindow(d), False,
+ SubstructureNotifyMask, &xev);
+}
+
int
main(int argc, char **argv)
{
@@ -388,17 +409,21 @@ main(int argc, char **argv)
struct fft *fft;
int16_t *buffer;
- int ch, dflag = 0;
- int delta;
+ int ch;
+ int dflag = 0;
+ int fflag = 0;
int width, height;
unsigned long black, white;
- float factor;
-
- while ((ch = getopt(argc, argv, "hd")) != -1)
+ float factor = 0.75;
+ int round = 1024; /* FFT is fastest with powers of two */
+ while ((ch = getopt(argc, argv, "dfh")) != -1)
switch (ch) {
case 'd':
dflag = 1;
break;
+ case 'f':
+ fflag = 1;
+ break;
case 'h':
default:
usage();
@@ -408,25 +433,25 @@ main(int argc, char **argv)
argv += optind;
signal(SIGINT, catch);
+
+ if (dflag)
+ daemon(0, 0);
dsp = XOpenDisplay(NULL);
if (!dsp)
errx(1, "Cannot connect to X11 server");
- sio = init_sio();
-
- if (dflag)
- daemon(0, 0);
-
- /* FIXME: not really useful */
- XGetWindowAttributes(dsp, DefaultRootWindow(dsp), &wa);
- factor = (float)wa.height / (float)wa.width;
- if (factor < 0.75)
- factor = 0.75;
+ if (fflag) {
+ XGetWindowAttributes(dsp, DefaultRootWindow(dsp), &wa);
+ round = wa.width - HGAP;
+ width = wa.width;
+ height = wa.height;
+ } else {
+ width = round + HGAP;
+ height = factor * width;
+ }
- delta = get_round(sio);
- width = delta + HGAP;
- height = factor * width;
+ sio = init_sio(round);
scr = DefaultScreen(dsp);
white = WhitePixel(dsp, scr);
@@ -434,6 +459,9 @@ main(int argc, char **argv)
win = XCreateSimpleWindow(dsp, RootWindow(dsp, scr),
0, 0, width, height, 0, white, black);
+
+ if (fflag && gofullscreen(dsp, win) != Success)
+ XMoveResizeWindow(dsp, win, 0, 0, wa.width, wa.height);
XStoreName(dsp, win, __progname);
class = XAllocClassHint();
@@ -462,15 +490,15 @@ main(int argc, char **argv)
0, 0, width, height, 0, white, black);
XMapWindow(dsp, container);
- left = init_panel(dsp, container, 0, 0, delta / 2, height, 1);
- right = init_panel(dsp, container, delta / 2 + HGAP, 0, delta / 2, height, 0);
- fft = init_fft(delta);
+ left = init_panel(dsp, container, 0, 0, round / 2, height, 1);
+ right = init_panel(dsp, container, round / 2 + HGAP, 0, round / 2, height, 0);
+ fft = init_fft(round);
XClearWindow(dsp, win);
XMapWindow(dsp, win);
while (!die) {
- buffer = read_sio(sio, delta);
+ buffer = read_sio(sio, round);
dofft(fft, buffer, left->data, 0);
dofft(fft, buffer, right->data, 1);