aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2014-10-02 09:52:04 +0000
committerDimitri Sokolyuk <demon@dim13.org>2014-10-02 09:52:04 +0000
commitf0ca536edd6089fb8030fc98df021239e99cb403 (patch)
tree552a45908e169a5fda9f9d5045ac426566f779ba
parent67d4601b4e0f6615da862b5728ae5c9f1201ea6d (diff)
deinterleave
-rw-r--r--Display.c8
-rw-r--r--Sgraph.c1
-rw-r--r--alsa.c14
-rw-r--r--sio.c26
-rw-r--r--sio.h9
-rw-r--r--spectrogram.c2
6 files changed, 28 insertions, 32 deletions
diff --git a/Display.c b/Display.c
index 7881b66..88e1785 100644
--- a/Display.c
+++ b/Display.c
@@ -11,7 +11,6 @@
} while (0)
static void Initialize(Widget, Widget, ArgList, Cardinal *);
-static XtGeometryResult GeometryManager(Widget, XtWidgetGeometry *, XtWidgetGeometry *);
static void ChangeManaged(Widget);
static void Resize(Widget);
static void Redisplay(Widget, XEvent *, Region);
@@ -89,13 +88,6 @@ Initialize(Widget req, Widget new, ArgList args, Cardinal *num_args)
Trace(new);
}
-static XtGeometryResult
-GeometryManager(Widget w, XtWidgetGeometry *request, XtWidgetGeometry *reply)
-{
- Trace(w);
- return XtGeometryYes;
-}
-
static void
ChangeManaged(Widget w)
{
diff --git a/Sgraph.c b/Sgraph.c
index eec068d..3bf6ae5 100644
--- a/Sgraph.c
+++ b/Sgraph.c
@@ -31,7 +31,6 @@ static void Initialize(Widget request, Widget w, ArgList args, Cardinal *nargs);
static void Realize(Widget w, XtValueMask *mask, XSetWindowAttributes *attr);
static void Resize(Widget w);
static void Redisplay(Widget w, XEvent *event, Region r);
-static Boolean SetValues(Widget old, Widget reference, Widget new, ArgList args, Cardinal *num_args);
static void mirror(Widget, XEvent *, String *, Cardinal *);
/* Initialization */
diff --git a/alsa.c b/alsa.c
index 8c875d5..bc7408a 100644
--- a/alsa.c
+++ b/alsa.c
@@ -79,10 +79,10 @@ init_sio(void)
}
size_t
-read_sio(int *left, int *right, size_t n)
+read_sio(int **out, size_t n)
{
snd_pcm_sframes_t rc;
- struct data *data;
+ int16_t *tmp;
int i;
if (n > samples)
@@ -95,13 +95,11 @@ read_sio(int *left, int *right, size_t n)
snd_pcm_prepare(hdl);
}
- data = (struct data *)&buffer[samples - n];
+ tmp = buffer[samples - n];
- /* split and normalize */
- for (i = 0; i < n; i++) {
- left[i] = data[i].left;
- right[i] = data[i].right;
- }
+ /* split */
+ for (i = 0; i < n * STEREO; i++)
+ out[i % STEREO][i / STEREO] = tmp[i];
return n;
}
diff --git a/sio.c b/sio.c
index 9416ee3..3dba68e 100644
--- a/sio.c
+++ b/sio.c
@@ -33,11 +33,6 @@ static struct sio_par par;
static int16_t *buffer;
static unsigned int samples;
-struct data {
- int16_t left;
- int16_t right;
-};
-
int
init_sio(void)
{
@@ -78,12 +73,12 @@ init_sio(void)
}
size_t
-read_sio(int *left, int *right, size_t n)
+read_sio(int **out, size_t n)
{
int done, i;
char *p = (char *)buffer;
size_t bufsz, rndsz;
- struct data *data;
+ int16_t *tmp;
if (n > samples)
n = samples;
@@ -101,13 +96,11 @@ read_sio(int *left, int *right, size_t n)
* return a pointer to the latest ROUND samples (the most recent
* ones) to minimize latency between picture and sound
*/
- data = (struct data *)(p - rndsz);
+ tmp = (int16_t *)(p - rndsz);
- /* split and normalize */
- for (i = 0; i < n; i++) {
- left[i] = data[i].left;
- right[i] = data[i].right;
- }
+ /* split */
+ for (i = 0; i < n * par.rchan; i++)
+ out[i % par.rchan][i / par.rchan] = tmp[i];
return n;
}
@@ -119,3 +112,10 @@ free_sio(void)
sio_close(hdl);
free(buffer);
}
+
+sio_input sndio = {
+ .name = "sndio",
+ .initialize = init_sio,
+ .read = NULL,
+ .destroy = free_sio,
+};
diff --git a/sio.h b/sio.h
index 97659c0..203a1f7 100644
--- a/sio.h
+++ b/sio.h
@@ -18,9 +18,16 @@
#ifndef __SIO_H
#define __SIO_H
+typedef struct {
+ char *name;
+ int (*initialize)(void);
+ size_t (*read)(int **, size_t);
+ void (*destroy)(void);
+} sio_input;
+
__BEGIN_DECLS
int init_sio(void);
-size_t read_sio(int *, int *, size_t);
+size_t read_sio(int **, size_t);
void free_sio(void);
__END_DECLS
diff --git a/spectrogram.c b/spectrogram.c
index 541ac41..8d08ba0 100644
--- a/spectrogram.c
+++ b/spectrogram.c
@@ -83,7 +83,7 @@ worker(XtPointer p)
XtSetArg(arg[n], XtNdata, &data); n++;
XtGetValues(p, arg, n);
- size = read_sio(data[0], data[1], size);
+ size = read_sio(data, size);
exec_fft(data[0], size);
exec_fft(data[1], size);