aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2014-09-18 15:49:38 +0000
committerDimitri Sokolyuk <demon@dim13.org>2014-09-18 15:49:38 +0000
commit60c1097c987fb516474cdae9f1f9d2bab6c3c6f1 (patch)
tree409dc11eece73424e840d12d8ff0dec72a20da6d
parentf0a7687ebd6eab275c3e1f0b3f753b556c74246b (diff)
add normalization
-rw-r--r--Sgraph.c8
-rw-r--r--alsa.c6
-rw-r--r--sio.c6
3 files changed, 14 insertions, 6 deletions
diff --git a/Sgraph.c b/Sgraph.c
index b06544f..e18a2de 100644
--- a/Sgraph.c
+++ b/Sgraph.c
@@ -249,9 +249,13 @@ Redisplay(Widget w, XEvent *event, Region r)
XDrawLine(XtDisplay(sw), sw->sgraph.backBuf, sw->sgraph.foreGC,
0, height / 2 + height, 2 * width, height / 2 + height);
for (x = 0; x < sw->sgraph.size; x++) {
- yl = sw->sgraph.leftData[x] / (2 * height) + height / 2;
- yr = sw->sgraph.rightData[x] / (2 * height) + height / 2;
+ yl = sw->sgraph.leftData[x] * height / 2;
+ yl += height / 2;
+
+ yr = sw->sgraph.rightData[x] * height / 2;
+ yr += height / 2;
yr += height;
+
XDrawPoint(XtDisplay(sw), sw->sgraph.backBuf,
sw->sgraph.foreGC, x, yl);
XDrawPoint(XtDisplay(sw), sw->sgraph.backBuf,
diff --git a/alsa.c b/alsa.c
index 881246f..e311ed5 100644
--- a/alsa.c
+++ b/alsa.c
@@ -17,6 +17,7 @@
#include <assert.h>
#include <err.h>
+#include <stdint.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>
@@ -92,9 +93,10 @@ read_sio(double *left, double *right, size_t n)
data = (struct data *)&buffer[samples - n];
+ /* split and normalize */
for (i = 0; i < n; i++) {
- left[i] = data[i].left;
- right[i] = data[i].right;
+ left[i] = data[i].left / (double)INT16_MAX;
+ right[i] = data[i].right / (double)INT16_MAX;
}
return n;
diff --git a/sio.c b/sio.c
index 414de7c..6e76f8f 100644
--- a/sio.c
+++ b/sio.c
@@ -17,6 +17,7 @@
#include <assert.h>
#include <err.h>
+#include <sndint.h>
#include <sndio.h>
#include <stdlib.h>
@@ -100,9 +101,10 @@ read_sio(double *left, double *right, size_t n)
*/
data = (struct data *)(p - rndsz);
+ /* split and normalize */
for (i = 0; i < n; i++) {
- left[i] = data[i].left;
- right[i] = data[i].right;
+ left[i] = data[i].left / (double)INT16_MAX;
+ right[i] = data[i].right / (double)INT16_MAX;
}
return n;