tscope_print API
This commit is contained in:
parent
5cbaa98027
commit
560e15ba8d
@ -9,5 +9,5 @@ minimodem_LDADD = $(DEPS_LIBS)
|
||||
minimodem_SOURCES = minimodem.c
|
||||
|
||||
tscope_LDADD = $(DEPS_LIBS)
|
||||
tscope_SOURCES = tscope.c
|
||||
tscope_SOURCES = tscope.c tscope_print.c
|
||||
|
||||
|
@ -49,7 +49,7 @@ am_minimodem_OBJECTS = minimodem.$(OBJEXT)
|
||||
minimodem_OBJECTS = $(am_minimodem_OBJECTS)
|
||||
am__DEPENDENCIES_1 =
|
||||
minimodem_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
am_tscope_OBJECTS = tscope.$(OBJEXT)
|
||||
am_tscope_OBJECTS = tscope.$(OBJEXT) tscope_print.$(OBJEXT)
|
||||
tscope_OBJECTS = $(am_tscope_OBJECTS)
|
||||
tscope_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
|
||||
@ -158,7 +158,7 @@ INCLUDES = $(DEPS_CFLAGS)
|
||||
minimodem_LDADD = $(DEPS_LIBS)
|
||||
minimodem_SOURCES = minimodem.c
|
||||
tscope_LDADD = $(DEPS_LIBS)
|
||||
tscope_SOURCES = tscope.c
|
||||
tscope_SOURCES = tscope.c tscope_print.c
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
@ -245,6 +245,7 @@ distclean-compile:
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/minimodem.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tscope.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tscope_print.Po@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
|
47
src/tscope.c
47
src/tscope.c
@ -27,47 +27,7 @@
|
||||
|
||||
#include <fftw3.h>
|
||||
|
||||
|
||||
static inline
|
||||
float
|
||||
band_mag( fftwf_complex * const cplx, unsigned int band, float scalar )
|
||||
{
|
||||
float re = cplx[band][0];
|
||||
float im = cplx[band][1];
|
||||
float mag = hypot(re, im) * scalar;
|
||||
return mag;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
tscope_print( fftwf_complex * const fftout, int nbands, float magscalar,
|
||||
unsigned char one_line_mode, unsigned char show_maxmag )
|
||||
{
|
||||
char magchars[] = " .-=+#^";
|
||||
char *buf = alloca(nbands+1);
|
||||
if ( one_line_mode )
|
||||
magchars[0] = '_';
|
||||
float maxmag = 0;
|
||||
int i;
|
||||
for ( i=0; i<nbands; i++ ) {
|
||||
float mag = band_mag(fftout, i, magscalar);
|
||||
if ( mag > maxmag )
|
||||
maxmag = mag;
|
||||
char c;
|
||||
if ( mag <= 0.05 ) c = magchars[0];
|
||||
else if ( mag <= 0.10 ) c = magchars[1];
|
||||
else if ( mag <= 0.25 ) c = magchars[2];
|
||||
else if ( mag <= 0.50 ) c = magchars[3];
|
||||
else if ( mag <= 0.95 ) c = magchars[4];
|
||||
else if ( mag <= 1.00 ) c = magchars[5];
|
||||
else c = magchars[6];
|
||||
buf[i] = c;
|
||||
}
|
||||
buf[i] = 0;
|
||||
if ( show_maxmag )
|
||||
printf(" %.2f", maxmag);
|
||||
printf("|%s|", buf);
|
||||
}
|
||||
#include "tscope_print.h"
|
||||
|
||||
|
||||
int
|
||||
@ -87,6 +47,9 @@ main( int argc, char*argv[] )
|
||||
int one_line_mode = 1;
|
||||
int show_maxmag = 1;
|
||||
|
||||
if ( ! isatty(1) )
|
||||
one_line_mode = 0;
|
||||
|
||||
int argi = 1;
|
||||
while ( argi < argc && argv[argi][0] == '-' ) {
|
||||
/* -s switch enables "scrolling mode" instead of "one line mode" */
|
||||
@ -198,7 +161,7 @@ main( int argc, char*argv[] )
|
||||
int n;
|
||||
for ( n=0; n<pa_nchannels; n++ )
|
||||
tscope_print(fftout+n*nbands, show_nbands, magscalar,
|
||||
one_line_mode, show_maxmag);
|
||||
one_line_mode, show_maxmag);
|
||||
printf( one_line_mode ? "\r" : "\n" );
|
||||
fflush(stdout);
|
||||
}
|
||||
|
63
src/tscope_print.c
Normal file
63
src/tscope_print.c
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* tscope_print.c
|
||||
*
|
||||
* Author: Kamal Mostafa <kamal@whence.com>
|
||||
*
|
||||
* Unpublished work, not licensed for any purpose.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <alloca.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <fftw3.h>
|
||||
|
||||
#include "tscope_print.h"
|
||||
|
||||
|
||||
static inline
|
||||
float
|
||||
band_mag( fftwf_complex * const cplx, unsigned int band, float scalar )
|
||||
{
|
||||
float re = cplx[band][0];
|
||||
float im = cplx[band][1];
|
||||
float mag = hypot(re, im) * scalar;
|
||||
return mag;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
tscope_print( fftwf_complex * const fftout, int nbands, float magscalar,
|
||||
int one_line_mode, int show_maxmag )
|
||||
{
|
||||
char *buf = alloca(nbands+1);
|
||||
char magchars[] = " .-=+#^";
|
||||
if ( one_line_mode )
|
||||
magchars[0] = '_';
|
||||
float maxmag = 0;
|
||||
int i;
|
||||
for ( i=0; i<nbands; i++ ) {
|
||||
char c;
|
||||
float mag = band_mag(fftout, i, magscalar);
|
||||
if ( maxmag < mag )
|
||||
maxmag = mag;
|
||||
if ( mag <= 0.05 ) c = magchars[0];
|
||||
else if ( mag <= 0.10 ) c = magchars[1];
|
||||
else if ( mag <= 0.25 ) c = magchars[2];
|
||||
else if ( mag <= 0.50 ) c = magchars[3];
|
||||
else if ( mag <= 0.95 ) c = magchars[4];
|
||||
else if ( mag <= 1.00 ) c = magchars[5];
|
||||
else c = magchars[6];
|
||||
buf[i] = c;
|
||||
}
|
||||
buf[i] = 0;
|
||||
if ( show_maxmag )
|
||||
printf(" %.2f", maxmag);
|
||||
printf("|%s|", buf);
|
||||
}
|
||||
|
15
src/tscope_print.h
Normal file
15
src/tscope_print.h
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* tscope_print.h
|
||||
*
|
||||
* Author: Kamal Mostafa <kamal@whence.com>
|
||||
*
|
||||
* Unpublished work, not licensed for any purpose.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <fftw3.h>
|
||||
|
||||
extern void
|
||||
tscope_print( fftwf_complex * const fftout, int nbands, float magscalar,
|
||||
int one_line_mode, int show_maxmag );
|
||||
|
Loading…
x
Reference in New Issue
Block a user