aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2015-12-30 19:20:20 +0000
committerFreeArtMan <dos21h@gmail.com>2015-12-30 19:20:20 +0000
commita9d66c6a759515c7061e2e8aac661eeb0082ea1e (patch)
treeda0bfb62d614fcad482cc5267f0a4348cbde5256
parent03a2ac933087722b3754f5eca349b26193e9bffd (diff)
downloadradiola-a9d66c6a759515c7061e2e8aac661eeb0082ea1e.tar.gz
radiola-a9d66c6a759515c7061e2e8aac661eeb0082ea1e.zip
More configurable sources. Move some math functions to core/math.h. Move delay filter from sdr_fm
-rw-r--r--Makefile3
-rw-r--r--README.md6
-rw-r--r--config/config_bsd.h4
-rw-r--r--config/config_linux.h4
-rw-r--r--core/make.mk11
-rw-r--r--core/math.c48
-rw-r--r--core/math.h16
-rw-r--r--draw/glui.c4
-rw-r--r--draw/glui.h4
-rw-r--r--filt/filt.h7
-rw-r--r--filt/filt_5th.c (renamed from filt/f_5th.c)2
-rw-r--r--filt/filt_delay.c51
-rw-r--r--filt/make.mk2
-rw-r--r--hw/aud.c2
-rw-r--r--hw/aud.h4
-rw-r--r--radiola.c9
-rw-r--r--test/Makefile2
-rw-r--r--test/sdr_fm.c94
-rw-r--r--test/ui_gl_waterfall.c5
-rw-r--r--test/ui_tui_waterfall.c16
20 files changed, 176 insertions, 118 deletions
diff --git a/Makefile b/Makefile
index b8a6721..d347f98 100644
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,7 @@ SOURCES=
OBJECTS=
OBJECTS_FINAL=
+include core/make.mk
include draw/make.mk
include filt/make.mk
include hw/make.mk
@@ -50,4 +51,4 @@ menuconfig-bsd: kconf2h
bsd: $(OBJECTS)
$(CC) $(OBJECTS_FINAL) $(PROJECT).c -o $(PROJECT) $(LDFLAGS_BSD)
- ld -r $(OBJECTS_FINAL) -o $(PROJECT).o \ No newline at end of file
+ ld -r $(OBJECTS_FINAL) -o $(PROJECT).o
diff --git a/README.md b/README.md
index b0e125e..0d4eecf 100644
--- a/README.md
+++ b/README.md
@@ -12,4 +12,8 @@ rtlsdr based sdr software, early prototype
## graphical waterfall
-![graphical waterfall](test/ui_gl.png) \ No newline at end of file
+![graphical waterfall](test/ui_gl.png)
+
+## Compile for *BSD
+
+make CFLAGS=-DCONFIG_OS_NETBSD bsd
diff --git a/config/config_bsd.h b/config/config_bsd.h
index a54486f..f74e647 100644
--- a/config/config_bsd.h
+++ b/config/config_bsd.h
@@ -1,5 +1,5 @@
-#ifndef __CONFIG_H
-#define __CONFIG_H
+#ifndef __CONFIG_BSD_H
+#define __CONFIG_BSD_H
#define CONFIG_CORE
#define CONFIG_OS_NETBSD
#define CONFIG_DRAW
diff --git a/config/config_linux.h b/config/config_linux.h
index 5fc9189..51c4a13 100644
--- a/config/config_linux.h
+++ b/config/config_linux.h
@@ -1,5 +1,5 @@
-#ifndef __CONFIG_H
-#define __CONFIG_H
+#ifndef __CONFIG_LINUX_H
+#define __CONFIG_LINUX_H
#define CONFIG_CORE
#define CONFIG_OS_LINUX
#define CONFIG_DRAW
diff --git a/core/make.mk b/core/make.mk
new file mode 100644
index 0000000..a1fe655
--- /dev/null
+++ b/core/make.mk
@@ -0,0 +1,11 @@
+DIR_CORE = core/
+SOURCES_CORE += core/math.c
+OBJECTS_CORE += $(SOURCES_CORE:.c=.o)
+LDFLAGS += -lm
+LDFLAGS_BSD += -lm
+
+
+OBJECTS_DIR_CORE += $(subst $(DIR_CORE),$(BUILD_DIR)$(DIR_CORE),$(OBJECTS_CORE))
+
+OBJECTS += $(OBJECTS_CORE)
+OBJECTS_FINAL += $(OBJECTS_DIR_CORE) \ No newline at end of file
diff --git a/core/math.c b/core/math.c
new file mode 100644
index 0000000..f962534
--- /dev/null
+++ b/core/math.c
@@ -0,0 +1,48 @@
+#include "math.h"
+
+
+float to_float(uint8_t x)
+{
+ return (1.0f/127.0f)*(((float)x)-127.0f);
+}
+
+
+//float ph_ch( uint8_t i1, uint8_t q1, uint8_t i2, uint8_t q2)
+float ph_ch( uint8_t i1, uint8_t q1 )
+{
+ static float complex last=0.0+0.0i;
+ float out;
+ float complex xy,c1;
+ //float c2;
+
+ c1 = to_float(i1) + I*to_float(q1);
+ //c1 = CMPLXF( to_float(i1), to_float(q1) );
+ //c2 = to_float(i2) + I*to_float(q2);
+ //c2 = CMPLXF( to_float(i2), to_float(q2) );
+ xy = conjf(last)*c1;
+ out = cargf( xy );
+ last = c1;
+
+ return out;
+}
+
+void rotate_90(uint8_t *buf, uint32_t len)
+/* 90 rotation is 1+0j, 0+1j, -1+0j, 0-1j
+ or [0, 1, -3, 2, -4, -5, 7, -6] */
+{
+ uint32_t i;
+ uint8_t tmp;
+ for (i=0; i<len; i+=8) {
+ /* uint8_t negation = 255 - x */
+ tmp = 255 - buf[i+3];
+ buf[i+3] = buf[i+2];
+ buf[i+2] = tmp;
+
+ buf[i+4] = 255 - buf[i+4];
+ buf[i+5] = 255 - buf[i+5];
+
+ tmp = 255 - buf[i+6];
+ buf[i+6] = buf[i+7];
+ buf[i+7] = tmp;
+ }
+} \ No newline at end of file
diff --git a/core/math.h b/core/math.h
new file mode 100644
index 0000000..dff1ffa
--- /dev/null
+++ b/core/math.h
@@ -0,0 +1,16 @@
+#ifndef __RADIOLA_MATH
+#define __RADIOLA_MATH
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <complex.h>
+#include <math.h>
+
+float to_float(uint8_t x);
+
+float ph_ch( uint8_t i1, uint8_t q1 );
+
+void rotate_90(uint8_t *buf, uint32_t len);
+
+#endif \ No newline at end of file
diff --git a/draw/glui.c b/draw/glui.c
index e056324..0f1e360 100644
--- a/draw/glui.c
+++ b/draw/glui.c
@@ -1,6 +1,6 @@
#include "glui.h"
-#if defined(OS_LINUX)
+#if def(OS_LINUX)
#define DEFAULT_TITLE "RADIOLA"
#define SCREEN_X 1024
@@ -171,4 +171,4 @@ int glui_close( glui_t *t )
return ret;
}
-#endif \ No newline at end of file
+#endif
diff --git a/draw/glui.h b/draw/glui.h
index 17c49da..9206bdf 100644
--- a/draw/glui.h
+++ b/draw/glui.h
@@ -9,7 +9,7 @@
#include <termios.h>
#include <unistd.h>
-#if defined(OS_LINUX)
+#if def(OS_LINUX)
#include <SDL2/SDL.h>
@@ -60,4 +60,4 @@ glui_color_t glui_waterfall_color( uint8_t d );
//close terminal ui
int glui_close( glui_t *t );
#endif
-#endif \ No newline at end of file
+#endif
diff --git a/filt/filt.h b/filt/filt.h
index d235449..9ce2caa 100644
--- a/filt/filt.h
+++ b/filt/filt.h
@@ -3,9 +3,14 @@
#include <stdlib.h>
#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
#include <unistd.h>
//fifth order filter from rtlsdr
-void f_5th(int16_t *data, int length, int16_t *hist);
+void filt_5th(int16_t *data, int length, int16_t *hist);
+
+//delay filtering from https://github.com/dpiponi/mini_fm.git
+void filt_delay( uint8_t *buf, int buf_len );
#endif \ No newline at end of file
diff --git a/filt/f_5th.c b/filt/filt_5th.c
index 811fb18..23d5aab 100644
--- a/filt/f_5th.c
+++ b/filt/filt_5th.c
@@ -29,4 +29,4 @@ void f_5th(int16_t *data, int length, int16_t *hist)
hist[3] = d;
hist[4] = e;
hist[5] = f;
-} \ No newline at end of file
+}
diff --git a/filt/filt_delay.c b/filt/filt_delay.c
new file mode 100644
index 0000000..53da0b0
--- /dev/null
+++ b/filt/filt_delay.c
@@ -0,0 +1,51 @@
+#include "filt.h"
+
+//delay filtering
+void filt_delay( uint8_t *buf, int buf_len )
+{
+ //delay length
+ const int n=10;
+
+ int i=0;
+ uint32_t cycle=0;
+ uint32_t avg_i=0, avg_q=0;
+ uint32_t cyc_buffer_i[n],delay_i=0;
+ uint32_t cyc_buffer_q[n],delay_q=0;
+ uint8_t in1=0,in2=0,out1=0,out2=0;
+
+ memset( cyc_buffer_i, 0, n*sizeof(uint32_t) );
+ memset( cyc_buffer_q, 0, n*sizeof(uint32_t) );
+
+ //for (i=0; i<(buf_len-(n*2));i+=2)
+ for (i=0 ; i<(buf_len-1) ; i+=2 )
+ //for (i=0; i<1000; i+=2)
+ {
+ in1 = buf[i];
+ in2 = buf[i+1];
+
+ //average
+ avg_i += (uint32_t)in1;
+ avg_q += (uint32_t)in2;
+
+ delay_i = cyc_buffer_i[cycle];
+ delay_q = cyc_buffer_q[cycle];
+
+ cyc_buffer_i[cycle] = avg_i;
+ cyc_buffer_q[cycle] = avg_q;
+ cycle = cycle + 1;
+ if ( cycle >= n )
+ {
+ cycle = 0;
+ }
+
+ out1 = (avg_i - delay_i)/n;
+ out2 = (avg_q - delay_q)/n;
+
+ buf[i] = out1;
+ buf[i+1] = out2;
+
+ //printf("%d,avg=[%d,%d],delay=[%d,%d],in=[%d,%d],out=[%d,%d]\n",
+ // cycle, avg_i,avg_q,delay_i,delay_q,in1,in2,out1,out2);
+
+ }
+} \ No newline at end of file
diff --git a/filt/make.mk b/filt/make.mk
index bde2fe3..be7468f 100644
--- a/filt/make.mk
+++ b/filt/make.mk
@@ -1,5 +1,5 @@
DIR_FILT = filt/
-SOURCES_FILT += filt/f_5th.c
+SOURCES_FILT += filt/filt_5th.c filt/filt_delay.c
OBJECTS_FILT += $(SOURCES_FILT:.c=.o)
LDFLAGS +=
LDFLAGS_BSD +=
diff --git a/hw/aud.c b/hw/aud.c
index 4c51dcc..ade60cb 100644
--- a/hw/aud.c
+++ b/hw/aud.c
@@ -1,6 +1,6 @@
#include "aud.h"
-#if defined(OS_LINUX)
+#if def(OS_LINUX)
//harc-copy from aplay.c static void device_list(void)
int audio_get_devices()
{
diff --git a/hw/aud.h b/hw/aud.h
index 396c27d..974646a 100644
--- a/hw/aud.h
+++ b/hw/aud.h
@@ -6,9 +6,9 @@
#include <stdlib.h>
#include <stdint.h>
-#if defined(OS_LINUX)
+#if def(OS_LINUX)
#include <alsa/asoundlib.h>
#endif
int audio_get_devices();
-#endif \ No newline at end of file
+#endif
diff --git a/radiola.c b/radiola.c
index c7279fa..aaaf047 100644
--- a/radiola.c
+++ b/radiola.c
@@ -6,5 +6,12 @@
int main()
{
+#if def(OS_LINUX)
+ printf("Compiled in Linux comp mode\n");
+#elif def(OS_NETBSD)
+ printf("Compiled in NetBSD comp mode\n");
+#else
+ printf("Unknown mode\n");
+#endif
return 0;
-} \ No newline at end of file
+}
diff --git a/test/Makefile b/test/Makefile
index c447b55..05714ae 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,5 +1,5 @@
CC=gcc
-CFLAGS=-std=gnu11 -I../
+CFLAGS=-I../
#LDFLAGS= `pkg-config --libs libusb` -L../../../r820t -lr820t -Wl,-rpath=../../../r820t
LDFLAGS=`pkg-config --libs libusb` `sdl2-config --cflags --libs` -lrtlsdr -lm ../radiola.o -lasound
SOURCE = $(wildcard *.c)
diff --git a/test/sdr_fm.c b/test/sdr_fm.c
index a7f5551..4fc4c98 100644
--- a/test/sdr_fm.c
+++ b/test/sdr_fm.c
@@ -8,8 +8,10 @@
#include <sys/timeb.h>
+#include <core/math.h>
#include <hw/hw.h>
#include <hw/sdr.h>
+#include <filt/filt.h>
#define SAMPLE_RATE 1000000
#define RESAMPLE_RATE 50000
@@ -149,99 +151,9 @@ uint8_t super_div20u8( uint16_t num )
return (uint8_t)r;
}
-void rotate_90(uint8_t *buf, uint32_t len)
-/* 90 rotation is 1+0j, 0+1j, -1+0j, 0-1j
- or [0, 1, -3, 2, -4, -5, 7, -6] */
-{
- uint32_t i;
- uint8_t tmp;
- for (i=0; i<len; i+=8) {
- /* uint8_t negation = 255 - x */
- tmp = 255 - buf[i+3];
- buf[i+3] = buf[i+2];
- buf[i+2] = tmp;
-
- buf[i+4] = 255 - buf[i+4];
- buf[i+5] = 255 - buf[i+5];
-
- tmp = 255 - buf[i+6];
- buf[i+6] = buf[i+7];
- buf[i+7] = tmp;
- }
-}
-
-float to_float(uint8_t x) {
- return (1.0f/127.0f)*(((float)x)-127.0f);
-}
-//float ph_ch( uint8_t i1, uint8_t q1, uint8_t i2, uint8_t q2)
-float ph_ch( uint8_t i1, uint8_t q1 )
-{
- static float complex last=0.0+0.0i;
- float out;
- float complex xy,c1;
- //float c2;
-
- c1 = to_float(i1) + I*to_float(q1);
- //c1 = CMPLXF( to_float(i1), to_float(q1) );
- //c2 = to_float(i2) + I*to_float(q2);
- //c2 = CMPLXF( to_float(i2), to_float(q2) );
- xy = conjf(last)*c1;
- out = cargf( xy );
- last = c1;
-
- return out;
-}
-
-//delay filtering
-void delay_filt( uint8_t *buf, int buf_len )
-{
- //delay length
- const int n=10;
-
- int i=0;
- uint32_t cycle=0;
- uint32_t avg_i=0, avg_q=0;
- uint32_t cyc_buffer_i[n],delay_i=0;
- uint32_t cyc_buffer_q[n],delay_q=0;
- uint8_t in1=0,in2=0,out1=0,out2=0;
-
- memset( cyc_buffer_i, 0, n*sizeof(uint32_t) );
- memset( cyc_buffer_q, 0, n*sizeof(uint32_t) );
-
- //for (i=0; i<(buf_len-(n*2));i+=2)
- for (i=0 ; i<(buf_len-1) ; i+=2 )
- //for (i=0; i<1000; i+=2)
- {
- in1 = buf[i];
- in2 = buf[i+1];
- //average
- avg_i += (uint32_t)in1;
- avg_q += (uint32_t)in2;
- delay_i = cyc_buffer_i[cycle];
- delay_q = cyc_buffer_q[cycle];
-
- cyc_buffer_i[cycle] = avg_i;
- cyc_buffer_q[cycle] = avg_q;
- cycle = cycle + 1;
- if ( cycle >= n )
- {
- cycle = 0;
- }
-
- out1 = (avg_i - delay_i)/n;
- out2 = (avg_q - delay_q)/n;
-
- buf[i] = out1;
- buf[i+1] = out2;
-
- //printf("%d,avg=[%d,%d],delay=[%d,%d],in=[%d,%d],out=[%d,%d]\n",
- // cycle, avg_i,avg_q,delay_i,delay_q,in1,in2,out1,out2);
-
- }
-}
int main( int argc, char **argv )
{
@@ -334,7 +246,7 @@ int main( int argc, char **argv )
// fbuf[i] = to_float(sample_buf[i]);
//}
//delay boxed filter
- delay_filt( sample_buf, sample_len );
+ filt_delay( sample_buf, sample_len );
//rotate by 90 degrees uint8_t
diff --git a/test/ui_gl_waterfall.c b/test/ui_gl_waterfall.c
index 837383f..33fbdb6 100644
--- a/test/ui_gl_waterfall.c
+++ b/test/ui_gl_waterfall.c
@@ -6,6 +6,9 @@
#include <getopt.h>
//radiola
+//#define CONFIG_OS_LINUX
+//#include <config.h>
+//#include <config/config_linux.h>
#include <draw/glui.h>
#include <hw/hw.h>
#include <hw/sdr.h>
@@ -329,4 +332,4 @@ main_exit:
sdr_close( sdr );
return 0;
-} \ No newline at end of file
+}
diff --git a/test/ui_tui_waterfall.c b/test/ui_tui_waterfall.c
index cc63fc3..82362c1 100644
--- a/test/ui_tui_waterfall.c
+++ b/test/ui_tui_waterfall.c
@@ -8,14 +8,14 @@
#include <hw/hw.h>
#include <hw/sdr.h>
-#define SAMPLE_RATE 2048000
-
-#define CENTER_FREQ 445500000
-#define FFT_LEVEL 10
-#define FFT_SIZE (1 << FFT_LEVEL)
-#define SAMPLE_LENGHT (2 * FFT_SIZE)
-#define PRESCALE 8
-#define POSTSCALE 2
+#define SAMPLE_RATE 2048000
+
+#define CENTER_FREQ 445500000
+#define FFT_LEVEL 10
+#define FFT_SIZE (1 << FFT_LEVEL)
+#define SAMPLE_LENGHT (2 * FFT_SIZE)
+#define PRESCALE 8
+#define POSTSCALE 2
int16_t* Sinewave;