From 3408ce19b34c50ae566f52d3dad7638c41ae6dcd Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 17 Sep 2014 21:51:03 +0000 Subject: push data into widget --- Makefile | 4 ++-- Sgraph.c | 16 +++++++++++----- Sgraph.h | 11 ++++++----- SgraphP.h | 7 ++++--- alsa.c | 8 +------- sio.c | 19 +++++++------------ sio.h | 3 +-- spectrogram.c | 29 ++++++++++++++++++++++++++--- 8 files changed, 58 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index 2742460..661319d 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ VERSION=3.0 PROG= spectrogram SRCS= spectrogram.c fft.c cms.c aux.c widget.c Sgraph.c -LIBS= fftw3 x11 xaw7 +LIBS= fftw3 xt BINDIR= /usr/local/bin UNAME!= uname @@ -23,7 +23,7 @@ CFLAGS+=${PCCF} PCLA!= pkg-config --libs ${LIBS} LDADD+= ${PCLA} -DEBUG+= -Wall +DEBUG+= -Wall -ggdb NOMAN= DIR= ${PROG}-${VERSION} diff --git a/Sgraph.c b/Sgraph.c index c5b9804..9e4c89a 100644 --- a/Sgraph.c +++ b/Sgraph.c @@ -63,9 +63,12 @@ static XtResource resources[] = { { XtNrightData, XtCParameter, XtRPointer, sizeof(XtPointer), XtOffset(SgraphWidget, sgraph.rightData), XtRPointer, NULL }, - { XtNsizeData, XtCsizeData, XtRInt, - sizeof(int), XtOffset(SgraphWidget, sgraph.sizeData), + { XtNsize, XtCsize, XtRInt, + sizeof(int), XtOffset(SgraphWidget, sgraph.size), XtRImmediate, (XtPointer)2048 }, + { XtNsamples, XtCsamples, XtRInt, + sizeof(int), XtOffset(SgraphWidget, sgraph.samples), + XtRImmediate, (XtPointer)0 }, }; #undef offset @@ -152,8 +155,8 @@ Initialize(Widget request, Widget w, ArgList args, Cardinal *nargs) { SgraphWidget sw = (SgraphWidget)w; - sw->sgraph.leftData = XtCalloc(sw->sgraph.sizeData, sizeof(double)); - sw->sgraph.rightData = XtCalloc(sw->sgraph.sizeData, sizeof(double)); + sw->sgraph.leftData = (double *)XtCalloc(sw->sgraph.size, sizeof(double)); + sw->sgraph.rightData = (double *)XtCalloc(sw->sgraph.size, sizeof(double)); warnx("Initialize"); GetGC(w); @@ -184,7 +187,8 @@ Resize(Widget w) height = winheight; warnx("win: %dx%d", winwidth, winheight); warnx("sub: %dx%d", width, height); - warnx("size: %d", sw->sgraph.sizeData); + warnx("size: %d", sw->sgraph.size); + warnx("samples: %d", sw->sgraph.samples); if (sw->sgraph.bg != None) XFreePixmap(XtDisplay(sw), sw->sgraph.bg); @@ -223,6 +227,8 @@ Redisplay(Widget w, XEvent *event, Region r) width - 2 * BORDER, height - 2 * BORDER); */ + warnx("%lf : %lf" , sw->sgraph.leftData[0], sw->sgraph.rightData[0]); + XClearWindow(XtDisplay(sw), XtWindow(sw)); n = (n + 1) % width; XCopyArea(XtDisplay(sw), sw->sgraph.bg, XtWindow(sw), sw->sgraph.foreGC, diff --git a/Sgraph.h b/Sgraph.h index 367b3c1..13cb2c0 100644 --- a/Sgraph.h +++ b/Sgraph.h @@ -45,14 +45,15 @@ /* define any special resource names here that are not in */ #define XtNmirror "mirror" -#define XtNdata "data" + #define XtNleftData "leftData" #define XtNrightData "rightData" -#define XtNsizeData "sizeData" -#define XtCsizeData "SizeData" -#define XtNsgraphResource "sgraphResource" -#define XtCSgraphResource "SgraphResource" +#define XtNsamples "samples" +#define XtCsamples "Samples" + +#define XtNsize "size" +#define XtCsize "Size" /* declare specific SgraphWidget class and instance datatypes */ typedef struct _SgraphClassRec *SgraphWidgetClass; diff --git a/SgraphP.h b/SgraphP.h index cb0b209..b9597d5 100644 --- a/SgraphP.h +++ b/SgraphP.h @@ -41,9 +41,10 @@ typedef struct { Pixel foreground; Pixel background; Boolean mirror; - XtPointer leftData; - XtPointer rightData; - int sizeData; + double *leftData; + double *rightData; + int size; + int samples; GC foreGC; GC backGC; diff --git a/alsa.c b/alsa.c index cf99349..ebf0ad0 100644 --- a/alsa.c +++ b/alsa.c @@ -66,16 +66,10 @@ init_sio(void) snd_pcm_prepare(hdl); samples = rate / FPS; - samples -= samples % round - round; + samples -= samples % round; buffer = calloc(samples * STEREO, sizeof(int16_t)); assert(buffer); - return 0; -} - -unsigned int -max_samples_sio(void) -{ return samples; } diff --git a/sio.c b/sio.c index 43ffcd6..7104e9a 100644 --- a/sio.c +++ b/sio.c @@ -63,25 +63,18 @@ init_sio(void) errx(1, "unsupported audio params"); samples = par.rate / FPS; - samples -= samples % par.round - par.round; + samples -= samples % par.round; buffer = calloc(samples * par.rchan, sizeof(int16_t)); assert(buffer); - return sio_start(hdl); -} + warnx("%d, %d, %d", samples, par.rate, par.round); + + sio_start(hdl); -unsigned int -max_samples_sio(void) -{ - /* - * maximal number of samples we're willing to provide - * with 1920 at 25 fps and 48000 Hz or - * with 1764 at 25 fps and 44100 Hz it shall fit on most screens - */ return samples; } -void +size_t read_sio(double *left, double *right, size_t n) { int done, i; @@ -109,6 +102,8 @@ read_sio(double *left, double *right, size_t n) left[i] = data[i].left; right[i] = data[i].right; } + + return n; } void diff --git a/sio.h b/sio.h index b5b5d5e..b4ac675 100644 --- a/sio.h +++ b/sio.h @@ -20,8 +20,7 @@ __BEGIN_DECLS int init_sio(void); -void read_sio(double *, double *, size_t); -unsigned int max_samples_sio(void); +size_t read_sio(double *, double *, size_t); void free_sio(void); __END_DECLS diff --git a/spectrogram.c b/spectrogram.c index 8b86f90..da3f6e6 100644 --- a/spectrogram.c +++ b/spectrogram.c @@ -74,8 +74,23 @@ static Boolean worker(XtPointer data) { Arg arg[10]; - redisplay(XtDisplay(data), XtWindow(data)); - //XtSetValues(data, arg, 0); + int n, size, samples; + double *left, *right; + + n = 0; + XtSetArg(arg[n], XtNsize, &size); n++; + XtSetArg(arg[n], XtNsamples, &samples); n++; + XtSetArg(arg[n], XtNleftData, &left); n++; + XtSetArg(arg[n], XtNrightData, &right); n++; + XtGetValues(data, arg, n); + + size = read_sio(left, right, size); + //warnx("samples: %d, size: %d, %d", samples, size, n); + //warnx("l/r: %p (%lf) / %p (%lf)", left, *left, right, *right); + + n = 0; + XtSetArg(arg[n], XtNsize, size); n++; + XtSetValues(data, arg, n); /* trigger expose */ usleep(40); /* emulate 25 Hz */ return False; /* don't remove the work procedure from the list */ @@ -85,6 +100,8 @@ int main(int argc, char **argv) { Widget toplevel, sgraph; + int n, samples; + Arg args[10]; toplevel = XtInitialize(__progname, "Spectrograph", options, XtNumber(options), &argc, argv); @@ -93,8 +110,14 @@ main(int argc, char **argv) if (argc != 1) usage(); + samples = init_sio(); + warnx("samples: %d", samples); + + n = 0; + XtSetArg(args[n], XtNsamples, samples); n++; sgraph = XtCreateManagedWidget(__progname, sgraphWidgetClass, - toplevel, NULL, 0); + toplevel, args, n); + XtOverrideTranslations(sgraph, XtParseTranslationTable("q: quit()")); XtAddWorkProc(worker, sgraph); -- cgit v1.2.3