Compare commits

..

1 commit

Author SHA1 Message Date
ha7ilm
73e0e02d2e Non-blocking the client pipes screws things up. 2015-12-03 11:37:28 +01:00
40 changed files with 4627 additions and 19875 deletions

10
.gitignore vendored
View file

@ -1,10 +0,0 @@
csdr
nmux
ddcd
*.o
*.so
*.so.*
tags
dumpvect.*.vect
*.swp
grc_tests/top_block.py

View file

@ -1,15 +0,0 @@
First of all, thank you for taking the time to contribute to this project!
Before I can accept your contributions, I need a signed copy of the Individual Contributor License Agreement (ICLA) from you, which is available <a href="ICLA.txt">here</a>.
The ICLA is needed because it will allow me to dual license the OpenWebRX project under AGPL and a commercial license.
I will also apply dual licensing to csdr, but only those parts that are original work (e.g. without the parts enabled by `-DUSE_IMA_ADPCM`; code taken from other projects is clearly separable).
However, even if there is commercial interest in the projects, I promise to keep them as open as possible, keeping my original intention to provide an open-source web-based SDR receiver software to the amateur radio operators and SDR enthusiasts.
This contributor agreement is based on the one of Apache Software Foundation, with some modifications.
When you contribute for the first time, I will send you the ICLA. Replying with only the information requested and the text "I Agree" is sufficient.
Thanks,
Andras, HA7ILM

128
ICLA.txt
View file

@ -1,128 +0,0 @@
Individual Contributor License Agreement ("Agreement")
In order to clarify the intellectual property license granted
with Contributions from any person or entity, András Retzler
(hereinafter referred to as "Project Owner") must have a
Contributor License Agreement ("CLA") on file that has
been signed by each Contributor, indicating agreement to the license
terms below. This license is for your protection as a Contributor as
well as the protection of the Project Owner; it does not change your
rights to use your own Contributions for any other purpose.
Please read this document carefully before signing and keep a copy
for your records.
Full name: ______________________________________________________
(optional) Public name: _________________________________________
Mailing Address: ________________________________________________
________________________________________________
Country: ______________________________________________________
(optional) Telephone: ___________________________________________
E-Mail: ______________________________________________________
You accept and agree to the following terms and conditions for Your
present and future Contributions submitted to the Project Owner.
Except for the license granted herein to the Project Owner and recipients
of software distributed by the Project Owner, You reserve all right, title,
and interest in and to Your Contributions.
1. Definitions.
"You" (or "Your") shall mean the copyright owner or legal entity
authorized by the copyright owner that is making this Agreement
with the Project Owner. For legal entities, the entity making a
Contribution and all other entities that control, are controlled
by, or are under common control with that entity are considered to
be a single Contributor. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"Contribution" shall mean any original work of authorship,
including any modifications or additions to an existing work, that
is intentionally submitted by You to the Project Owner for inclusion
in, or documentation of, any of the products owned or managed by
the Project Owner (the "Work"). For the purposes of this definition,
"submitted" means any form of electronic, verbal, or written
communication sent to the Project Owner or its representatives,
including but not limited to communication on electronic mailing
lists, source code control systems, and issue tracking systems that
are managed by, or on behalf of, the Project Owner for the purpose of
discussing and improving the Work, but excluding communication that
is conspicuously marked or otherwise designated in writing by You
as "Not a Contribution."
2. Grant of Copyright License. Subject to the terms and conditions of
this Agreement, You hereby grant to the Project Owner and to
recipients of software distributed by the Project Owner a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare derivative works of,
publicly display, publicly perform, sublicense, and distribute Your
Contributions and such derivative works.
3. Grant of Patent License. Subject to the terms and conditions of
this Agreement, You hereby grant to the Project Owner and to
recipients of software distributed by the Project Owner a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have
made, use, offer to sell, sell, import, and otherwise transfer the
Work, where such license applies only to those patent claims
licensable by You that are necessarily infringed by Your
Contribution(s) alone or by combination of Your Contribution(s)
with the Work to which such Contribution(s) was submitted. If any
entity institutes patent litigation against You or any other entity
(including a cross-claim or counterclaim in a lawsuit) alleging
that your Contribution, or the Work to which you have contributed,
constitutes direct or contributory patent infringement, then any
patent licenses granted to that entity under this Agreement for
that Contribution or Work shall terminate as of the date such
litigation is filed.
4. You represent that you are legally entitled to grant the above
license. If your employer(s) has rights to intellectual property
that you create that includes your Contributions, you represent
that you have received permission to make Contributions on behalf
of that employer, that your employer has waived such rights for
your Contributions to the Project Owner, or that your employer has
executed a separate Corporate CLA with the Project Owner.
5. You represent that each of Your Contributions is Your original
creation (see section 7 for submissions on behalf of others). You
represent that Your Contribution submissions include complete
details of any third-party license or other restriction (including,
but not limited to, related patents and trademarks) of which you
are personally aware and which are associated with any part of Your
Contributions.
6. You are not expected to provide support for Your Contributions,
except to the extent You desire to provide support. You may provide
support for free, for a fee, or not at all. Unless required by
applicable law or agreed to in writing, You provide Your
Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied, including, without
limitation, any warranties or conditions of TITLE, NON-
INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
7. Should You wish to submit work that is not Your original creation,
You may submit it to the Project Owner separately from any
Contribution, identifying the complete details of its source and of
any license or other restriction (including, but not limited to,
related patents, trademarks, and license agreements) of which you
are personally aware, and conspicuously marking the work as
"Submitted on behalf of a third-party: [named here]".
8. You agree to notify the Project Owner of any facts or circumstances of
which you become aware that would make these representations
inaccurate in any respect.
Please sign: __________________________________ Date: ________________
Text derived from the Apache Individual Contributor License Agreement
("Agreement") V2.0, available at http://apache.org/licenses/icla.txt

View file

@ -26,57 +26,54 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
LIBSOURCES = fft_fftw.c libcsdr_wrapper.c
#SOURCES = csdr.c $(LIBSOURCES)
PARAMS_SIMD = $(shell ./detect_params.sh)
cpufeature = $(if $(findstring $(1),$(shell cat /proc/cpuinfo)),$(2))
PARAMS_SSE = $(call cpufeature,sse,-msse) $(call cpufeature,sse2,-msse2) $(call cpufeature,sse3,-msse3) $(call cpufeature,sse4,-msse4) $(call cpufeature,sse4_1,-msse4.1) $(call cpufeature,sse4_2,-msse4.2) -mfpmath=sse
PARAMS_NEON = -mfloat-abi=hard -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mvectorize-with-neon-quad -funsafe-math-optimizations -Wformat=0 -DNEON_OPTS
#tnx Jan Szumiec for the Raspberry Pi support
PARAMS_RASPI = -mfloat-abi=hard -mcpu=arm1176jzf-s -mfpu=vfp -funsafe-math-optimizations -Wformat=0
PARAMS_ARM = $(if $(call cpufeature,BCM2708,dummy-text),$(PARAMS_RASPI),$(PARAMS_NEON))
PARAMS_SIMD = $(if $(call cpufeature,sse,dummy-text),$(PARAMS_SSE),$(PARAMS_ARM))
PARAMS_LOOPVECT = -O3 -ffast-math -fdump-tree-vect-details -dumpbase dumpvect
PARAMS_LIBS = -g -lm -lrt -lfftw3f -DUSE_FFTW -DLIBCSDR_GPL -DUSE_IMA_ADPCM
PARAMS_SO = -fpic
PARAMS_MISC = -Wno-unused-result
#DEBUG_ON = 0 #debug is always on by now (anyway it could be compiled with `make DEBUG_ON=1`)
#PARAMS_DEBUG = $(if $(DEBUG_ON),-g,)
FFTW_PACKAGE = fftw-3.3.3
PREFIX ?= /usr
SOVERSION = 0.15
PARSEVECT ?= yes
.PHONY: clean-vect clean codequality checkdocs v
all: codequality csdr nmux
libcsdr.so: fft_fftw.c fft_rpi.c libcsdr_wrapper.c libcsdr.c libcsdr_gpl.c fastddc.c fastddc.h fft_fftw.h fft_rpi.h ima_adpcm.h libcsdr_gpl.h libcsdr.h predefined.h
.PHONY: clean-vect clean
all: csdr ddcd
libcsdr.so: fft_fftw.c fft_rpi.c libcsdr_wrapper.c libcsdr.c libcsdr_gpl.c fastddc.c *.h
@echo NOTE: you may have to manually edit Makefile to optimize for your CPU \(especially if you compile on ARM, please edit PARAMS_NEON\).
@echo Auto-detected optimization parameters: $(PARAMS_SIMD)
@echo
rm -f dumpvect*.vect
gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) $(LIBSOURCES) $(PARAMS_LIBS) $(PARAMS_MISC) -fpic -shared -Wl,-soname,libcsdr.so.$(SOVERSION) -o libcsdr.so.$(SOVERSION)
@ln -fs libcsdr.so.$(SOVERSION) libcsdr.so
ifeq ($(PARSEVECT),yes)
gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) $(LIBSOURCES) $(PARAMS_LIBS) $(PARAMS_MISC) -fpic -shared -o libcsdr.so
-./parsevect dumpvect*.vect
endif
csdr: csdr.c libcsdr.so
gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) csdr.c $(PARAMS_LIBS) -L. -lcsdr $(PARAMS_MISC) -o csdr
ddcd: ddcd.cpp libcsdr.so ddcd.h
g++ $(PARAMS_LOOPVECT) $(PARAMS_SIMD) ddcd.cpp $(PARAMS_LIBS) -L. -lcsdr -lpthread $(PARAMS_MISC) -o ddcd
nmux: nmux.cpp libcsdr.so nmux.h tsmpool.cpp tsmpool.h
g++ $(PARAMS_LOOPVECT) $(PARAMS_SIMD) nmux.cpp tsmpool.cpp $(PARAMS_LIBS) -L. -lcsdr -lpthread $(PARAMS_MISC) -o nmux
arm-cross: clean-vect
#note: this doesn't work since having added FFTW
arm-linux-gnueabihf-gcc -std=gnu99 -O3 -fshort-double -ffast-math -dumpbase dumpvect-arm -fdump-tree-vect-details -mfloat-abi=softfp -march=armv7-a -mtune=cortex-a9 -mfpu=neon -mvectorize-with-neon-quad -Wno-unused-result -Wformat=0 $(SOURCES) -lm -o ./csdr
clean-vect:
rm -f dumpvect*.vect
clean: clean-vect
rm -f libcsdr.so.$(SOVERSION) csdr ddcd nmux *.o *.so
rm -f libcsdr.so csdr ddcd
install: all
install -m 0755 libcsdr.so.$(SOVERSION) $(PREFIX)/lib
install -m 0755 csdr $(PREFIX)/bin
install -m 0755 csdr-fm $(PREFIX)/bin
install -m 0755 nmux $(PREFIX)/bin
#-install -m 0755 ddcd $(PREFIX)/bin
@ldconfig || echo please run ldconfig
install -m 0755 libcsdr.so /usr/lib
install -m 0755 csdr /usr/bin
install -m 0755 csdr-fm /usr/bin
install -m 0755 ddcd /usr/bin
ldconfig
uninstall:
rm $(PREFIX)/lib/libcsdr.so.$(SOVERSION) $(PREFIX)/bin/csdr $(PREFIX)/bin/csdr-fm
rm /usr/lib/libcsdr.so /usr/bin/csdr /usr/bin/csdr-fm
ldconfig
disasm:
objdump -S libcsdr.so.$(SOVERSION) > libcsdr.disasm
objdump -S libcsdr.so > libcsdr.disasm
emcc-clean:
-rm sdr.js/sdr.js
-rm sdr.js/sdrjs-compiled.js
@ -92,16 +89,7 @@ emcc-get-deps:
emmake make; \
emmake make install
emcc:
emcc -O3 -Isdr.js/$(FFTW_PACKAGE)/api -Lsdr.js/$(FFTW_PACKAGE)/emscripten-lib -o sdr.js/sdrjs-compiled.js fft_fftw.c libcsdr_wrapper.c -s TOTAL_MEMORY=67108864 -DLIBCSDR_GPL -DUSE_IMA_ADPCM -DUSE_FFTW -lfftw3f -s EXPORTED_FUNCTIONS="`python sdr.js/exported_functions.py`"
emcc -O3 -Isdr.js/$(FFTW_PACKAGE)/api -Lsdr.js/$(FFTW_PACKAGE)/emscripten-lib -o sdr.js/sdrjs-compiled.js fft_fftw.c libcsdr_wrapper.c -DLIBCSDR_GPL -DUSE_IMA_ADPCM -DUSE_FFTW -lfftw3f -s EXPORTED_FUNCTIONS="`python sdr.js/exported_functions.py`"
cat sdr.js/sdrjs-header.js sdr.js/sdrjs-compiled.js sdr.js/sdrjs-footer.js > sdr.js/sdr.js
emcc-beautify:
bash -c 'type js-beautify >/dev/null 2>&1; if [ $$? -eq 0 ]; then js-beautify sdr.js/sdr.js >sdr.js/sdr.js.beautiful; mv sdr.js/sdr.js.beautiful sdr.js/sdr.js; fi'
codequality:
@bash -c 'if [ `cat csdr.c | grep badsyntax | grep -v return | wc -l` -ne 1 ]; then echo "error at code quality check: badsyntax() used in csdr.c without return."; exit 1; else exit 0; fi'
checkdocs:
@cat csdr.c | grep strcmp | egrep 'argv\[1\]' | awk -F'"' '$$0=$$2' > /tmp/csdr-list-of-functions
@cat /tmp/csdr-list-of-functions | xargs -I{} bash -c 'if ! cat csdr.c | grep \"\ \ \ \ {} >/dev/null ; then echo "warning: \"{}\" is in csdr.c code, but not in usage string"; fi'
@cat /tmp/csdr-list-of-functions | xargs -I{} bash -c 'if ! cat README.md | grep {} >/dev/null ; then echo "warning: \"{}\" is in csdr.c code, but not in README.md"; fi'
@rm /tmp/csdr-list-of-functions
v:
vim csdr.c libcsdr.c

1305
README.md Executable file → Normal file

File diff suppressed because it is too large Load diff

4949
csdr.c Executable file → Normal file

File diff suppressed because it is too large Load diff

519
ddcd.cpp
View file

@ -1,5 +1,5 @@
/*
This software is part of libcsdr, a set of simple DSP routines for
This software is part of libcsdr, a set of simple DSP routines for
Software Defined Radio.
Copyright (c) 2014, Andras Retzler <randras@sdr.hu>
@ -31,28 +31,74 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "ddcd.h"
#define SOFTWARE_NAME "ddcd"
#define MSG_START SOFTWARE_NAME ": "
int host_port = 0;
char host_address[100] = "127.0.0.1";
int thread_cntr = 0;
//CLI parameters
int decimation = 0;
float transition_bw = 0.05;
int bufsize = 1024; //! currently unused
int bufcnt = 1024;
int bufsize = 1024;
int bufsizeall;
int pipe_max_size;
int in_client = 0;
char ddc_method_str[100] = "td";
ddc_method_t ddc_method;
pid_t main_dsp_proc;
int input_fd = STDIN_FILENO; //can be stdin, or the stdout of main_subprocess
pid_t main_subprocess_pid = 0;
pid_t main_subprocess_pgrp = 0;
pid_t client_subprocess_pid = 0;
pid_t client_subprocess_pgrp = 0;
char* buf;
int set_nonblocking(int fd)
{
int flagtmp;
if((flagtmp = fcntl(fd, F_GETFL))!=-1)
if((flagtmp = fcntl(fd, F_SETFL, flagtmp|O_NONBLOCK))!=-1)
return 0;
return 1;
}
int proc_exists(pid_t pid)
{
if(pid==0 || pid==1) return 1;
return kill(pid, 0) != -1;
}
void sig_handler(int signo)
{
fprintf(stderr, MSG_START "signal %d caught, exiting ddcd...\n", signo);
{
int tmpstat;
if(signo==SIGPIPE)
{
fprintf(stderr,MSG_START "SIGPIPE received.\n");
return;
}
if(signo==SIGCHLD)
if( main_subprocess_pid && signo==SIGCHLD && (waitpid(main_subprocess_pid, &tmpstat, WNOHANG), 1) && !proc_exists(main_subprocess_pid) )
{
fprintf(stderr,MSG_START "main_subprocess_pid exited! Exiting...\n");
}
else return;
//if(pgrp!=1 && pgrp!=0) //I just want to make sure that we cannot kill init or sched
// killpg(pgrp, signo);
if( !in_client && main_subprocess_pid ) killpg2(main_subprocess_pgrp);
if( in_client && client_subprocess_pid ) killpg2(client_subprocess_pgrp);
fprintf(stderr, MSG_START "signal %d caught in %s, exiting ddcd...\n", signo, (in_client)?"client":"main");
fflush(stderr);
exit(0);
}
client_t* this_client;
int main(int argc, char* argv[])
{
int c;
fd_set select_fds;
for(;;)
{
int option_index = 0;
@ -61,13 +107,12 @@ int main(int argc, char* argv[])
{"address", required_argument, 0, 'a' },
{"decimation", required_argument, 0, 'd' },
{"bufsize", required_argument, 0, 'b' },
{"bufcnt", required_argument, 0, 'n' },
{"method", required_argument, 0, 'm' },
{"transition", required_argument, 0, 't' }
};
c = getopt_long(argc, argv, "p:a:d:b:n:m:t:", long_options, &option_index);
c = getopt_long(argc, argv, "p:a:d:b:m:t:", long_options, &option_index);
if(c==-1) break;
switch (c)
switch (c)
{
case 'a':
host_address[100-1]=0;
@ -82,9 +127,6 @@ int main(int argc, char* argv[])
case 'b':
bufsize=atoi(optarg);
break;
case 'n':
bufcnt=atoi(optarg);
break;
case 'm':
ddc_method_str[100-1]=0;
strncpy(ddc_method_str,optarg,100-1);
@ -99,23 +141,22 @@ int main(int argc, char* argv[])
print_exit(MSG_START "error in getopt_long()\n");
}
}
if(!decimation) print_exit(MSG_START "missing required command line argument, --decimation.\n");
if(!host_port) print_exit(MSG_START "missing required command line argument, --port.\n");
if(decimation<0) print_exit(MSG_START "invalid value for --decimation (should be >0).\n");
if(decimation==1) fprintf(stderr, MSG_START "decimation = 1, just copying raw samples.\n");
if(transition_bw<0||transition_bw>0.5) print_exit(MSG_START "invalid value for --transition (should be between 0 and 0.5).\n");
if(bufsize<0) print_exit(MSG_START "invalid value for --bufsize (should be >0)\n");
if(bufcnt<0) print_exit(MSG_START "invalid value for --bufcnt (should be >0)\n");
if(decimation==1); //don't do anything then //!will have to take care about this later
else if(!strcmp(ddc_method_str,"td"))
if(decimation==1); //don't do anything then
else if(!strcmp(ddc_method_str,"td"))
{
ddc_method = M_TD;
ddc_method = M_TD;
fprintf(stderr, MSG_START "method is M_TD (default).\n");
}
else if (!strcmp(ddc_method_str,"fastddc"))
else if (!strcmp(ddc_method_str,"fastddc"))
{
ddc_method = M_FASTDDC;
ddc_method = M_FASTDDC;
fprintf(stderr, MSG_START "method is M_FASTDDC.\n");
}
else print_exit(MSG_START "invalid parameter given to --method.\n");
@ -129,6 +170,9 @@ int main(int argc, char* argv[])
sigaction(SIGQUIT, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGHUP, &sa, NULL);
sigaction(SIGCHLD, &sa, NULL);
sigaction(SIGPIPE, &sa, NULL);
prctl(PR_SET_PDEATHSIG, SIGHUP); //get a signal when parent exits
struct sockaddr_in addr_host;
int listen_socket;
@ -140,12 +184,12 @@ int main(int argc, char* argv[])
if( setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&sockopt, sizeof(sockopt)) == -1 )
error_exit(MSG_START "cannot set SO_REUSEADDR"); //the best description on SO_REUSEADDR ever: http://stackoverflow.com/a/14388707/3182453
memset(&addr_host,'0',sizeof(addr_host));
addr_host.sin_family = AF_INET;
addr_host.sin_port = htons(host_port);
memset(&addr_host,'0',sizeof(addr_host));
addr_host.sin_family=AF_INET;
addr_host.sin_port=htons(host_port);
addr_host.sin_addr.s_addr = INADDR_ANY;
if( (addr_host.sin_addr.s_addr=inet_addr(host_address)) == INADDR_NONE )
if( (addr_host.sin_addr.s_addr=inet_addr(host_address)) == INADDR_NONE )
error_exit(MSG_START "invalid host address");
if( bind(listen_socket, (struct sockaddr*) &addr_host, sizeof(addr_host)) < 0 )
@ -160,25 +204,68 @@ int main(int argc, char* argv[])
socklen_t addr_cli_len = sizeof(addr_cli);
int new_socket;
int highfd = 0;
bufsizeall = bufsize*sizeof(char);
buf = (char*)malloc(bufsizeall);
FILE* tempfile = fopen("/proc/sys/fs/pipe-max-size","r");
if(!tempfile)
{
perror(MSG_START "cannot read /proc/sys/fs/pipe-max-size");
}
else
{
char pipe_max_size_str[100];
int tfread = fread(pipe_max_size_str, 1, 100, tempfile);
pipe_max_size_str[tfread]='\0';
pipe_max_size = atoi(pipe_max_size_str);
//fprintf(stderr, MSG_START "note: pipe_max_size = %d\n", pipe_max_size);
//if(pipe_max_size>4096 && fcntl(STDIN_FILENO, F_SETPIPE_SZ, pipe_max_size)==-1)
// perror("failed to fcntl(STDIN_FILENO, F_SETPIPE_SZ, ...)");
}
//We'll see if it is a good idea:
//setpgrp();
//pgrp = getpgrp();
//It is not, because we can't catch Ctrl+C (SIGINT), as it is sent to a process group...
//Start DSP subprocess from the main process if required
char main_subprocess_cmd_buf[500];
int pipe_m2s_ctl[2]; //main to subprocess :: control channel
int pipe_s2m[2]; //subprocess to main
if(pipe(pipe_m2s_ctl)) error_exit(MSG_START "couldn't create pipe_m2s_ctl");
if(pipe(pipe_s2m)) error_exit(MSG_START "couldn't create pipe_s2m");
if(decimation!=1)
{
switch(ddc_method)
{
case M_TD:
break;
case M_FASTDDC:
sprintf(main_subprocess_cmd_buf, subprocess_args_fastddc_1, decimation, transition_bw);
fprintf(stderr, MSG_START "starting main_subprocess_cmd: %s\n", main_subprocess_cmd_buf);
if(!(main_subprocess_pid = run_subprocess( main_subprocess_cmd_buf, 0, pipe_s2m, &main_subprocess_pgrp )))
print_exit(MSG_START "couldn't start main_subprocess_cmd!\n");
close(STDIN_FILENO); // redirect stdin to the stdin of the subprocess
break;
}
}
int highfd = 0;
FD_ZERO(&select_fds);
FD_SET(listen_socket, &select_fds);
maxfd(&highfd, listen_socket);
if(main_subprocess_pid) input_fd = pipe_s2m[0]; //else STDIN_FILENO
FD_SET(input_fd, &select_fds);
maxfd(&highfd, input_fd);
//Set stdin and listen_socket to non-blocking
if(set_nonblocking(input_fd) || set_nonblocking(listen_socket))
//Set stdin and listen_socket to non-blocking
if(set_nonblocking(input_fd) || set_nonblocking(listen_socket)) //don't do it before subprocess fork!
error_exit(MSG_START "cannot set_nonblocking()");
//Create tsmpool
tsmpool* pool = new tsmpool(bufsize, bufcnt);
if(!pool->ok) print_exit(MSG_START "tsmpool failed to initialize\n");
unsigned char* current_write_buffer = pool->get_write_buffer();
int index_in_current_write_buffer = 0;
for(;;)
{
//Let's wait until there is any new data to read, or any new connection!
@ -186,141 +273,301 @@ int main(int argc, char* argv[])
//Is there a new client connection?
if( (new_socket = accept(listen_socket, (struct sockaddr*)&addr_cli, &addr_cli_len)) != -1)
{
clients_close_all_finished();
if(pthread_create(&new_client->thread, NULL, client_thread , (void*)&new_client)<0)
{
this_client = new client_t;
this_client->error = 0;
memcpy(&this_client->addr, &addr_cli, sizeof(this_client->addr));
this_client->socket = new_socket;
if(pipe(this_client->pipefd) == -1)
{
perror(MSG_START "cannot open new pipe() for the client");
continue;
}
if(fcntl(this_client->pipefd[1], F_SETPIPE_SZ, pipe_max_size) == -1)
perror("failed to F_SETPIPE_SZ for the client pipe");
if(this_client->pid = fork())
{
//We're the parent
client_t* new_client = new client_t;
new_client->error = 0;
memcpy(&new_client->addr, &addr_cli, sizeof(new_client->addr));
new_client->socket = new_socket;
new_client->status = CS_CREATED;
clients.push_back(new_client);
fprintf(stderr, MSG_START "pthread_create() done, clients now: %d\n", clients.size());
set_nonblocking(this_client->pipefd[1]);
clients.push_back(this_client);
fprintf(stderr, MSG_START "client pid: %d\n", this_client->pid);
}
else
{
//We're the client
client();
return 1;
}
else fprintf(stderr, MSG_START "pthread_create() failed.\n");
}
if(index_in_current_write_buffer >= bufsize)
int retval = read(input_fd, buf, bufsizeall);
if(retval==0)
{
current_write_buffer = pool->get_write_buffer();
index_in_current_write_buffer = 0;
//end of input stream, close clients and exit
}
int retval = read(input_fd, current_write_buffer + index_in_current_write_buffer, bufsize - index_in_current_write_buffer);
if(retval>0)
else if(retval != -1)
{
index_in_current_write_buffer += retval;
for (int i=0; i<clients.size(); i++)
{
if(write(clients[i]->pipefd[1], buf, retval)==-1)
{
if(!clients[i]->error)
{
print_client(clients[i], "lost buffer, failed to write pipe.");
clients[i]->error=1;
}
//fprintf(stderr, MSG_START "errno is %d\n", errno); //usually 11
//int wpstatus;
//int wpresult = waitpid(clients[i]->pid, &wpstatus, WNOHANG);
//fprintf(stderr, MSG_START "pid is %d\n",clients[i]->pid);
//perror("somethings wrong");
//if(wpresult == -1) print_client(clients[i], "error while waitpid()!");
//else if(wpresult == 0)
waitpid(clients[i]->pid, NULL, WNOHANG);
if(!proc_exists(clients[i]->pid))
{
//Client exited!
print_client(clients[i], "closing client from main process.");
close(clients[i]->pipefd[1]);
close(clients[i]->socket);
delete clients[i];
clients.erase(clients.begin()+i);
fprintf(stderr, MSG_START "done closing client from main process.\n");
}
}
else { if(clients[i]->error) print_client(clients[i], "pipe okay again."); clients[i]->error=0; }
}
}
else if(retval==0)
//TODO: at the end, server closes pipefd[1] for client
}
return 0;
}
pid_t run_subprocess(char* cmd, int* pipe_in, int* pipe_out, pid_t* pgrp)
{
/*char sem_name[101];
snprintf(sem_name,100,"ddcd_sem_%d",getpid());
sem_t mysem;
if(sem_init(&mysem, 1, 1)==-1) error_exit("failed to sem_init() in run_subprocess()");
fprintf(stderr, "sem_waiting\n");
if(sem_wait(&mysem)==-1) error_exit("the first sem_wait() failed in run_subprocess()");
fprintf(stderr, "sem_waited\n");
*/
int syncpipe[2];
if(pipe(syncpipe)==-1) error_exit("failed to create pipe()");
pid_t pid = fork();
if(pid < 0) return 0; //fork failed
if(pid == 0)
{
setpgrp();
write(syncpipe[1], " ", 1);
//if(sem_post(&mysem)==-1) error_exit("failed to sem_post() in run_subprocess()");
//We're the subprocess
//fprintf(stderr, "run_subprocess :: execl\n");
//if(fcntl(pipe_in[1], F_SETPIPE_SZ, pipe_max_size) == -1) perror("Failed to F_SETPIPE_SZ in run_subprocess()");
if(pipe_in)
{
//!end of input stream, close clients and exit
print_exit(MSG_START "end of input, exiting.\n")
close(pipe_in[1]);
dup2(pipe_in[0], STDIN_FILENO);
}
if(pipe_out)
{
close(pipe_out[0]);
dup2(pipe_out[1], STDOUT_FILENO);
}
execl("/bin/bash","bash","-c",cmd, (char*)0);
error_exit(MSG_START "run_subprocess failed to execute command");
}
else
{
//if(sem_wait(&mysem)==-1) error_exit("the second sem_wait() failed in run_subprocess()");
int synctemp;
read(syncpipe[0], &synctemp, 1);
*pgrp = getpgid(pid);
fprintf(stderr, MSG_START "run_subprocess pgid returned = %d\n", *pgrp);
return pid;
}
}
#if 0
for (int i=0; i<clients.size(); i++)
void print_client(client_t* client, const char* what)
{
if(write(clients[i]->pipefd[1], buf, retval)==-1)
{
fprintf(stderr,MSG_START "(client %s:%d) %s\n", inet_ntoa(client->addr.sin_addr), client->addr.sin_port, what);
}
if(!clients[i]->error)
#define CTL_BUFSIZE 1024
int read_socket_ctl(int fd, char* output, int max_size)
{
//fprintf(stderr, "doing read_socket_ctl %d\n", fd);
//if(!fd) return 0;
static char buffer[CTL_BUFSIZE];
static int buffer_index=0;
if(buffer_index==CTL_BUFSIZE) buffer_index=0;
int bytes_read=recv(fd,buffer+buffer_index,(CTL_BUFSIZE-buffer_index)*sizeof(char), MSG_DONTWAIT);
if(bytes_read<=0) return 0;
//fprintf(stderr, "recv %d\n", bytes_read);
int prev_newline_at=0;
int last_newline_at=0;
for(int i=0;i<buffer_index+bytes_read;i++)
{
if(buffer[i]=='\n')
{
print_client(clients[i], "lost buffer, failed to write pipe.");
clients[i]->error=1;
}
//fprintf(stderr, MSG_START "errno is %d\n", errno); //usually 11
//int wpstatus;
//int wpresult = waitpid(clients[i]->pid, &wpstatus, WNOHANG);
//fprintf(stderr, MSG_START "pid is %d\n",clients[i]->pid);
//perror("somethings wrong");
//if(wpresult == -1) print_client(clients[i], "error while waitpid()!");
//else if(wpresult == 0)
waitpid(clients[i]->pid, NULL, WNOHANG);
if(!proc_exists(clients[i]->pid))
{
//Client exited!
print_client(clients[i], "closing client from main process.");
close(clients[i]->pipefd[1]);
close(clients[i]->socket);
delete clients[i];
clients.erase(clients.begin()+i);
fprintf(stderr, MSG_START "done closing client from main process.\n");
prev_newline_at=last_newline_at;
last_newline_at=i+1;
}
}
else { if(clients[i]->error) print_client(clients[i], "pipe okay again."); clients[i]->error=0; }
}
}
//TODO: at the end, server closes pipefd[1] for client
#endif
void clients_close_all_finished()
{
for(int i=0;i<clients.size();i++)
if(last_newline_at)
{
if(clients[i]->status == CS_THREAD_FINISHED) clients.erase(i);
int oi=0;
for(int i=prev_newline_at;buffer[i]!='\n'&&oi<max_size;i++) output[oi++]=buffer[i]; //copy to output buffer
output[oi++]='\0';
memmove(buffer,buffer+last_newline_at,buffer_index+bytes_read-last_newline_at);
buffer_index=bytes_read-last_newline_at;
return 1;
}
else
{
buffer_index+=bytes_read;
return 0;
}
}
void client_parser_push(char c)
{ //!TODO
command_t cmd;
char* commands_cstr = commands.c_str();
int newline_index = -1;
for(int i=0;commands_cstr[i];i++) if(commands_cstr[i]=='\n') newline_index = i;
if(newline_index == -1)
char param_name[101];
char param_value[101];
for(int i=0;i<100;commands_csdr
int ctl_get_arg(char* input, const char* cmd, const char* format, ...)
{
int retval=0;
int cmdlen=strlen(cmd);
if(input[cmdlen]=='=')
{
//fprintf(stderr, "cga found=\n");
if(input[cmdlen]=0, !strcmp(input,cmd))
{
//fprintf(stderr, "cga foundokay\n");
va_list vl;
va_start(vl,format);
retval=vsscanf(input+cmdlen+1,format,vl);
va_end(vl);
}
input[cmdlen]='=';
}
//fprintf(stderr, "cga retval %d\n", retval);
return retval;
}
void* client_thread (void* param) //!TODO
void client()
{
client_t* me_the_client = (client_t*)param;
me_the_client->status = CS_THREAD_RUNNING;
char ctl_data_buffer;
int retval;
tsmpool* p1_temp;
tsmpool* p2_temp;
const int num_client_buffers = 20;
if(ddc_method == M_TD)
in_client=1;
print_client(this_client, "client process forked.");
char client_subprocess_cmd_buf[500];
int input_fd = this_client->pipefd[0];
int pipe_ctl[2], pipe_stdout[2];
prctl(PR_SET_PDEATHSIG, SIGHUP); //get a signal when parent exits
if(decimation!=1)
{
p1_temp = new tsmpool(bufsize, )
if(pipe(pipe_ctl)==-1) error_exit(MSG_START "cannot open new pipe() for the client subprocess");
if(pipe(pipe_stdout)==-1) error_exit(MSG_START "cannot open new pipe() for the client subprocess");
switch(ddc_method)
{
case M_TD:
sprintf(client_subprocess_cmd_buf, subprocess_cmd_td, pipe_ctl[0], decimation, transition_bw);
break;
case M_FASTDDC:
sprintf(client_subprocess_cmd_buf, subprocess_args_fastddc_2, decimation, pipe_ctl[0], transition_bw);
break;
}
if(!(client_subprocess_pid = run_subprocess( client_subprocess_cmd_buf, this_client->pipefd, pipe_stdout, &client_subprocess_pgrp)))
print_exit(MSG_START "couldn't start client_subprocess_cmd!\n");
fprintf(stderr, MSG_START "starting client_subprocess_cmd: %s\n", client_subprocess_cmd_buf);
input_fd = pipe_stdout[0]; //we don't have to set it nonblocking
fprintf(stderr, MSG_START "pipe_stdout[0] = %d\n", pipe_stdout[0]);
write(pipe_ctl[1], "0.1\n", 4);
}
char recv_cmd[CTL_BUFSIZE];
char temps[CTL_BUFSIZE*2];
int tempi;
float tempf;
fd_set client_fds;
int highfd = 0;
FD_ZERO(&client_fds);
FD_SET(this_client->socket, &client_fds);
maxfd(&highfd, this_client->socket);
FD_SET(this_client->pipefd[0], &client_fds);
maxfd(&highfd, this_client->pipefd[0]);
set_nonblocking(this_client->socket);
//set_nonblocking(this_client->pipefd[0]);
if(client_subprocess_pid)
{
FD_SET(pipe_stdout[0], &client_fds);
maxfd(&highfd, pipe_stdout[0]);
set_nonblocking(pipe_stdout[0]);
}
for(;;)
{
do
//Let's wait until there is anything on the fds...
select(highfd, &client_fds, NULL, NULL, NULL);
while(read_socket_ctl(this_client->socket, recv_cmd, CTL_BUFSIZE))
{
retval = recv(me_the_client->socket, &ctl_data_buffer, 1, 0);
if(client_parser_push(ctl_data_buffer)) break;
} while (retval);
//read control data from socket
//process control data
//run shift
//run decimation
//have an exit condition (??)
if(ddc_method == M_TD)
{
sprintf(temps, "read_socket_ctl: %s", recv_cmd);
print_client(this_client, temps);
if(ctl_get_arg(recv_cmd, "bypass", "%d", &tempi))
{
if(tempi==1 && client_subprocess_pid)
{
//print_client(this_client, "suspending client_subprocess_pgrp...\n");
//fprintf(stderr, "client_subprocess_pgrp = %d\n", client_subprocess_pgrp);
//killpg(client_subprocess_pgrp, SIGTSTP);
//while(proc_exists(client_subprocess_pid)) usleep(10000);
//print_client(this_client, "done killing client_subprocess_pid.\n");
input_fd=this_client->pipefd[0]; //by doing this, we don't read from pipe_stdout[0] anymore, so that csdr stops doing anything, and also doesn't read anymore from the input: we get the whole I/Q stream!
}
if(tempi==0 && client_subprocess_pid)
{
input_fd=pipe_stdout[0];
}
}
if(ctl_get_arg(recv_cmd, "shift", "%g", &tempf))
{
tempi=sprintf(temps, "%g\n", tempf);
write(pipe_ctl[1], temps, tempi);
fsync(pipe_ctl[1]);
}
}
}
me_the_client->status = CS_THREAD_FINISHED;
pthread_exit(NULL);
return NULL;
int nread = read(input_fd,buf,bufsizeall);
if(nread<=0) continue;
for(;;) if(send(this_client->socket,buf,nread,0)==-1)
{
if(errno==11) continue;
print_client(this_client, "client process is exiting.\n");
if(client_subprocess_pid) killpg2(client_subprocess_pgrp);
exit(0);
} else break;
}
}
void killpg2(pid_t pgrp)
{
//fprintf(stderr, MSG_START "killpg2: %d\n", pgrp);
if(pgrp!=1 && pgrp!=0) killpg(pgrp, SIGTERM);
}
void error_exit(const char* why)
{
perror(why); //do we need a \n at the end of (why)?
exit(1);
perror(why);
exit(1);
}
void print_exit(const char* why)
@ -331,5 +578,5 @@ void print_exit(const char* why)
void maxfd(int* maxfd, int fd)
{
if(fd>=*maxfd) *maxfd=fd+1;
if(fd>=*maxfd) *maxfd=fd+1;
}

87
ddcd.h
View file

@ -1,57 +1,62 @@
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <signal.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <getopt.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <iostream>
#include <vector>
#include <limits.h>
#define SOFTWARE_NAME "ddcd"
#define MSG_START SOFTWARE_NAME ": "
typedef enum ddc_method_e
{
M_TD,
M_FASTDDC
} ddc_method_t;
typedef enum client_status_e
{
CS_CREATED,
CS_THREAD_RUNNING,
CS_THREAD_FINISHED
} client_status_t;
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/wait.h>
#include <sys/prctl.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <semaphore.h>
typedef struct client_s
{
struct sockaddr_in addr;
int socket;
int error; //set to non-zero on error (data transfer failed)
pthread_t thread;
client_status_t status;
pid_t pid;
int pipefd[2];
int error;
pid_t dsp_proc;
} client_t;
typedef enum command_type_e
{
CT_SHIFT,
CT_BYPASS
} command_type_t;
typedef struct command_s
{
command_type_t type;
float float_param;
} command_t;
void print_exit(const char* why);
void client();
void error_exit(const char* why);
void print_exit(const char* why);
void print_client(client_t* client, const char* what);
int proc_exists(pid_t pid);
pid_t run_subprocess(char* cmd, int* pipe_in, int* pipe_out, pid_t* pgrp);
void maxfd(int* maxfd, int fd);
void sig_handler(int signo);
void killpg2(pid_t pgrp);
int ctl_get_arg(char* input, const char* cmd, const char* format, ...);
typedef enum ddc_method_e
{
M_TD,
M_FASTDDC
} ddc_method_t;
const char subprocess_cmd_td[] = "csdr "
#ifdef NEON_OPTS
"shift_addfast_cc"
#else
"shift_unroll_cc"
#endif
" --fd %d | csdr fir_decimate_cc %d %g";
//const char subprocess_args_fastddc_1[] = "csdr fastddc_fwd_cc %d %g";
const char subprocess_args_fastddc_1[] = "csdr through %d %g";
//const char subprocess_args_fastddc_2[] = "csdr fastddc_inv_cc %d --pipe %d %g";
const char subprocess_args_fastddc_2[] = "csdr convert_u8_f %d %d %g";

View file

@ -1,560 +0,0 @@
/*
This software is part of libcsdr, a set of simple DSP routines for
Software Defined Radio.
Copyright (c) 2014, Andras Retzler <randras@sdr.hu>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ANDRAS RETZLER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ddcd.h"
#define SOFTWARE_NAME "ddcd"
#define MSG_START SOFTWARE_NAME ": "
int host_port = 0;
char host_address[100] = "127.0.0.1";
int decimation = 0;
float transition_bw = 0.05;
int bufsize = 1024;
int bufsizeall;
int pipe_max_size;
int in_client = 0;
char ddc_method_str[100] = "td";
ddc_method_t ddc_method;
pid_t main_dsp_proc;
int input_fd = STDIN_FILENO; //can be stdin, or the stdout of main_subprocess
pid_t main_subprocess_pid = 0;
pid_t main_subprocess_pgrp = 0;
pid_t client_subprocess_pid = 0;
pid_t client_subprocess_pgrp = 0;
char* buf;
int set_nonblocking(int fd)
{
int flagtmp;
if((flagtmp = fcntl(fd, F_GETFL))!=-1)
if((flagtmp = fcntl(fd, F_SETFL, flagtmp|O_NONBLOCK))!=-1)
return 0;
return 1;
}
int proc_exists(pid_t pid)
{
if(pid==0 || pid==1) return 1;
return kill(pid, 0) != -1;
}
void sig_handler(int signo)
{
int tmpstat;
if(signo==SIGPIPE)
{
fprintf(stderr,MSG_START "SIGPIPE received.\n");
return;
}
if(signo==SIGCHLD)
if( main_subprocess_pid && signo==SIGCHLD && (waitpid(main_subprocess_pid, &tmpstat, WNOHANG), 1) && !proc_exists(main_subprocess_pid) )
{
fprintf(stderr,MSG_START "main_subprocess_pid exited! Exiting...\n");
}
else return;
//if(pgrp!=1 && pgrp!=0) //I just want to make sure that we cannot kill init or sched
// killpg(pgrp, signo);
if( !in_client && main_subprocess_pid ) killpg2(main_subprocess_pgrp);
if( in_client && client_subprocess_pid ) killpg2(client_subprocess_pgrp);
fprintf(stderr, MSG_START "signal %d caught in %s, exiting ddcd...\n", signo, (in_client)?"client":"main");
fflush(stderr);
exit(0);
}
client_t* this_client;
int main(int argc, char* argv[])
{
int c;
fd_set select_fds;
for(;;)
{
int option_index = 0;
static struct option long_options[] = {
{"port", required_argument, 0, 'p' },
{"address", required_argument, 0, 'a' },
{"decimation", required_argument, 0, 'd' },
{"bufsize", required_argument, 0, 'b' },
{"method", required_argument, 0, 'm' },
{"transition", required_argument, 0, 't' }
};
c = getopt_long(argc, argv, "p:a:d:b:m:t:", long_options, &option_index);
if(c==-1) break;
switch (c)
{
case 'a':
host_address[100-1]=0;
strncpy(host_address,optarg,100-1);
break;
case 'p':
host_port=atoi(optarg);
break;
case 'd':
decimation=atoi(optarg);
break;
case 'b':
bufsize=atoi(optarg);
break;
case 'm':
ddc_method_str[100-1]=0;
strncpy(ddc_method_str,optarg,100-1);
break;
case 't':
sscanf(optarg,"%g",&transition_bw);
break;
case 0:
case '?':
case ':':
default:;
print_exit(MSG_START "error in getopt_long()\n");
}
}
if(!decimation) print_exit(MSG_START "missing required command line argument, --decimation.\n");
if(!host_port) print_exit(MSG_START "missing required command line argument, --port.\n");
if(decimation<0) print_exit(MSG_START "invalid value for --decimation (should be >0).\n");
if(decimation==1) fprintf(stderr, MSG_START "decimation = 1, just copying raw samples.\n");
if(transition_bw<0||transition_bw>0.5) print_exit(MSG_START "invalid value for --transition (should be between 0 and 0.5).\n");
if(decimation==1); //don't do anything then
else if(!strcmp(ddc_method_str,"td"))
{
ddc_method = M_TD;
fprintf(stderr, MSG_START "method is M_TD (default).\n");
}
else if (!strcmp(ddc_method_str,"fastddc"))
{
ddc_method = M_FASTDDC;
fprintf(stderr, MSG_START "method is M_FASTDDC.\n");
}
else print_exit(MSG_START "invalid parameter given to --method.\n");
//set signals
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = sig_handler;
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGKILL, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGHUP, &sa, NULL);
sigaction(SIGCHLD, &sa, NULL);
sigaction(SIGPIPE, &sa, NULL);
prctl(PR_SET_PDEATHSIG, SIGHUP); //get a signal when parent exits
struct sockaddr_in addr_host;
int listen_socket;
std::vector<client_t*> clients;
clients.reserve(100);
listen_socket=socket(AF_INET,SOCK_STREAM,0);
int sockopt = 1;
if( setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&sockopt, sizeof(sockopt)) == -1 )
error_exit(MSG_START "cannot set SO_REUSEADDR"); //the best description on SO_REUSEADDR ever: http://stackoverflow.com/a/14388707/3182453
memset(&addr_host,'0',sizeof(addr_host));
addr_host.sin_family=AF_INET;
addr_host.sin_port=htons(host_port);
addr_host.sin_addr.s_addr = INADDR_ANY;
if( (addr_host.sin_addr.s_addr=inet_addr(host_address)) == INADDR_NONE )
error_exit(MSG_START "invalid host address");
if( bind(listen_socket, (struct sockaddr*) &addr_host, sizeof(addr_host)) < 0 )
error_exit(MSG_START "cannot bind() address to the socket");
if( listen(listen_socket, 10) == -1 )
error_exit(MSG_START "cannot listen() on socket");
fprintf(stderr,MSG_START "listening on %s:%d\n", inet_ntoa(addr_host.sin_addr), host_port);
struct sockaddr_in addr_cli;
socklen_t addr_cli_len = sizeof(addr_cli);
int new_socket;
bufsizeall = bufsize*sizeof(char);
buf = (char*)malloc(bufsizeall);
FILE* tempfile = fopen("/proc/sys/fs/pipe-max-size","r");
if(!tempfile)
{
perror(MSG_START "cannot read /proc/sys/fs/pipe-max-size");
}
else
{
char pipe_max_size_str[100];
int tfread = fread(pipe_max_size_str, 1, 100, tempfile);
pipe_max_size_str[tfread]='\0';
pipe_max_size = atoi(pipe_max_size_str);
//fprintf(stderr, MSG_START "note: pipe_max_size = %d\n", pipe_max_size);
//if(pipe_max_size>4096 && fcntl(STDIN_FILENO, F_SETPIPE_SZ, pipe_max_size)==-1)
// perror("failed to fcntl(STDIN_FILENO, F_SETPIPE_SZ, ...)");
}
//We'll see if it is a good idea:
//setpgrp();
//pgrp = getpgrp();
//It is not, because we can't catch Ctrl+C (SIGINT), as it is sent to a process group...
//Start DSP subprocess from the main process if required
char main_subprocess_cmd_buf[500];
int pipe_m2s_ctl[2]; //main to subprocess :: control channel
int pipe_s2m[2]; //subprocess to main
if(pipe(pipe_m2s_ctl)) error_exit(MSG_START "couldn't create pipe_m2s_ctl");
if(pipe(pipe_s2m)) error_exit(MSG_START "couldn't create pipe_s2m");
if(decimation!=1)
{
switch(ddc_method)
{
case M_TD:
break;
case M_FASTDDC:
sprintf(main_subprocess_cmd_buf, subprocess_args_fastddc_1, decimation, transition_bw);
fprintf(stderr, MSG_START "starting main_subprocess_cmd: %s\n", main_subprocess_cmd_buf);
if(!(main_subprocess_pid = run_subprocess( main_subprocess_cmd_buf, 0, pipe_s2m, &main_subprocess_pgrp )))
print_exit(MSG_START "couldn't start main_subprocess_cmd!\n");
close(STDIN_FILENO); // redirect stdin to the stdin of the subprocess
break;
}
}
int highfd = 0;
FD_ZERO(&select_fds);
FD_SET(listen_socket, &select_fds);
maxfd(&highfd, listen_socket);
if(main_subprocess_pid) input_fd = pipe_s2m[0]; //else STDIN_FILENO
FD_SET(input_fd, &select_fds);
maxfd(&highfd, input_fd);
//Set stdin and listen_socket to non-blocking
if(set_nonblocking(input_fd) || set_nonblocking(listen_socket)) //don't do it before subprocess fork!
error_exit(MSG_START "cannot set_nonblocking()");
for(;;)
{
//Let's wait until there is any new data to read, or any new connection!
select(highfd, &select_fds, NULL, NULL, NULL);
//Is there a new client connection?
if( (new_socket = accept(listen_socket, (struct sockaddr*)&addr_cli, &addr_cli_len)) != -1)
{
this_client = new client_t;
this_client->error = 0;
memcpy(&this_client->addr, &addr_cli, sizeof(this_client->addr));
this_client->socket = new_socket;
if(pipe(this_client->pipefd) == -1)
{
perror(MSG_START "cannot open new pipe() for the client");
continue;
}
if(fcntl(this_client->pipefd[1], F_SETPIPE_SZ, pipe_max_size) == -1)
perror("failed to F_SETPIPE_SZ for the client pipe");
if(this_client->pid = fork())
{
//We're the parent
set_nonblocking(this_client->pipefd[1]);
clients.push_back(this_client);
fprintf(stderr, MSG_START "client pid: %d\n", this_client->pid);
}
else
{
//We're the client
client();
return 1;
}
}
int retval = read(input_fd, buf, bufsizeall);
if(retval==0)
{
//end of input stream, close clients and exit
}
else if(retval != -1)
{
for (int i=0; i<clients.size(); i++)
{
if(write(clients[i]->pipefd[1], buf, retval)==-1)
{
if(!clients[i]->error)
{
print_client(clients[i], "lost buffer, failed to write pipe.");
clients[i]->error=1;
}
//fprintf(stderr, MSG_START "errno is %d\n", errno); //usually 11
//int wpstatus;
//int wpresult = waitpid(clients[i]->pid, &wpstatus, WNOHANG);
//fprintf(stderr, MSG_START "pid is %d\n",clients[i]->pid);
//perror("somethings wrong");
//if(wpresult == -1) print_client(clients[i], "error while waitpid()!");
//else if(wpresult == 0)
waitpid(clients[i]->pid, NULL, WNOHANG);
if(!proc_exists(clients[i]->pid))
{
//Client exited!
print_client(clients[i], "closing client from main process.");
close(clients[i]->pipefd[1]);
close(clients[i]->socket);
delete clients[i];
clients.erase(clients.begin()+i);
fprintf(stderr, MSG_START "done closing client from main process.\n");
}
}
else { if(clients[i]->error) print_client(clients[i], "pipe okay again."); clients[i]->error=0; }
}
}
//TODO: at the end, server closes pipefd[1] for client
}
return 0;
}
pid_t run_subprocess(char* cmd, int* pipe_in, int* pipe_out, pid_t* pgrp)
{
/*char sem_name[101];
snprintf(sem_name,100,"ddcd_sem_%d",getpid());
sem_t mysem;
if(sem_init(&mysem, 1, 1)==-1) error_exit("failed to sem_init() in run_subprocess()");
fprintf(stderr, "sem_waiting\n");
if(sem_wait(&mysem)==-1) error_exit("the first sem_wait() failed in run_subprocess()");
fprintf(stderr, "sem_waited\n");
*/
int syncpipe[2];
if(pipe(syncpipe)==-1) error_exit("failed to create pipe()");
pid_t pid = fork();
if(pid < 0) return 0; //fork failed
if(pid == 0)
{
setpgrp();
write(syncpipe[1], " ", 1);
//if(sem_post(&mysem)==-1) error_exit("failed to sem_post() in run_subprocess()");
//We're the subprocess
//fprintf(stderr, "run_subprocess :: execl\n");
//if(fcntl(pipe_in[1], F_SETPIPE_SZ, pipe_max_size) == -1) perror("Failed to F_SETPIPE_SZ in run_subprocess()");
if(pipe_in)
{
close(pipe_in[1]);
dup2(pipe_in[0], STDIN_FILENO);
}
if(pipe_out)
{
close(pipe_out[0]);
dup2(pipe_out[1], STDOUT_FILENO);
}
execl("/bin/bash","bash","-c",cmd, (char*)0);
error_exit(MSG_START "run_subprocess failed to execute command");
}
else
{
//if(sem_wait(&mysem)==-1) error_exit("the second sem_wait() failed in run_subprocess()");
int synctemp;
read(syncpipe[0], &synctemp, 1);
*pgrp = getpgid(pid);
fprintf(stderr, MSG_START "run_subprocess pgid returned = %d\n", *pgrp);
return pid;
}
}
void print_client(client_t* client, const char* what)
{
fprintf(stderr,MSG_START "(client %s:%d) %s\n", inet_ntoa(client->addr.sin_addr), client->addr.sin_port, what);
}
#define CTL_BUFSIZE 1024
int read_socket_ctl(int fd, char* output, int max_size)
{
//fprintf(stderr, "doing read_socket_ctl %d\n", fd);
//if(!fd) return 0;
static char buffer[CTL_BUFSIZE];
static int buffer_index=0;
if(buffer_index==CTL_BUFSIZE) buffer_index=0;
int bytes_read=recv(fd,buffer+buffer_index,(CTL_BUFSIZE-buffer_index)*sizeof(char), MSG_DONTWAIT);
if(bytes_read<=0) return 0;
//fprintf(stderr, "recv %d\n", bytes_read);
int prev_newline_at=0;
int last_newline_at=0;
for(int i=0;i<buffer_index+bytes_read;i++)
{
if(buffer[i]=='\n')
{
prev_newline_at=last_newline_at;
last_newline_at=i+1;
}
}
if(last_newline_at)
{
int oi=0;
for(int i=prev_newline_at;buffer[i]!='\n'&&oi<max_size;i++) output[oi++]=buffer[i]; //copy to output buffer
output[oi++]='\0';
memmove(buffer,buffer+last_newline_at,buffer_index+bytes_read-last_newline_at);
buffer_index=bytes_read-last_newline_at;
return 1;
}
else
{
buffer_index+=bytes_read;
return 0;
}
}
int ctl_get_arg(char* input, const char* cmd, const char* format, ...)
{
int retval=0;
int cmdlen=strlen(cmd);
if(input[cmdlen]=='=')
{
//fprintf(stderr, "cga found=\n");
if(input[cmdlen]=0, !strcmp(input,cmd))
{
//fprintf(stderr, "cga foundokay\n");
va_list vl;
va_start(vl,format);
retval=vsscanf(input+cmdlen+1,format,vl);
va_end(vl);
}
input[cmdlen]='=';
}
//fprintf(stderr, "cga retval %d\n", retval);
return retval;
}
void client()
{
in_client=1;
print_client(this_client, "client process forked.");
char client_subprocess_cmd_buf[500];
int input_fd = this_client->pipefd[0];
int pipe_ctl[2], pipe_stdout[2];
prctl(PR_SET_PDEATHSIG, SIGHUP); //get a signal when parent exits
if(decimation!=1)
{
if(pipe(pipe_ctl)==-1) error_exit(MSG_START "cannot open new pipe() for the client subprocess");
if(pipe(pipe_stdout)==-1) error_exit(MSG_START "cannot open new pipe() for the client subprocess");
switch(ddc_method)
{
case M_TD:
sprintf(client_subprocess_cmd_buf, subprocess_cmd_td, pipe_ctl[0], decimation, transition_bw);
break;
case M_FASTDDC:
sprintf(client_subprocess_cmd_buf, subprocess_args_fastddc_2, pipe_ctl[0], decimation, transition_bw);
break;
}
if(!(client_subprocess_pid = run_subprocess( client_subprocess_cmd_buf, this_client->pipefd, pipe_stdout, &client_subprocess_pgrp)))
print_exit(MSG_START "couldn't start client_subprocess_cmd!\n");
fprintf(stderr, MSG_START "starting client_subprocess_cmd: %s\n", client_subprocess_cmd_buf);
input_fd = pipe_stdout[0]; //we don't have to set it nonblocking
fprintf(stderr, MSG_START "pipe_stdout[0] = %d\n", pipe_stdout[0]);
write(pipe_ctl[1], "0.0\n", 4);
}
char recv_cmd[CTL_BUFSIZE];
char temps[CTL_BUFSIZE*2];
int tempi;
float tempf;
for(;;)
{
while(read_socket_ctl(this_client->socket, recv_cmd, CTL_BUFSIZE))
{
sprintf(temps, "read_socket_ctl: %s", recv_cmd);
print_client(this_client, temps);
if(ctl_get_arg(recv_cmd, "bypass", "%d", &tempi))
{
if(tempi==1 && client_subprocess_pid)
{
//print_client(this_client, "suspending client_subprocess_pgrp...\n");
//fprintf(stderr, "client_subprocess_pgrp = %d\n", client_subprocess_pgrp);
//killpg(client_subprocess_pgrp, SIGTSTP);
//while(proc_exists(client_subprocess_pid)) usleep(10000);
//print_client(this_client, "done killing client_subprocess_pid.\n");
input_fd=this_client->pipefd[0]; //by doing this, we don't read from pipe_stdout[0] anymore, so that csdr stops doing anything, and also doesn't read anymore from the input: we get the whole I/Q stream!
}
if(tempi==0 && client_subprocess_pid)
{
input_fd=pipe_stdout[0];
}
}
if(ctl_get_arg(recv_cmd, "shift", "%g", &tempf))
{
tempi=sprintf(temps, "%g\n", tempf);
write(pipe_ctl[1], temps, tempi);
fsync(pipe_ctl[1]);
}
}
int nread = read(input_fd,buf,bufsizeall);
if(nread<=0) continue;
if(send(this_client->socket,buf,nread,0)==-1)
{
print_client(this_client, "client process is exiting.\n");
if(client_subprocess_pid) killpg2(client_subprocess_pgrp);
exit(0);
}
}
}
void killpg2(pid_t pgrp)
{
//fprintf(stderr, MSG_START "killpg2: %d\n", pgrp);
if(pgrp!=1 && pgrp!=0) killpg(pgrp, SIGTERM);
}
void error_exit(const char* why)
{
perror(why);
exit(1);
}
void print_exit(const char* why)
{
fprintf(stderr, "%s", why);
exit(1);
}
void maxfd(int* maxfd, int fd)
{
if(fd>=*maxfd) *maxfd=fd+1;
}

View file

@ -1,62 +0,0 @@
#pragma once
#include <signal.h>
#include <stdio.h>
#include <getopt.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <iostream>
#include <vector>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/wait.h>
#include <sys/prctl.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <semaphore.h>
typedef struct client_s
{
struct sockaddr_in addr;
int socket;
pid_t pid;
int pipefd[2];
int error;
pid_t dsp_proc;
} client_t;
void client();
void error_exit(const char* why);
void print_exit(const char* why);
void print_client(client_t* client, const char* what);
int proc_exists(pid_t pid);
pid_t run_subprocess(char* cmd, int* pipe_in, int* pipe_out, pid_t* pgrp);
void maxfd(int* maxfd, int fd);
void sig_handler(int signo);
void killpg2(pid_t pgrp);
int ctl_get_arg(char* input, const char* cmd, const char* format, ...);
typedef enum ddc_method_e
{
M_TD,
M_FASTDDC
} ddc_method_t;
const char subprocess_cmd_td[] = "csdr "
#ifdef NEON_OPTS
"shift_addfast_cc"
#else
"shift_unroll_cc"
#endif
" --fd %d | csdr fir_decimate_cc %d %g";
const char subprocess_args_fastddc_1[] = "csdr fastddc_fwd_cc %d %g";
//const char subprocess_args_fastddc_1[] = "csdr through %d %g";
const char subprocess_args_fastddc_2[] = "csdr fastddc_inv_cc --fd %d %d %g";
//const char subprocess_args_fastddc_2[] = "csdr convert_u8_f %d %d %g";

View file

@ -1,80 +0,0 @@
#!/bin/sh
# This software is part of libcsdr, a set of simple DSP routines for
# Software Defined Radio.
#
# Copyright (c) 2014, Andras Retzler <randras@sdr.hu>
# Copyright (c) 2019, MeFisto94
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This file will try to detect the correct GCC optimization parameters, especially when running on ARM Platforms such as the Raspberry Pi
# Desktop Processors
if grep -q sse /proc/cpuinfo; then
if grep -q sse /proc/cpuinfo; then
PARAMS_SSE="$PARAMS_SSE-msse"
fi
if grep -q sse2 /proc/cpuinfo; then
PARAMS_SSE="$PARAMS_SSE -msse2"
fi
if grep -q sse3 /proc/cpuinfo; then
PARAMS_SSE="$PARAMS_SSE -msse3"
fi
if grep -q sse4a /proc/cpuinfo; then
PARAMS_SSE="$PARAMS_SSE -msse4a"
fi
if grep -q sse4_1 /proc/cpuinfo; then
PARAMS_SSE="$PARAMS_SSE -msse4.1"
fi
# TODO: Is this "-msse4" only for sse4_2 intended?
if grep -q sse4_2 /proc/cpuinfo; then
PARAMS_SSE="$PARAMS_SSE -msse4.2 -msse4"
fi
echo "$PARAMS_SSE -mfpmath=sse"
return 0
else
ARCH=$(uname -m)
# Detect Raspberry Pi
if grep -q 'Raspberry' /proc/device-tree/model; then
if [ "$ARCH" = "aarch64" ]; then # Probably RPi 3+ on 64bit
# Float ABI is always hard on AARCH64. TODO: Does RPi 1 or 2 also have aarch64?
PARAMS_PI="-mcpu=cortex-a53 -mtune=cortex-a53"
else # note -mcpu replaces -march
# See https://gist.github.com/fm4dd/c663217935dc17f0fc73c9c81b0aa845
if grep -q 3 /proc/device-tree/model; then
PARAMS_PI="-mcpu=cortex-a53 -mfloat-abi=hard -mfpu=neon-fp-armv8 -mneon-for-64bits"
elif grep -q 2 /proc/device-tree/model; then
PARAMS_PI="-mcpu=cortex-a7 -mfloat-abi=hard -mfpu=neon-vfpv4"
elif grep -q 1 /proc/device-tree/model; then
PARAMS_PI="-mcpu=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp"
fi
fi
PARAMS_ARM="$PARAMS_PI -funsafe-math-optimizations -Wformat=0"
else # Generic ARM Device
# Most likely mtune is incorrect here
PARAMS_ARM = "-mfloat-abi=hard -march=`uname -m` -mtune=cortex-a8 -mfpu=neon -mvectorize-with-neon-quad -funsafe-math-optimizations -Wformat=0 -DNEON_OPTS"
fi
echo $PARAMS_ARM
return 0
fi

View file

@ -22,7 +22,6 @@ struct fft_plan_s
#include "libcsdr.h"
FFT_PLAN_T* make_fft_c2c(int size, complexf* input, complexf* output, int forward, int benchmark);
FFT_PLAN_T* make_fft_r2c(int size, float* input, complexf* output, int benchmark);
void fft_execute(FFT_PLAN_T* plan);
void fft_destroy(FFT_PLAN_T* plan);

View file

@ -1,53 +0,0 @@
#!/usr/bin/python
import os, time, signal
from subprocess import *
#https://bugs.python.org/issue1652
def p(x):
global printcmds
if printcmds: print x
return check_output(x, shell=True)
printcmds=True
def genfiles(snr):
cmd="""(while true; do echo -n 'CQ CQ CQ DE HA7ILM HA7ILM HA7ILM PSE K '; done) | \
csdr psk31_varicode_encoder_u8_u8 | \
tee /s/bpsk31_testin | \
csdr differential_encoder_u8_u8 | \
csdr psk_modulator_u8_c 2 | \
csdr psk31_interpolate_sine_cc 256 | \
csdr awgn_cc %d | \
csdr timing_recovery_cc GARDNER 256 0.5 2 --add_q | \
csdr dbpsk_decoder_c_u8 | \
dd bs=1024 count=10 of=/s/bpsk31_testout
"""%snr
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
if printcmds: print cmd
os.system(cmd)
def getminsize():
return min(os.path.getsize("/s/bpsk31_testout"), os.path.getsize("/s/bpsk31_testin"))
def mkdiff(shift):
if shift==0:
return int(p("cmp -l /s/bpsk31_testin /s/bpsk31_testout | wc -l"))
elif shift<0:
return int(p("(dd if=/dev/zero bs=%d count=1; cat /s/bpsk31_testin)>/s/bpsk31_testin0; cmp -l /s/bpsk31_testin0 /s/bpsk31_testout | wc -l"%-shift))
elif shift>0:
return int(p("(dd if=/dev/zero bs=%d count=1; cat /s/bpsk31_testout)>/s/bpsk31_testout0; cmp -l /s/bpsk31_testin /s/bpsk31_testout0 | wc -l"%shift))
lf=open("/s/output_results","w")
for snr in range(0,20,2):
genfiles(snr)
num_totalbits=getminsize()
num_errors=None
for shift in range(-5,5):
curr_num_errors = mkdiff(shift)
if not num_errors or (num_errors and num_errors > curr_num_errors):
num_errors = curr_num_errors
lf.write("%d; %d; %d; %d\n" %(snr, num_errors, num_totalbits, num_errors/float(num_totalbits)))

View file

@ -1,67 +0,0 @@
#!/usr/bin/octave
%{
function [output]=fgc(path, type)
if(type(1)=='f')
elseif(type(1)=='c')
end
end
%}
function output=shrunf(cmd)
SIGTERM=15;
output=[];
[pin, pout, pid]=popen2('bash',{'-c', cmd});
%fclose(pin);
sleep(0.1)
do
current_output=fread(pout, Inf, 'float32');
output=[output; current_output];
until(feof(pout))
waitpid(pid);
%kill(pid, SIGTERM);
fclose(pin);
fclose(pout);
end
function error_value=run_tr(skip, which_ted)
out_vect=shrunf(sprintf('dd bs=8 skip=%d if=bpsk31_baseband_sample_complex_8000_sps_010101.raw | csdr timing_recovery_cc %s 256 --add_q --output_error', skip, which_ted));
error_value=out_vect(2);
end
function error_values=mkscurve(which_ted, skips)
error_values=[]
for skip=skips
error_values=[error_values run_tr(skip, which_ted)];
end
end
function fmtplot(h)
FN = findall(h,'-property','FontName');
set(FN,'FontName','/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerifCondensed.ttf');
set(FN,'FontName','times');
FS = findall(h,'-property','FontSize');
set(FS,'FontSize',18);
xlabel('Phase offset in number of samples');
ylabel('Error value (TED output)');
end
skips_gardner=0:16:256
error_values_gardner=mkscurve('GARDNER',skips_gardner);
skips_earlylate=0:16:256
error_values_earlylate=mkscurve('EARLYLATE',skips_earlylate);
%graphics_toolkit("gnuplot")
h=figure(1);
plot((skips_gardner-128)/256, -error_values_gardner, 'linewidth', 2);
title('S-curve for Gardner TED');
fmtplot(h)
grid on
pause
plot((skips_earlylate-128)/256, error_values_earlylate, 'linewidth', 2);
title('S-curve for early-late TED');
fmtplot(h)
grid on
pause

View file

@ -1,99 +0,0 @@
#!/usr/bin/octave
%you need to first install the parallel and struct packages:
%pkg install -forge struct
%pkg install -forge parallel
pkg load parallel
function y=inarg(x)
for i=1:length(argv())
if strcmp(argv(){i},x)
y=1;
return
end
end
y=0;
end
bpfcmd="csdr bandpass_fir_fft_cc $(csdr \"=-31.25/8e3\") $(csdr \"=31.25/8e3\") $(csdr \"=31.25/8e3\") | ";
if !inarg('--nogen')
fwrite(stdout, "===========================================\nGenerating baseband signal from random data\n===========================================\n");
system(["cat /dev/urandom | csdr pack_bits_8to1_u8_u8 | csdr psk_modulator_u8_c 2 | csdr gain_ff 0.25 | csdr psk31_interpolate_sine_cc 256 | " bpfcmd "csdr add_n_zero_samples_at_beginning_f 170 | pv -ps 2g | dd iflag=fullblock bs=128M count=16 of=/tmp/psk31-raw-data"]);
fwrite(stdout, "===========================================\nGenerating Gaussian white noise for agwn_cc\n===========================================\n");
system(["csdr gaussian_noise_c | " bpfcmd "pv -ps 256m | dd of=/tmp/psk31-gaussian-noise iflag=fullblock bs=256M count=1"]);
end
if inarg('--onlygen')
exit(0)
end
fwrite(stdout, "===========================================\nCalculating variance graph data \n===========================================\n");
function output=shrun(cmd, type, minsize)
SIGTERM=15;
output=[];
cmd
[pin, pout, pid]=popen2('bash',{'-c', cmd});
%fclose(pin);
do
sleep(0.3)
fwrite(stdout,'.');
%size(output)
%output
current_output=fread(pout, Inf, type);
frewind(pout);
output=[output; current_output];
until(size(output)(1)>=minsize)
waitpid(pid);
kill(pid, SIGTERM);
fclose(pin);
fclose(pout);
end
function variance=run_var(snr, which_ted)
disp('ran a command')
out_vect=shrun(sprintf('cat /tmp/psk31-raw-data | csdr awgn_cc %d --awgnfile /tmp/psk31-gaussian-noise | csdr simple_agc_cc 0.0001 0.5 | csdr timing_recovery_cc %s 256 0.5 2 --add_q --output_indexes | CSDR_FIXED_BUFSIZE=1048576 csdr normalized_timing_variance_u32_f 256 85', snr, which_ted), 'float32', 1);
disp('run_var output:');
out_vect'
variance=out_vect(1);
end
function variances=mkvarplot(which_ted, snrs)
fun = @(x) run_var(x, which_ted);
variances=pararrayfun(nproc, fun, snrs);
%{
variances=[]
for snr=snrs
snr
variances=[variances run_var(snr, which_ted)];
end
%}
end
function fmtplot(h)
FN = findall(h,'-property','FontName');
set(FN,'FontName','/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerifCondensed.ttf');
set(FN,'FontName','times');
FS = findall(h,'-property','FontSize');
set(FS,'FontSize',18);
xlabel('E_b/N_0 [dB]');
ylabel('Phase error variance [rad^2]');
end
%snrs=-10:5:10
snrs=-10:5:25
%snrs=[10]
error_values=mkvarplot('EARLYLATE',snrs);
%graphics_toolkit("gnuplot")
h=figure(1);
ebn0=snrs+9.7
semilogy(ebn0, error_values, 'linewidth', 2);
title('Estimation variance');
fmtplot(h)
pause
if !inarg('--nogen')
system('rm /tmp/psk31-raw-data /tmp/psk31-gaussian-noise');
end

View file

@ -1,70 +0,0 @@
#!/usr/bin/octave
global Tb=20
function g=gbb(t) %impulse response of pulse shaping filter
global Tb
g=t;
for i = 1:size(t)(2)
if (t(i)>1*Tb || t(i)<=-1*Tb)
g(i) = 0;
else
g(i) = 0.5+cos((t(i)/(Tb*1))*pi)/2; %this is not RRC, rather a sinusoidal pulse shape
end
end
end
global padding=[-2 2];
function [toreturny, plotrange]=y(s)
global Tb
global padding
slen=size(s)(2)
plotrange=((padding(1)-1)*Tb):(slen+padding(2))*Tb-1;
plotlen=size(plotrange)(2)
toreturny=zeros(1,plotlen);
for i=1:slen %sum of (symbol[i] * filter impulse response) for all symbols
toreturny+=s(i)*gbb(plotrange.-(i-1)*Tb);
end
plotrange=plotrange/Tb
end
function fmtplot(h)
FN = findall(h,'-property','FontName');
set(FN,'FontName','/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerifCondensed.ttf');
set(FN,'FontName','times');
FS = findall(h,'-property','FontSize');
set(FS,'FontSize',18);
set(FS,'FontSize',18);
end
h=figure(1);
subplot(2, 1, 1);
[a b]=y([1]);
plot(b, a, 'linewidth', 2)
title(sprintf("Impulse response of pulse shaping filter"))
xlabel('t/Ts')
ylabel('h(t)')
subplot(2, 1, 2);
[a b]=y([1 1 -1 -1 1 1 1 -1 1 -1 1 1]);
plot(b, a, 'linewidth', 2)
title("Baseband signal for modulator input\nbit sequence: 110011101011") %assuming that differential encoding has already been performed
xlabel('t/Ts')
ylabel('s(t)')
xbounds = xlim;
set(gca,'XTick',xbounds(1):xbounds(2));
fmtplot(h);
pause
exit
%fourier analisys of baseband signal
h2=figure(2);
padding=[-1 1]
plot(y([1]))
h3=figure(3);
fftvals=abs(fft(y([1])));
sizefftvals=size(fftvals)(2)
fftvals=[fftvals(sizefftvals/2:sizefftvals) fftvals(2:sizefftvals/2)]
plot(fftvals, "-")
pause

View file

@ -1,669 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<?grc format='1' created='3.7.8'?>
<flow_graph>
<timestamp>Sun Nov 16 15:12:31 2014</timestamp>
<block>
<key>options</key>
<param>
<key>author</key>
<value></value>
</param>
<param>
<key>window_size</key>
<value>1280, 1024</value>
</param>
<param>
<key>category</key>
<value>Custom</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>description</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(10, 10)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>generate_options</key>
<value>wx_gui</value>
</param>
<param>
<key>id</key>
<value>top_block</value>
</param>
<param>
<key>max_nouts</key>
<value>0</value>
</param>
<param>
<key>realtime_scheduling</key>
<value></value>
</param>
<param>
<key>run_options</key>
<value>prompt</value>
</param>
<param>
<key>run</key>
<value>True</value>
</param>
<param>
<key>thread_safe_setters</key>
<value></value>
</param>
<param>
<key>title</key>
<value></value>
</param>
</block>
<block>
<key>variable_slider</key>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>converver</key>
<value>float_converter</value>
</param>
<param>
<key>value</key>
<value>1</value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(120, 147)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>amplitude</value>
</param>
<param>
<key>label</key>
<value></value>
</param>
<param>
<key>max</key>
<value>2</value>
</param>
<param>
<key>min</key>
<value>0</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>num_steps</key>
<value>100</value>
</param>
<param>
<key>style</key>
<value>wx.SL_HORIZONTAL</value>
</param>
</block>
<block>
<key>variable_slider</key>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>converver</key>
<value>float_converter</value>
</param>
<param>
<key>value</key>
<value>0</value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(8, 147)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>frequency</value>
</param>
<param>
<key>label</key>
<value></value>
</param>
<param>
<key>max</key>
<value>samp_rate/2</value>
</param>
<param>
<key>min</key>
<value>-samp_rate/2</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>num_steps</key>
<value>100</value>
</param>
<param>
<key>style</key>
<value>wx.SL_HORIZONTAL</value>
</param>
</block>
<block>
<key>variable</key>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(8, 83)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>samp_rate</value>
</param>
<param>
<key>value</key>
<value>40e3</value>
</param>
</block>
<block>
<key>analog_sig_source_x</key>
<param>
<key>amp</key>
<value>1</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>freq</key>
<value>frequency</value>
</param>
<param>
<key>_coordinate</key>
<value>(184, 11)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>analog_sig_source_x_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>offset</key>
<value>0</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>waveform</key>
<value>analog.GR_COS_WAVE</value>
</param>
</block>
<block>
<key>blocks_multiply_const_vxx</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>const</key>
<value>amplitude</value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(344, 43)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_multiply_const_vxx_0</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>blocks_throttle</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(496, 43)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_throttle_0_0</value>
</param>
<param>
<key>ignoretag</key>
<value>True</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>samples_per_second</key>
<value>samp_rate</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>ha5kfu_execproc_xx</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>commandline</key>
<value>csdr awgn_cc 10 --snrshow</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>1</value>
</param>
<param>
<key>_coordinate</key>
<value>(344, 275)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>ha5kfu_execproc_xx_0_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>type</key>
<value>cc</value>
</param>
</block>
<block>
<key>wxgui_fftsink2</key>
<param>
<key>avg_alpha</key>
<value>0</value>
</param>
<param>
<key>average</key>
<value>False</value>
</param>
<param>
<key>baseband_freq</key>
<value>0</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>fft_size</key>
<value>1024</value>
</param>
<param>
<key>freqvar</key>
<value>None</value>
</param>
<param>
<key>_coordinate</key>
<value>(616, 203)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_fftsink2_0_0</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>peak_hold</key>
<value>False</value>
</param>
<param>
<key>ref_level</key>
<value>0</value>
</param>
<param>
<key>ref_scale</key>
<value>2.0</value>
</param>
<param>
<key>fft_rate</key>
<value>15</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>title</key>
<value>FFT Plot</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>win</key>
<value>None</value>
</param>
<param>
<key>y_divs</key>
<value>10</value>
</param>
<param>
<key>y_per_div</key>
<value>10</value>
</param>
</block>
<block>
<key>wxgui_fftsink2</key>
<param>
<key>avg_alpha</key>
<value>0</value>
</param>
<param>
<key>average</key>
<value>False</value>
</param>
<param>
<key>baseband_freq</key>
<value>0</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>fft_size</key>
<value>1024</value>
</param>
<param>
<key>freqvar</key>
<value>None</value>
</param>
<param>
<key>_coordinate</key>
<value>(856, 75)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_fftsink2_0_0_0</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>peak_hold</key>
<value>False</value>
</param>
<param>
<key>ref_level</key>
<value>0</value>
</param>
<param>
<key>ref_scale</key>
<value>2.0</value>
</param>
<param>
<key>fft_rate</key>
<value>15</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>title</key>
<value>FFT Plot</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>win</key>
<value>None</value>
</param>
<param>
<key>y_divs</key>
<value>10</value>
</param>
<param>
<key>y_per_div</key>
<value>10</value>
</param>
</block>
<connection>
<source_block_id>analog_sig_source_x_0</source_block_id>
<sink_block_id>blocks_multiply_const_vxx_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_multiply_const_vxx_0</source_block_id>
<sink_block_id>blocks_throttle_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_throttle_0_0</source_block_id>
<sink_block_id>ha5kfu_execproc_xx_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_throttle_0_0</source_block_id>
<sink_block_id>wxgui_fftsink2_0_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>ha5kfu_execproc_xx_0_0</source_block_id>
<sink_block_id>wxgui_fftsink2_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
</flow_graph>

File diff suppressed because it is too large Load diff

View file

@ -1,675 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<?grc format='1' created='3.7.8'?>
<flow_graph>
<timestamp>Mon Oct 13 20:03:23 2014</timestamp>
<block>
<key>options</key>
<param>
<key>author</key>
<value></value>
</param>
<param>
<key>window_size</key>
<value>1280, 1024</value>
</param>
<param>
<key>category</key>
<value>Custom</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>description</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(10, 10)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>generate_options</key>
<value>wx_gui</value>
</param>
<param>
<key>id</key>
<value>top_block</value>
</param>
<param>
<key>max_nouts</key>
<value>0</value>
</param>
<param>
<key>realtime_scheduling</key>
<value></value>
</param>
<param>
<key>run_options</key>
<value>prompt</value>
</param>
<param>
<key>run</key>
<value>True</value>
</param>
<param>
<key>thread_safe_setters</key>
<value></value>
</param>
<param>
<key>title</key>
<value></value>
</param>
</block>
<block>
<key>variable</key>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(184, 11)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>samp_rate</value>
</param>
<param>
<key>value</key>
<value>48e3</value>
</param>
</block>
<block>
<key>audio_source</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>device_name</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(56, 107)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>audio_source_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>num_outputs</key>
<value>1</value>
</param>
<param>
<key>ok_to_block</key>
<value>True</value>
</param>
<param>
<key>samp_rate</key>
<value>int(samp_rate)</value>
</param>
</block>
<block>
<key>blocks_file_sink</key>
<param>
<key>append</key>
<value>False</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>file</key>
<value>/home/pcfl/Asztal/szakdoga/dipterv1/bpsk31_input_f.raw</value>
</param>
<param>
<key>_coordinate</key>
<value>(232, 251)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_file_sink_0</value>
</param>
<param>
<key>type</key>
<value>float</value>
</param>
<param>
<key>unbuffered</key>
<value>False</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>blocks_file_sink</key>
<param>
<key>append</key>
<value>False</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>file</key>
<value>/home/pcfl/Asztal/szakdoga/dipterv1/bpsk31_baseband_c.raw</value>
</param>
<param>
<key>_coordinate</key>
<value>(1032, 91)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_file_sink_0_0</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>unbuffered</key>
<value>False</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>freq_xlating_fir_filter_xxx</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>center_freq</key>
<value>2000</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>decim</key>
<value>1</value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(296, 123)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>freq_xlating_fir_filter_xxx_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>taps</key>
<value>[1]</value>
</param>
<param>
<key>type</key>
<value>fcc</value>
</param>
</block>
<block>
<key>low_pass_filter</key>
<param>
<key>beta</key>
<value>6.76</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>cutoff_freq</key>
<value>1000</value>
</param>
<param>
<key>decim</key>
<value>1</value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>type</key>
<value>fir_filter_ccf</value>
</param>
<param>
<key>_coordinate</key>
<value>(536, 99)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>gain</key>
<value>1</value>
</param>
<param>
<key>id</key>
<value>low_pass_filter_0</value>
</param>
<param>
<key>interp</key>
<value>1</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>width</key>
<value>100</value>
</param>
<param>
<key>win</key>
<value>firdes.WIN_HAMMING</value>
</param>
</block>
<block>
<key>notebook</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(280, 11)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>nb</value>
</param>
<param>
<key>labels</key>
<value>['tab1', 'tab2', 'tab3', 'tab4']</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>style</key>
<value>wx.NB_TOP</value>
</param>
</block>
<block>
<key>wxgui_fftsink2</key>
<param>
<key>avg_alpha</key>
<value>0</value>
</param>
<param>
<key>average</key>
<value>False</value>
</param>
<param>
<key>baseband_freq</key>
<value>0</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>fft_size</key>
<value>1024</value>
</param>
<param>
<key>freqvar</key>
<value>None</value>
</param>
<param>
<key>_coordinate</key>
<value>(1032, 187)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_fftsink2_0</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>peak_hold</key>
<value>False</value>
</param>
<param>
<key>ref_level</key>
<value>0</value>
</param>
<param>
<key>ref_scale</key>
<value>2.0</value>
</param>
<param>
<key>fft_rate</key>
<value>15</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>title</key>
<value>FFT Plot</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>win</key>
<value>None</value>
</param>
<param>
<key>y_divs</key>
<value>10</value>
</param>
<param>
<key>y_per_div</key>
<value>10</value>
</param>
</block>
<block>
<key>wxgui_fftsink2</key>
<param>
<key>avg_alpha</key>
<value>0</value>
</param>
<param>
<key>average</key>
<value>False</value>
</param>
<param>
<key>baseband_freq</key>
<value>0</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>fft_size</key>
<value>1024</value>
</param>
<param>
<key>freqvar</key>
<value>None</value>
</param>
<param>
<key>_coordinate</key>
<value>(232, 339)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_fftsink2_0_0</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>peak_hold</key>
<value>False</value>
</param>
<param>
<key>ref_level</key>
<value>0</value>
</param>
<param>
<key>ref_scale</key>
<value>2.0</value>
</param>
<param>
<key>fft_rate</key>
<value>15</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>title</key>
<value>FFT Plot</value>
</param>
<param>
<key>type</key>
<value>float</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>win</key>
<value>None</value>
</param>
<param>
<key>y_divs</key>
<value>10</value>
</param>
<param>
<key>y_per_div</key>
<value>10</value>
</param>
</block>
<connection>
<source_block_id>audio_source_0</source_block_id>
<sink_block_id>blocks_file_sink_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>audio_source_0</source_block_id>
<sink_block_id>freq_xlating_fir_filter_xxx_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>audio_source_0</source_block_id>
<sink_block_id>wxgui_fftsink2_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>freq_xlating_fir_filter_xxx_0</source_block_id>
<sink_block_id>low_pass_filter_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>low_pass_filter_0</source_block_id>
<sink_block_id>blocks_file_sink_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>low_pass_filter_0</source_block_id>
<sink_block_id>wxgui_fftsink2_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
</flow_graph>

File diff suppressed because it is too large Load diff

View file

@ -1,10 +0,0 @@
#!/bin/bash
sox -r 48k -t f32 -c 2 /s/costas_nco -t wav -e floating-point /s/costas_nco.wav
sox -r 48k -t f32 -c 1 /s/costas_error -t wav -e floating-point /s/costas_error.wav
sox -r 48k -t f32 -c 1 /s/costas_dphase -t wav -e floating-point --norm=-6 /s/costas_dphase.wav
sox -r 48k -t f32 -c 2 /s/costas_input -t wav -e floating-point /s/costas_input.wav
sox -r 48k -t f32 -c 2 /s/costas_output -t wav -e floating-point /s/costas_output.wav
sox -r 48k -t f32 -c 2 /s/tr_input -t wav -e floating-point /s/tr_input.wav
ls -al /s/costas_nco.wav /s/costas_error.wav /s/costas_dphase.wav /s/costas_output.wav /s/costas_input.wav

View file

@ -257,7 +257,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(112, 675)</value>
<value>(112, 875)</value>
</param>
<param>
<key>_rotation</key>
@ -375,7 +375,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(368, 691)</value>
<value>(136, 763)</value>
</param>
<param>
<key>_rotation</key>
@ -465,7 +465,7 @@
</param>
<param>
<key>commandline</key>
<value>csdr fastddc_fwd_cc %d | csdr fastddc_inv_cc 0.4 %d"%(decimation,decimation)+"</value>
<value>csdr fastddc_fwd_cc %d | csdr fastddc_inv_cc %d 0.4"%(decimation,decimation)+"</value>
</param>
<param>
<key>comment</key>
@ -690,7 +690,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(616, 291)</value>
<value>(616, 379)</value>
</param>
<param>
<key>_rotation</key>
@ -789,7 +789,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(576, 619)</value>
<value>(400, 691)</value>
</param>
<param>
<key>_rotation</key>

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,816 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<?grc format='1' created='3.7.8'?>
<flow_graph>
<timestamp>Sat Oct 31 16:06:38 2015</timestamp>
<block>
<key>options</key>
<param>
<key>author</key>
<value></value>
</param>
<param>
<key>window_size</key>
<value>1280*2, 1024*4</value>
</param>
<param>
<key>category</key>
<value>Custom</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>description</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(8, 11)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>generate_options</key>
<value>wx_gui</value>
</param>
<param>
<key>id</key>
<value>top_block</value>
</param>
<param>
<key>max_nouts</key>
<value>0</value>
</param>
<param>
<key>realtime_scheduling</key>
<value></value>
</param>
<param>
<key>run_options</key>
<value>prompt</value>
</param>
<param>
<key>run</key>
<value>True</value>
</param>
<param>
<key>thread_safe_setters</key>
<value></value>
</param>
<param>
<key>title</key>
<value></value>
</param>
</block>
<block>
<key>variable</key>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(272, 11)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>interp</value>
</param>
<param>
<key>value</key>
<value>1024*4</value>
</param>
</block>
<block>
<key>variable</key>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(176, 11)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>samp_rate</value>
</param>
<param>
<key>value</key>
<value>2**16</value>
</param>
</block>
<block>
<key>blocks_complex_to_float</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>1</value>
</param>
<param>
<key>_coordinate</key>
<value>(656, 65)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_complex_to_float_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>blocks_interleave</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>blocksize</key>
<value>1</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>1</value>
</param>
<param>
<key>_coordinate</key>
<value>(904, 65)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_interleave_0</value>
</param>
<param>
<key>type</key>
<value>float</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>num_streams</key>
<value>2</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>blocks_throttle</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(496, 155)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_throttle_0</value>
</param>
<param>
<key>ignoretag</key>
<value>True</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>samples_per_second</key>
<value>samp_rate</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>blocks_vco_c</key>
<param>
<key>amplitude</key>
<value>1</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(248, 139)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_vco_c_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>sensitivity</key>
<value>samp_rate*0.9</value>
</param>
</block>
<block>
<key>blocks_vector_source_x</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(8, 139)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_vector_source_x_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>type</key>
<value>float</value>
</param>
<param>
<key>repeat</key>
<value>True</value>
</param>
<param>
<key>tags</key>
<value>[]</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
<param>
<key>vector</key>
<value>[2]*interp+[-2]*interp+[0.333*2]*interp+[-0.333*2]*interp</value>
</param>
</block>
<block>
<key>ha5kfu_execproc_sink_f</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>commandline</key>
<value>csdr fmdemod_quadri_cf | csdr dsb_fc | csdr fir_decimate_cc 40 | csdr timing_recovery_cc GARDNER 100 0.5 2 --add_q | CSDR_FIXED_BUFSIZE=64 csdr realpart_cf | CSDR_FIXED_BUFSIZE=64 csdr gain_ff 2.5 | CSDR_FIXED_BUFSIZE=64 csdr generic_slicer_f_u8 4 &gt; /s/mfsksymbols</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>1</value>
</param>
<param>
<key>_coordinate</key>
<value>(1040, 75)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>ha5kfu_execproc_sink_f_0</value>
</param>
</block>
<block>
<key>ha5kfu_execproc_xx</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>commandline</key>
<value>csdr fmdemod_quadri_cf | csdr dsb_fc | csdr bandpass_fir_fft_cc -0.1 0.1 0.001 | csdr timing_recovery_cc GARDNER 1024 0.5 2 --add_q | csdr realpart_cf | csdr generic_slicer_f_u8 4 &gt; /s/sliced</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>0</value>
</param>
<param>
<key>_coordinate</key>
<value>(528, 467)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>ha5kfu_execproc_xx_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>type</key>
<value>cc</value>
</param>
</block>
<block>
<key>wxgui_fftsink2</key>
<param>
<key>avg_alpha</key>
<value>0</value>
</param>
<param>
<key>average</key>
<value>False</value>
</param>
<param>
<key>baseband_freq</key>
<value>0</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>fft_size</key>
<value>1024</value>
</param>
<param>
<key>freqvar</key>
<value>None</value>
</param>
<param>
<key>_coordinate</key>
<value>(1040, 115)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_fftsink2_0</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>peak_hold</key>
<value>False</value>
</param>
<param>
<key>ref_level</key>
<value>0</value>
</param>
<param>
<key>ref_scale</key>
<value>2.0</value>
</param>
<param>
<key>fft_rate</key>
<value>15</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>title</key>
<value>FFT Plot</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>win</key>
<value>None</value>
</param>
<param>
<key>y_divs</key>
<value>10</value>
</param>
<param>
<key>y_per_div</key>
<value>10</value>
</param>
</block>
<block>
<key>wxgui_scopesink2</key>
<param>
<key>ac_couple</key>
<value>False</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>0</value>
</param>
<param>
<key>_coordinate</key>
<value>(864, 443)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_scopesink2_0</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>num_inputs</key>
<value>1</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>t_scale</key>
<value>0</value>
</param>
<param>
<key>title</key>
<value>Scope Plot</value>
</param>
<param>
<key>trig_mode</key>
<value>wxgui.TRIG_MODE_AUTO</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>v_offset</key>
<value>0</value>
</param>
<param>
<key>v_scale</key>
<value>0</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>xy_mode</key>
<value>False</value>
</param>
<param>
<key>y_axis_label</key>
<value>Counts</value>
</param>
</block>
<block>
<key>wxgui_waterfallsink2</key>
<param>
<key>avg_alpha</key>
<value>0</value>
</param>
<param>
<key>average</key>
<value>False</value>
</param>
<param>
<key>baseband_freq</key>
<value>0</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>dynamic_range</key>
<value>100</value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>fft_rate</key>
<value>15</value>
</param>
<param>
<key>fft_size</key>
<value>512</value>
</param>
<param>
<key>freqvar</key>
<value>None</value>
</param>
<param>
<key>_coordinate</key>
<value>(864, 251)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_waterfallsink2_0</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>ref_scale</key>
<value>2.0</value>
</param>
<param>
<key>ref_level</key>
<value>0</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>title</key>
<value>Waterfall Plot</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>win</key>
<value>None</value>
</param>
</block>
<connection>
<source_block_id>blocks_complex_to_float_0</source_block_id>
<sink_block_id>blocks_interleave_0</sink_block_id>
<source_key>1</source_key>
<sink_key>1</sink_key>
</connection>
<connection>
<source_block_id>blocks_complex_to_float_0</source_block_id>
<sink_block_id>blocks_interleave_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_interleave_0</source_block_id>
<sink_block_id>ha5kfu_execproc_sink_f_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_throttle_0</source_block_id>
<sink_block_id>blocks_complex_to_float_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_throttle_0</source_block_id>
<sink_block_id>ha5kfu_execproc_xx_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_throttle_0</source_block_id>
<sink_block_id>wxgui_fftsink2_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_throttle_0</source_block_id>
<sink_block_id>wxgui_waterfallsink2_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_vco_c_0</source_block_id>
<sink_block_id>blocks_throttle_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_vector_source_x_0</source_block_id>
<sink_block_id>blocks_vco_c_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>ha5kfu_execproc_xx_0</source_block_id>
<sink_block_id>wxgui_scopesink2_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
</flow_graph>

View file

@ -1,702 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<?grc format='1' created='3.7.8'?>
<flow_graph>
<timestamp>Sun Nov 16 15:12:31 2014</timestamp>
<block>
<key>options</key>
<param>
<key>author</key>
<value></value>
</param>
<param>
<key>window_size</key>
<value>1280, 1024</value>
</param>
<param>
<key>category</key>
<value>Custom</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>description</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(10, 10)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>generate_options</key>
<value>wx_gui</value>
</param>
<param>
<key>id</key>
<value>top_block</value>
</param>
<param>
<key>max_nouts</key>
<value>0</value>
</param>
<param>
<key>realtime_scheduling</key>
<value></value>
</param>
<param>
<key>run_options</key>
<value>prompt</value>
</param>
<param>
<key>run</key>
<value>True</value>
</param>
<param>
<key>thread_safe_setters</key>
<value></value>
</param>
<param>
<key>title</key>
<value></value>
</param>
</block>
<block>
<key>variable</key>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(8, 83)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>samp_rate</value>
</param>
<param>
<key>value</key>
<value>100e3</value>
</param>
</block>
<block>
<key>analog_const_source_x</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>const</key>
<value>0</value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(40, 179)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>analog_const_source_x_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
</block>
<block>
<key>blocks_complex_to_float</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(392, 313)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_complex_to_float_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>blocks_throttle</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(216, 179)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_throttle_0</value>
</param>
<param>
<key>ignoretag</key>
<value>True</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>samples_per_second</key>
<value>0</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>blocks_throttle</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(680, 91)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_throttle_0_0</value>
</param>
<param>
<key>ignoretag</key>
<value>True</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>samples_per_second</key>
<value>samp_rate</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>blocks_throttle</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(800, 331)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_throttle_0_0_0</value>
</param>
<param>
<key>ignoretag</key>
<value>True</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>samples_per_second</key>
<value>samp_rate</value>
</param>
<param>
<key>type</key>
<value>float</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>ha5kfu_execproc_xx</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>commandline</key>
<value>csdr noise_f</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>1</value>
</param>
<param>
<key>_coordinate</key>
<value>(400, 227)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>ha5kfu_execproc_xx_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>type</key>
<value>cc</value>
</param>
</block>
<block>
<key>ha5kfu_execproc_xx</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>commandline</key>
<value>csdr noise_f</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>1</value>
</param>
<param>
<key>_coordinate</key>
<value>(568, 307)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>ha5kfu_execproc_xx_0_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>type</key>
<value>ff</value>
</param>
</block>
<block>
<key>wxgui_fftsink2</key>
<param>
<key>avg_alpha</key>
<value>0</value>
</param>
<param>
<key>average</key>
<value>False</value>
</param>
<param>
<key>baseband_freq</key>
<value>0</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>fft_size</key>
<value>1024</value>
</param>
<param>
<key>freqvar</key>
<value>None</value>
</param>
<param>
<key>_coordinate</key>
<value>(896, 11)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_fftsink2_0_0</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>peak_hold</key>
<value>False</value>
</param>
<param>
<key>ref_level</key>
<value>0</value>
</param>
<param>
<key>ref_scale</key>
<value>2.0</value>
</param>
<param>
<key>fft_rate</key>
<value>15</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>title</key>
<value>FFT Plot</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>win</key>
<value>None</value>
</param>
<param>
<key>y_divs</key>
<value>10</value>
</param>
<param>
<key>y_per_div</key>
<value>10</value>
</param>
</block>
<block>
<key>wxgui_fftsink2</key>
<param>
<key>avg_alpha</key>
<value>0</value>
</param>
<param>
<key>average</key>
<value>False</value>
</param>
<param>
<key>baseband_freq</key>
<value>0</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>fft_size</key>
<value>1024</value>
</param>
<param>
<key>freqvar</key>
<value>None</value>
</param>
<param>
<key>_coordinate</key>
<value>(976, 259)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_fftsink2_0_0_0</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>peak_hold</key>
<value>False</value>
</param>
<param>
<key>ref_level</key>
<value>0</value>
</param>
<param>
<key>ref_scale</key>
<value>2.0</value>
</param>
<param>
<key>fft_rate</key>
<value>15</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>title</key>
<value>FFT Plot</value>
</param>
<param>
<key>type</key>
<value>float</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>win</key>
<value>None</value>
</param>
<param>
<key>y_divs</key>
<value>10</value>
</param>
<param>
<key>y_per_div</key>
<value>10</value>
</param>
</block>
<connection>
<source_block_id>analog_const_source_x_0</source_block_id>
<sink_block_id>blocks_throttle_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_complex_to_float_0</source_block_id>
<sink_block_id>ha5kfu_execproc_xx_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_throttle_0</source_block_id>
<sink_block_id>blocks_complex_to_float_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_throttle_0</source_block_id>
<sink_block_id>ha5kfu_execproc_xx_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_throttle_0_0</source_block_id>
<sink_block_id>wxgui_fftsink2_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_throttle_0_0_0</source_block_id>
<sink_block_id>wxgui_fftsink2_0_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>ha5kfu_execproc_xx_0</source_block_id>
<sink_block_id>blocks_throttle_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>ha5kfu_execproc_xx_0_0</source_block_id>
<sink_block_id>blocks_throttle_0_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
</flow_graph>

View file

@ -1,752 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<?grc format='1' created='3.7.8'?>
<flow_graph>
<timestamp>Sun Nov 16 15:12:31 2014</timestamp>
<block>
<key>options</key>
<param>
<key>author</key>
<value></value>
</param>
<param>
<key>window_size</key>
<value>1280, 1024</value>
</param>
<param>
<key>category</key>
<value>Custom</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>description</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(10, 10)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>generate_options</key>
<value>wx_gui</value>
</param>
<param>
<key>id</key>
<value>top_block</value>
</param>
<param>
<key>max_nouts</key>
<value>0</value>
</param>
<param>
<key>realtime_scheduling</key>
<value></value>
</param>
<param>
<key>run_options</key>
<value>prompt</value>
</param>
<param>
<key>run</key>
<value>True</value>
</param>
<param>
<key>thread_safe_setters</key>
<value></value>
</param>
<param>
<key>title</key>
<value></value>
</param>
</block>
<block>
<key>variable</key>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(8, 83)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>samp_rate</value>
</param>
<param>
<key>value</key>
<value>1e3</value>
</param>
</block>
<block>
<key>analog_random_source_x</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(8, 155)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>analog_random_source_x_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>max</key>
<value>2147483647</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>min</key>
<value>-2147483648</value>
</param>
<param>
<key>num_samps</key>
<value>1000</value>
</param>
<param>
<key>type</key>
<value>int</value>
</param>
<param>
<key>repeat</key>
<value>True</value>
</param>
</block>
<block>
<key>blocks_deinterleave</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>blocksize</key>
<value>1</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(384, 169)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_deinterleave_0</value>
</param>
<param>
<key>type</key>
<value>float</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>num_streams</key>
<value>2</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>blocks_float_to_complex</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(544, 169)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_float_to_complex_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>blocks_int_to_float</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(208, 179)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_int_to_float_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>scale</key>
<value>2147483647.</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>blocks_throttle</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(736, 179)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_throttle_0</value>
</param>
<param>
<key>ignoretag</key>
<value>True</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>samples_per_second</key>
<value>samp_rate*10</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>ha5kfu_execproc_xx</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>commandline</key>
<value>csdr peaks_fir_cc 101 -0.2 -0.1 0 0.1 0.2</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>1</value>
</param>
<param>
<key>_coordinate</key>
<value>(168, 339)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>ha5kfu_execproc_xx_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>type</key>
<value>cc</value>
</param>
</block>
<block>
<key>wxgui_fftsink2</key>
<param>
<key>avg_alpha</key>
<value>0</value>
</param>
<param>
<key>average</key>
<value>False</value>
</param>
<param>
<key>baseband_freq</key>
<value>0</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>fft_size</key>
<value>1024</value>
</param>
<param>
<key>freqvar</key>
<value>None</value>
</param>
<param>
<key>_coordinate</key>
<value>(472, 435)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_fftsink2_0</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>peak_hold</key>
<value>False</value>
</param>
<param>
<key>ref_level</key>
<value>0</value>
</param>
<param>
<key>ref_scale</key>
<value>2.0</value>
</param>
<param>
<key>fft_rate</key>
<value>15</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>title</key>
<value>FFT Plot</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>win</key>
<value>None</value>
</param>
<param>
<key>y_divs</key>
<value>10</value>
</param>
<param>
<key>y_per_div</key>
<value>10</value>
</param>
</block>
<block>
<key>wxgui_fftsink2</key>
<param>
<key>avg_alpha</key>
<value>0</value>
</param>
<param>
<key>average</key>
<value>False</value>
</param>
<param>
<key>baseband_freq</key>
<value>0</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>fft_size</key>
<value>1024</value>
</param>
<param>
<key>freqvar</key>
<value>None</value>
</param>
<param>
<key>_coordinate</key>
<value>(976, 107)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_fftsink2_0_0</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>peak_hold</key>
<value>False</value>
</param>
<param>
<key>ref_level</key>
<value>0</value>
</param>
<param>
<key>ref_scale</key>
<value>2.0</value>
</param>
<param>
<key>fft_rate</key>
<value>15</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>title</key>
<value>FFT Plot</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>win</key>
<value>None</value>
</param>
<param>
<key>y_divs</key>
<value>10</value>
</param>
<param>
<key>y_per_div</key>
<value>10</value>
</param>
</block>
<block>
<key>wxgui_scopesink2</key>
<param>
<key>ac_couple</key>
<value>False</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>0</value>
</param>
<param>
<key>_coordinate</key>
<value>(480, 299)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_scopesink2_0</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>num_inputs</key>
<value>1</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>t_scale</key>
<value>0</value>
</param>
<param>
<key>title</key>
<value>Scope Plot</value>
</param>
<param>
<key>trig_mode</key>
<value>wxgui.TRIG_MODE_AUTO</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>v_offset</key>
<value>0</value>
</param>
<param>
<key>v_scale</key>
<value>0</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>xy_mode</key>
<value>False</value>
</param>
<param>
<key>y_axis_label</key>
<value>Counts</value>
</param>
</block>
<connection>
<source_block_id>analog_random_source_x_0</source_block_id>
<sink_block_id>blocks_int_to_float_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_deinterleave_0</source_block_id>
<sink_block_id>blocks_float_to_complex_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_deinterleave_0</source_block_id>
<sink_block_id>blocks_float_to_complex_0</sink_block_id>
<source_key>1</source_key>
<sink_key>1</sink_key>
</connection>
<connection>
<source_block_id>blocks_float_to_complex_0</source_block_id>
<sink_block_id>blocks_throttle_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_int_to_float_0</source_block_id>
<sink_block_id>blocks_deinterleave_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_throttle_0</source_block_id>
<sink_block_id>ha5kfu_execproc_xx_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_throttle_0</source_block_id>
<sink_block_id>wxgui_fftsink2_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>ha5kfu_execproc_xx_0</source_block_id>
<sink_block_id>wxgui_fftsink2_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>ha5kfu_execproc_xx_0</source_block_id>
<sink_block_id>wxgui_scopesink2_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
</flow_graph>

File diff suppressed because it is too large Load diff

View file

@ -1,746 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<?grc format='1' created='3.7.8'?>
<flow_graph>
<timestamp>Mon Oct 13 20:03:23 2014</timestamp>
<block>
<key>options</key>
<param>
<key>author</key>
<value></value>
</param>
<param>
<key>window_size</key>
<value>1280, 1024</value>
</param>
<param>
<key>category</key>
<value>Custom</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>description</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(10, 10)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>generate_options</key>
<value>wx_gui</value>
</param>
<param>
<key>id</key>
<value>top_block</value>
</param>
<param>
<key>max_nouts</key>
<value>0</value>
</param>
<param>
<key>realtime_scheduling</key>
<value></value>
</param>
<param>
<key>run_options</key>
<value>prompt</value>
</param>
<param>
<key>run</key>
<value>True</value>
</param>
<param>
<key>thread_safe_setters</key>
<value></value>
</param>
<param>
<key>title</key>
<value></value>
</param>
</block>
<block>
<key>variable</key>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(184, 11)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>samp_rate</value>
</param>
<param>
<key>value</key>
<value>48e3</value>
</param>
</block>
<block>
<key>audio_source</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>device_name</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(56, 107)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>audio_source_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>num_outputs</key>
<value>1</value>
</param>
<param>
<key>ok_to_block</key>
<value>True</value>
</param>
<param>
<key>samp_rate</key>
<value>int(samp_rate)</value>
</param>
</block>
<block>
<key>blocks_deinterleave</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>blocksize</key>
<value>1</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(656, 113)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_deinterleave_0</value>
</param>
<param>
<key>type</key>
<value>float</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>num_streams</key>
<value>2</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>blocks_float_to_complex</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(808, 113)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_float_to_complex_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>ha5kfu_execproc_xx</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>commandline</key>
<value>csdr dsb_fc | csdr shift_addition_cc $(csdr =-2000/48e3) | csdr fir_decimate_cc 48 </value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(384, 123)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>ha5kfu_execproc_xx_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>type</key>
<value>ff</value>
</param>
</block>
<block>
<key>ha5kfu_execproc_xx</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>commandline</key>
<value>csdr resonators_fir_cc 31 $(csdr =85/1e3) $(csdr =-85/1e3) | CSDR_FIXED_BUFSIZE=128 csdr simple_agc_cc 0.0001 0.5</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(752, 275)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>ha5kfu_execproc_xx_0_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>type</key>
<value>cc</value>
</param>
</block>
<block>
<key>notebook</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(400, 40)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>nb</value>
</param>
<param>
<key>labels</key>
<value>['input signal', 'decimated', 'filtered', 'tab4']</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>style</key>
<value>wx.NB_TOP</value>
</param>
</block>
<block>
<key>wxgui_fftsink2</key>
<param>
<key>avg_alpha</key>
<value>0</value>
</param>
<param>
<key>average</key>
<value>False</value>
</param>
<param>
<key>baseband_freq</key>
<value>0</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>fft_size</key>
<value>1024</value>
</param>
<param>
<key>freqvar</key>
<value>None</value>
</param>
<param>
<key>_coordinate</key>
<value>(1048, 251)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_fftsink2_0</value>
</param>
<param>
<key>notebook</key>
<value>nb, 2</value>
</param>
<param>
<key>peak_hold</key>
<value>False</value>
</param>
<param>
<key>ref_level</key>
<value>0</value>
</param>
<param>
<key>ref_scale</key>
<value>2.0</value>
</param>
<param>
<key>fft_rate</key>
<value>15</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate/48</value>
</param>
<param>
<key>title</key>
<value>FFT Plot</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>win</key>
<value>None</value>
</param>
<param>
<key>y_divs</key>
<value>10</value>
</param>
<param>
<key>y_per_div</key>
<value>10</value>
</param>
</block>
<block>
<key>wxgui_fftsink2</key>
<param>
<key>avg_alpha</key>
<value>0</value>
</param>
<param>
<key>average</key>
<value>False</value>
</param>
<param>
<key>baseband_freq</key>
<value>0</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>fft_size</key>
<value>1024</value>
</param>
<param>
<key>freqvar</key>
<value>None</value>
</param>
<param>
<key>_coordinate</key>
<value>(280, 227)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_fftsink2_0_0</value>
</param>
<param>
<key>notebook</key>
<value>nb, 0</value>
</param>
<param>
<key>peak_hold</key>
<value>False</value>
</param>
<param>
<key>ref_level</key>
<value>0</value>
</param>
<param>
<key>ref_scale</key>
<value>2.0</value>
</param>
<param>
<key>fft_rate</key>
<value>15</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>title</key>
<value>Input signal</value>
</param>
<param>
<key>type</key>
<value>float</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>win</key>
<value>None</value>
</param>
<param>
<key>y_divs</key>
<value>10</value>
</param>
<param>
<key>y_per_div</key>
<value>10</value>
</param>
</block>
<block>
<key>wxgui_fftsink2</key>
<param>
<key>avg_alpha</key>
<value>0</value>
</param>
<param>
<key>average</key>
<value>False</value>
</param>
<param>
<key>baseband_freq</key>
<value>0</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>fft_size</key>
<value>1024</value>
</param>
<param>
<key>freqvar</key>
<value>None</value>
</param>
<param>
<key>_coordinate</key>
<value>(1048, 11)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_fftsink2_0_1</value>
</param>
<param>
<key>notebook</key>
<value>nb, 1</value>
</param>
<param>
<key>peak_hold</key>
<value>False</value>
</param>
<param>
<key>ref_level</key>
<value>0</value>
</param>
<param>
<key>ref_scale</key>
<value>2.0</value>
</param>
<param>
<key>fft_rate</key>
<value>15</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate/48</value>
</param>
<param>
<key>title</key>
<value>FFT Plot</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>win</key>
<value>None</value>
</param>
<param>
<key>y_divs</key>
<value>10</value>
</param>
<param>
<key>y_per_div</key>
<value>10</value>
</param>
</block>
<connection>
<source_block_id>audio_source_0</source_block_id>
<sink_block_id>ha5kfu_execproc_xx_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>audio_source_0</source_block_id>
<sink_block_id>wxgui_fftsink2_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_deinterleave_0</source_block_id>
<sink_block_id>blocks_float_to_complex_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_deinterleave_0</source_block_id>
<sink_block_id>blocks_float_to_complex_0</sink_block_id>
<source_key>1</source_key>
<sink_key>1</sink_key>
</connection>
<connection>
<source_block_id>blocks_float_to_complex_0</source_block_id>
<sink_block_id>ha5kfu_execproc_xx_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_float_to_complex_0</source_block_id>
<sink_block_id>wxgui_fftsink2_0_1</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>ha5kfu_execproc_xx_0</source_block_id>
<sink_block_id>blocks_deinterleave_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>ha5kfu_execproc_xx_0_0</source_block_id>
<sink_block_id>wxgui_fftsink2_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
</flow_graph>

View file

@ -1,844 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<?grc format='1' created='3.7.8'?>
<flow_graph>
<timestamp>Sun Nov 16 15:12:31 2014</timestamp>
<block>
<key>options</key>
<param>
<key>author</key>
<value></value>
</param>
<param>
<key>window_size</key>
<value>1280, 1024</value>
</param>
<param>
<key>category</key>
<value>Custom</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>description</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(10, 10)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>generate_options</key>
<value>wx_gui</value>
</param>
<param>
<key>id</key>
<value>top_block</value>
</param>
<param>
<key>max_nouts</key>
<value>0</value>
</param>
<param>
<key>realtime_scheduling</key>
<value></value>
</param>
<param>
<key>run_options</key>
<value>prompt</value>
</param>
<param>
<key>run</key>
<value>True</value>
</param>
<param>
<key>thread_safe_setters</key>
<value></value>
</param>
<param>
<key>title</key>
<value></value>
</param>
</block>
<block>
<key>variable</key>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(10, 170)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>samp_rate</value>
</param>
<param>
<key>value</key>
<value>48000</value>
</param>
</block>
<block>
<key>analog_agc_xx</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>0</value>
</param>
<param>
<key>_coordinate</key>
<value>(432, 355)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>gain</key>
<value>1</value>
</param>
<param>
<key>id</key>
<value>analog_agc_xx_0</value>
</param>
<param>
<key>max_gain</key>
<value>65536</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>rate</key>
<value>1e-2</value>
</param>
<param>
<key>reference</key>
<value>0.1</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
</block>
<block>
<key>audio_sink</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>device_name</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(1152, 427)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>audio_sink_0</value>
</param>
<param>
<key>num_inputs</key>
<value>1</value>
</param>
<param>
<key>ok_to_block</key>
<value>True</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
</block>
<block>
<key>band_reject_filter</key>
<param>
<key>beta</key>
<value>6.76</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>decim</key>
<value>1</value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>type</key>
<value>fir_filter_fff</value>
</param>
<param>
<key>_coordinate</key>
<value>(392, 35)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>gain</key>
<value>1</value>
</param>
<param>
<key>high_cutoff_freq</key>
<value>2000</value>
</param>
<param>
<key>id</key>
<value>band_reject_filter_0</value>
</param>
<param>
<key>interp</key>
<value>1</value>
</param>
<param>
<key>low_cutoff_freq</key>
<value>1600</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>width</key>
<value>50</value>
</param>
<param>
<key>win</key>
<value>firdes.WIN_HAMMING</value>
</param>
</block>
<block>
<key>blocks_complex_to_float</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(928, 289)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_complex_to_float_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>blocks_multiply_const_vxx</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>const</key>
<value>0.2</value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(968, 427)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_multiply_const_vxx_0</value>
</param>
<param>
<key>type</key>
<value>float</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>blocks_wavfile_source</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>file</key>
<value>/home/pcfl/Asztal/szakdoga/dipterv1/csdr-varicode/grc_tests/outfile.wav</value>
</param>
<param>
<key>_coordinate</key>
<value>(152, 163)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_wavfile_source_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>nchan</key>
<value>1</value>
</param>
<param>
<key>repeat</key>
<value>True</value>
</param>
</block>
<block>
<key>freq_xlating_fir_filter_xxx</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>center_freq</key>
<value>2000</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>decim</key>
<value>1</value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(832, 75)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>freq_xlating_fir_filter_xxx_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>taps</key>
<value>[1]</value>
</param>
<param>
<key>type</key>
<value>fcc</value>
</param>
</block>
<block>
<key>freq_xlating_fir_filter_xxx</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>center_freq</key>
<value>-2000</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>decim</key>
<value>1</value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(696, 275)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>freq_xlating_fir_filter_xxx_0_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>taps</key>
<value>[1]</value>
</param>
<param>
<key>type</key>
<value>ccc</value>
</param>
</block>
<block>
<key>ha5kfu_execproc_xx</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>commandline</key>
<value>csdr simple_agc_cc 0.001 0.05</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>1</value>
</param>
<param>
<key>_coordinate</key>
<value>(384, 291)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>ha5kfu_execproc_xx_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>type</key>
<value>cc</value>
</param>
</block>
<block>
<key>low_pass_filter</key>
<param>
<key>beta</key>
<value>6.76</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>cutoff_freq</key>
<value>3000</value>
</param>
<param>
<key>decim</key>
<value>1</value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>type</key>
<value>fir_filter_fff</value>
</param>
<param>
<key>_coordinate</key>
<value>(584, 43)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>gain</key>
<value>1</value>
</param>
<param>
<key>id</key>
<value>low_pass_filter_0</value>
</param>
<param>
<key>interp</key>
<value>1</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>width</key>
<value>50</value>
</param>
<param>
<key>win</key>
<value>firdes.WIN_HAMMING</value>
</param>
</block>
<block>
<key>wxgui_fftsink2</key>
<param>
<key>avg_alpha</key>
<value>0</value>
</param>
<param>
<key>average</key>
<value>False</value>
</param>
<param>
<key>baseband_freq</key>
<value>0</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>fft_size</key>
<value>1024</value>
</param>
<param>
<key>freqvar</key>
<value>None</value>
</param>
<param>
<key>_coordinate</key>
<value>(688, 403)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>id</key>
<value>wxgui_fftsink2_0</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>peak_hold</key>
<value>False</value>
</param>
<param>
<key>ref_level</key>
<value>0</value>
</param>
<param>
<key>ref_scale</key>
<value>2.0</value>
</param>
<param>
<key>fft_rate</key>
<value>15</value>
</param>
<param>
<key>samp_rate</key>
<value>samp_rate</value>
</param>
<param>
<key>title</key>
<value>FFT Plot</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>win_size</key>
<value></value>
</param>
<param>
<key>win</key>
<value>None</value>
</param>
<param>
<key>y_divs</key>
<value>10</value>
</param>
<param>
<key>y_per_div</key>
<value>10</value>
</param>
</block>
<connection>
<source_block_id>analog_agc_xx_0</source_block_id>
<sink_block_id>freq_xlating_fir_filter_xxx_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>analog_agc_xx_0</source_block_id>
<sink_block_id>wxgui_fftsink2_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>band_reject_filter_0</source_block_id>
<sink_block_id>low_pass_filter_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_complex_to_float_0</source_block_id>
<sink_block_id>blocks_multiply_const_vxx_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_multiply_const_vxx_0</source_block_id>
<sink_block_id>audio_sink_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_wavfile_source_0</source_block_id>
<sink_block_id>band_reject_filter_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>freq_xlating_fir_filter_xxx_0</source_block_id>
<sink_block_id>analog_agc_xx_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>freq_xlating_fir_filter_xxx_0</source_block_id>
<sink_block_id>ha5kfu_execproc_xx_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>freq_xlating_fir_filter_xxx_0_0</source_block_id>
<sink_block_id>blocks_complex_to_float_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>ha5kfu_execproc_xx_0</source_block_id>
<sink_block_id>freq_xlating_fir_filter_xxx_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>ha5kfu_execproc_xx_0</source_block_id>
<sink_block_id>wxgui_fftsink2_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>low_pass_filter_0</source_block_id>
<sink_block_id>freq_xlating_fir_filter_xxx_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
</flow_graph>

2925
libcsdr.c Executable file → Normal file

File diff suppressed because it is too large Load diff

295
libcsdr.h
View file

@ -1,5 +1,5 @@
/*
This software is part of libcsdr, a set of simple DSP routines for
This software is part of libcsdr, a set of simple DSP routines for
Software Defined Radio.
Copyright (c) 2014, Andras Retzler <randras@sdr.hu>
@ -30,17 +30,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#define MIN_M(x,y) (((x)>(y))?(y):(x))
#define MAX_M(x,y) (((x)<(y))?(y):(x))
/*
_____ _
/ ____| | |
| | ___ _ __ ___ _ __ | | _____ __
| | / _ \| '_ ` _ \| '_ \| |/ _ \ \/ /
| |___| (_) | | | | | | |_) | | __/> <
\_____\___/|_| |_| |_| .__/|_|\___/_/\_\
| |
|_|
_____ _
/ ____| | |
| | ___ _ __ ___ _ __ | | _____ __
| | / _ \| '_ ` _ \| '_ \| |/ _ \ \/ /
| |___| (_) | | | | | | |_) | | __/> <
\_____\___/|_| |_| |_| .__/|_|\___/_/\_\
| |
|_|
*/
typedef struct complexf_s { float i; float q; } complexf;
@ -48,9 +47,9 @@ typedef struct complexf_s { float i; float q; } complexf;
//apply to pointers:
#define iof(complexf_input_p,i) (*(((float*)complexf_input_p)+2*(i)))
#define qof(complexf_input_p,i) (*(((float*)complexf_input_p)+2*(i)+1))
#define absof(complexf_input_p,i) (sqrt((iof(complexf_input_p,i)*iof(complexf_input_p,i))+(qof(complexf_input_p,i)*qof(complexf_input_p,i))))
#define absof(complexf_input_p,i) (sqrt(iof(complexf_input_p,i)*iof(complexf_input_p,i)+qof(complexf_input_p,i)*qof(complexf_input_p,i)))
#define argof(complexf_input_p,i) (atan2(qof(complexf_input_p,i),iof(complexf_input_p,i)))
#define cmult(cfo, cfi1, cfi2) {iof(cfo,0)=iof(cfi1,0)*iof(cfi2,0)-qof(cfi1,0)*qof(cfi2,0);qof(cfo,0)=iof(cfi1,0)*qof(cfi2,0)+iof(cfi2,0)*qof(cfi1,0);}
#define cmult(cfo, cfi1, cfi2) iof(cfo,0)=iof(cfi1,0)*iof(cfi2,0)-qof(cfi1,0)*qof(cfi2,0);qof(cfo,0)=iof(cfi1,0)*qof(cfi2,0)+iof(cfi2,0)*qof(cfi1,0)
//(ai+aq*j)*(bi+bq*j)=ai*bi-aq*bq+(aq*bi+ai*bq)*j
#define cmultadd(cfo, cfi1, cfi2) { iof(cfo,0)+=iof(cfi1,0)*iof(cfi2,0)-qof(cfi1,0)*qof(cfi2,0);qof(cfo,0)+=iof(cfi1,0)*qof(cfi2,0)+iof(cfi2,0)*qof(cfi1,0); }
#define csetnull(cf) { iof(cf,0)=0.0; qof(cf,0)=0.0; }
@ -67,9 +66,9 @@ typedef struct complexf_s { float i; float q; } complexf;
#define TIME_TAKEN(start,end) ((end.tv_sec-start.tv_sec)+(end.tv_nsec-start.tv_nsec)/1e9)
//window
typedef enum window_s
typedef enum window_s
{
WINDOW_BOXCAR, WINDOW_BLACKMAN, WINDOW_HAMMING
WINDOW_BOXCAR, WINDOW_BLACKMAN, WINDOW_HAMMING
} window_t;
#define WINDOW_DEFAULT WINDOW_HAMMING
@ -102,85 +101,58 @@ void limit_ff(float* input, float* output, int input_size, float max_amplitude);
//filters, decimators, resamplers, shift, etc.
float fir_one_pass_ff(float* input, float* taps, int taps_length);
int fir_decimate_cc(complexf *input, complexf *output, int input_size, int decimation, float *taps, int taps_length);
int fir_interpolate_cc(complexf *input, complexf *output, int input_size, int interpolation, float *taps, int taps_length);
int deemphasis_nfm_ff (float* input, float* output, int input_size, int sample_rate);
float deemphasis_wfm_ff (float* input, float* output, int input_size, float tau, int sample_rate, float last_output);
float shift_math_cc(complexf *input, complexf* output, int input_size, float rate, float starting_phase);
typedef struct dcblock_preserve_s
{
float last_input;
float last_output;
float last_input;
float last_output;
} dcblock_preserve_t;
dcblock_preserve_t dcblock_ff(float* input, float* output, int input_size, float a, dcblock_preserve_t preserved);
float fastdcblock_ff(float* input, float* output, int input_size, float last_dc_level);
typedef struct fastagc_ff_s
{
float* buffer_1;
float* buffer_2;
float* buffer_input; //it is the actual input buffer to fill
float peak_1;
float peak_2;
int input_size;
float reference;
float last_gain;
float* buffer_1;
float* buffer_2;
float* buffer_input; //it is the actual input buffer to fill
float peak_1;
float peak_2;
int input_size;
float reference;
float last_gain;
} fastagc_ff_t;
void fastagc_ff(fastagc_ff_t* input, float* output);
typedef struct rational_resampler_ff_s
{
int input_processed;
int output_size;
int last_taps_delay;
int input_processed;
int output_size;
int last_taps_delay;
} rational_resampler_ff_t;
rational_resampler_ff_t rational_resampler_ff(float *input, float *output, int input_size, int interpolation, int decimation, float *taps, int taps_length, int last_taps_delay);
void rational_resampler_get_lowpass_f(float* output, int output_size, int interpolation, int decimation, window_t window);
float *precalculate_window(int size, window_t window);
void apply_window_c(complexf* input, complexf* output, int size, window_t window);
void apply_precalculated_window_c(complexf* input, complexf* output, int size, float *windowt);
void apply_precalculated_window_f(float* input, float* output, int size, float *windowt);
void apply_window_f(float* input, float* output, int size, window_t window);
void logpower_cf(complexf* input, float* output, int size, float add_db);
void accumulate_power_cf(complexf* input, float* output, int size);
void log_ff(float* input, float* output, int size, float add_db);
typedef struct fractional_decimator_ff_s
{
float where;
int input_processed;
int output_size;
int num_poly_points; //number of samples that the Lagrange interpolator will use
float* poly_precalc_denomiator; //while we don't precalculate coefficients here as in a Farrow structure, because it is a fractional interpolator, but we rather precaculate part of the interpolator expression
//float* last_inputs_circbuf; //circular buffer to store the last (num_poly_points) number of input samples.
//int last_inputs_startsat; //where the circular buffer starts now
//int last_inputs_samplewhere;
float* coeffs_buf;
float* filtered_buf;
int xifirst;
int xilast;
float rate;
float *taps;
int taps_length;
float remain;
int input_processed;
int output_size;
} fractional_decimator_ff_t;
fractional_decimator_ff_t fractional_decimator_ff_init(float rate, int num_poly_points, float* taps, int taps_length);
void fractional_decimator_ff(float* input, float* output, int input_size, fractional_decimator_ff_t* d);
typedef struct old_fractional_decimator_ff_s
{
float remain;
int input_processed;
int output_size;
} old_fractional_decimator_ff_t;
old_fractional_decimator_ff_t old_fractional_decimator_ff(float* input, float* output, int input_size, float rate, float *taps, int taps_length, old_fractional_decimator_ff_t d);
fractional_decimator_ff_t fractional_decimator_ff(float* input, float* output, int input_size, float rate, float *taps, int taps_length, fractional_decimator_ff_t d);
typedef struct shift_table_data_s
{
float* table;
int table_size;
float* table;
int table_size;
} shift_table_data_t;
void shift_table_deinit(shift_table_data_t table_data);
shift_table_data_t shift_table_init(int table_size);
@ -188,9 +160,9 @@ float shift_table_cc(complexf* input, complexf* output, int input_size, float ra
typedef struct shift_addfast_data_s
{
float dsin[4];
float dcos[4];
float phase_increment;
float dsin[4];
float dcos[4];
float phase_increment;
} shift_addfast_data_t;
shift_addfast_data_t shift_addfast_init(float rate);
shift_addfast_data_t shift_addfast_init(float rate);
@ -198,10 +170,10 @@ float shift_addfast_cc(complexf *input, complexf* output, int input_size, shift_
typedef struct shift_unroll_data_s
{
float* dsin;
float* dcos;
float phase_increment;
int size;
float* dsin;
float* dcos;
float phase_increment;
int size;
} shift_unroll_data_t;
float shift_unroll_cc(complexf *input, complexf* output, int input_size, shift_unroll_data_t* d, float starting_phase);
shift_unroll_data_t shift_unroll_init(float rate, int size);
@ -210,8 +182,6 @@ int log2n(int x);
int next_pow2(int x);
void apply_fir_fft_cc(FFT_PLAN_T* plan, FFT_PLAN_T* plan_inverse, complexf* taps_fft, complexf* last_overlap, int overlap_size);
void gain_ff(float* input, float* output, int input_size, float gain);
float get_power_f(float* input, int input_size, int decimation);
float get_power_c(complexf* input, int input_size, int decimation);
void add_dcoffset_cc(complexf* input, complexf* output, int input_size);
float fmmod_fc(float* input, complexf* output, int input_size, float last_phase);
@ -219,194 +189,7 @@ void fixed_amplitude_cc(complexf* input, complexf* output, int input_size, float
void convert_u8_f(unsigned char* input, float* output, int input_size);
void convert_f_u8(float* input, unsigned char* output, int input_size);
void convert_s8_f(signed char* input, float* output, int input_size);
void convert_f_s8(float* input, signed char* output, int input_size);
void convert_f_s16(float* input, short* output, int input_size);
void convert_s16_f(short* input, float* output, int input_size);
void convert_f_i16(float* input, short* output, int input_size);
void convert_i16_f(short* input, float* output, int input_size);
void convert_f_s24(float* input, unsigned char* output, int input_size, int bigendian);
void convert_s24_f(unsigned char* input, float* output, int input_size, int bigendian);
int is_nan(float f);
//digital demod
typedef struct rtty_baudot_item_s
{
unsigned long long code;
unsigned char ascii_letter;
unsigned char ascii_figure;
} rtty_baudot_item_t;
typedef enum rtty_baudot_decoder_state_e
{
RTTY_BAUDOT_WAITING_STOP_PULSE = 0,
RTTY_BAUDOT_WAITING_START_PULSE,
RTTY_BAUDOT_RECEIVING_DATA
} rtty_baudot_decoder_state_t;
typedef struct rtty_baudot_decoder_s
{
unsigned char fig_mode;
unsigned char character_received;
unsigned short shr;
unsigned char bit_cntr;
rtty_baudot_decoder_state_t state;
} rtty_baudot_decoder_t;
#define RTTY_FIGURE_MODE_SELECT_CODE 0b11011
#define RTTY_LETTER_MODE_SELECT_CODE 0b11111
char rtty_baudot_decoder_lookup(unsigned char* fig_mode, unsigned char c);
char rtty_baudot_decoder_push(rtty_baudot_decoder_t* s, unsigned char symbol);
//PSK31
typedef struct psk31_varicode_item_s
{
unsigned long long code;
int bitcount;
unsigned char ascii;
} psk31_varicode_item_t;
char psk31_varicode_decoder_push(unsigned long long* status_shr, unsigned char symbol);
//Serial
typedef struct serial_line_s
{
float samples_per_bits;
int databits; //including parity
float stopbits;
int output_size;
int input_used;
float bit_sampling_width_ratio;
} serial_line_t;
void serial_line_decoder_f_u8(serial_line_t* s, float* input, unsigned char* output, int input_size);
void binary_slicer_f_u8(float* input, unsigned char* output, int input_size);
typedef enum pll_type_e
{
PLL_P_CONTROLLER=1,
PLL_PI_CONTROLLER=2
} pll_type_t;
typedef struct pll_s
{
pll_type_t pll_type;
//common:
float output_phase;
float dphase;
float frequency;
float alpha;
float beta;
float iir_temp;
} pll_t;
void pll_cc_init_pi_controller(pll_t* p, float bandwidth, float ko, float kd, float damping_factor);
void pll_cc_init_p_controller(pll_t* p, float alpha);
void pll_cc(pll_t* p, complexf* input, float* output_dphase, complexf* output_nco, int input_size);
typedef enum timing_recovery_algorithm_e
{
TIMING_RECOVERY_ALGORITHM_GARDNER,
TIMING_RECOVERY_ALGORITHM_EARLYLATE
} timing_recovery_algorithm_t;
#define TIMING_RECOVERY_ALGORITHM_DEFAULT TIMING_RECOVERY_ALGORITHM_GARDNER
typedef struct timing_recovery_state_s
{
timing_recovery_algorithm_t algorithm;
int decimation_rate; // = input_rate / output_rate. We should get an input signal that is N times oversampled.
int output_size;
int input_processed;
int use_q; //use both I and Q for calculating the error
int debug_phase;
int debug_every_nth;
char* debug_writefiles_path;
int last_correction_offset;
float earlylate_ratio;
float loop_gain;
float max_error;
} timing_recovery_state_t;
timing_recovery_state_t timing_recovery_init(timing_recovery_algorithm_t algorithm, int decimation_rate, int use_q, float loop_gain, float max_error, int debug_every_nth, char* debug_writefiles_path);
void timing_recovery_cc(complexf* input, complexf* output, int input_size, float* timing_error, int* sampled_indexes, timing_recovery_state_t* state);
timing_recovery_algorithm_t timing_recovery_get_algorithm_from_string(char* input);
char* timing_recovery_get_string_from_algorithm(timing_recovery_algorithm_t algorithm);
void octave_plot_point_on_cplxsig(complexf* signal, int signal_size, float error, int index, int correction_offset, char* writefiles_path, int points_size, ...);
void psk_modulator_u8_c(unsigned char* input, complexf* output, int input_size, int n_psk);
void duplicate_samples_ntimes_u8_u8(unsigned char* input, unsigned char* output, int input_size_bytes, int sample_size_bytes, int ntimes);
complexf psk31_interpolate_sine_cc(complexf* input, complexf* output, int input_size, int interpolation, complexf last_input);
void psk31_varicode_encoder_u8_u8(unsigned char* input, unsigned char* output, int input_size, int output_max_size, int* input_processed, int* output_size);
unsigned char differential_codec(unsigned char* input, unsigned char* output, int input_size, int encode, unsigned char state);
#if 0
typedef struct bpsk_costas_loop_state_s
{
float rc_filter_alpha;
float vco_phase_addition_multiplier;
float vco_phase;
float last_lpfi_output;
float last_lpfq_output;
float last_vco_phase_addition;
} bpsk_costas_loop_state_t;
bpsk_costas_loop_state_t init_bpsk_costas_loop_cc(float samples_per_bits);
void bpsk_costas_loop_cc(complexf* input, complexf* output, int input_size, bpsk_costas_loop_state_t* state);
#endif
typedef struct bpsk_costas_loop_state_s
{
float alpha;
float beta;
int decision_directed;
float current_freq;
float dphase;
float nco_phase;
float dphase_max;
int dphase_max_reset_to_zero;
} bpsk_costas_loop_state_t;
void plain_interpolate_cc(complexf* input, complexf* output, int input_size, int interpolation);
void bpsk_costas_loop_cc(complexf* input, complexf* output, int input_size, float* output_error, float* output_dphase, complexf* output_nco, bpsk_costas_loop_state_t* s);
void init_bpsk_costas_loop_cc(bpsk_costas_loop_state_t* s, int decision_directed, float damping_factor, float bandwidth);
void simple_agc_cc(complexf* input, complexf* output, int input_size, float rate, float reference, float max_gain, float* current_gain);
void firdes_add_peak_c(complexf* output, int length, float rate, window_t window, int add, int normalize);
int apply_fir_cc(complexf* input, complexf* output, int input_size, complexf* taps, int taps_length);
FILE* init_get_random_samples_f();
void get_random_samples_f(float* output, int output_size, FILE* status);
void get_random_gaussian_samples_c(complexf* output, int output_size, FILE* status);
int deinit_get_random_samples_f(FILE* status);
float* add_ff(float* input1, float* input2, float* output, int input_size);
float total_logpower_cf(complexf* input, int input_size);
float normalized_timing_variance_u32_f(unsigned* input, float* temp, int input_size, int samples_per_symbol, int initial_sample_offset, int debug_print);
typedef enum matched_filter_type_e
{
MATCHED_FILTER_RRC,
MATCHED_FILTER_COSINE
} matched_filter_type_t;
#define MATCHED_FILTER_DEFAULT MATCHED_FILTER_RRC
int firdes_cosine_f(float* taps, int taps_length, int samples_per_symbol);
int firdes_rrc_f(float* taps, int taps_length, int samples_per_symbol, float beta);
matched_filter_type_t matched_filter_get_type_from_string(char* input);
int apply_real_fir_cc(complexf* input, complexf* output, int input_size, float* taps, int taps_length);
void generic_slicer_f_u8(float* input, unsigned char* output, int input_size, int n_symbols);
void plain_interpolate_cc(complexf* input, complexf* output, int input_size, int interpolation);;
void normalize_fir_f(float* input, float* output, int length);
float* add_const_cc(complexf* input, complexf* output, int input_size, complexf x);
void pack_bits_1to8_u8_u8(unsigned char* input, unsigned char* output, int input_size);
unsigned char pack_bits_8to1_u8_u8(unsigned char* input);
void dbpsk_decoder_c_u8(complexf* input, unsigned char* output, int input_size);
int bfsk_demod_cf(complexf* input, float* output, int input_size, complexf* mark_filter, complexf* space_filter, int taps_length);

View file

@ -47,34 +47,7 @@ float shift_addition_cc(complexf *input, complexf* output, int input_size, shift
}
starting_phase+=d.rate*PI*input_size;
while(starting_phase>PI) starting_phase-=2*PI; //@shift_addition_cc: normalize starting_phase
while(starting_phase<-PI) starting_phase+=2*PI;
return starting_phase;
}
float shift_addition_fc(float *input, complexf* output, int input_size, shift_addition_data_t d, float starting_phase)
{
//The original idea was taken from wdsp:
//http://svn.tapr.org/repos_sdr_hpsdr/trunk/W5WC/PowerSDR_HPSDR_mRX_PS/Source/wdsp/shift.c
//However, this method introduces noise (from floating point rounding errors), which increases until the end of the buffer.
//fprintf(stderr, "cosd=%g sind=%g\n", d.cosdelta, d.sindelta);
float cosphi=cos(starting_phase);
float sinphi=sin(starting_phase);
float cosphi_last, sinphi_last;
for(int i=0;i<input_size;i++) //@shift_addition_cc: work
{
iof(output,i)=cosphi*input[i];
qof(output,i)=sinphi*input[i];
//using the trigonometric addition formulas
//cos(phi+delta)=cos(phi)cos(delta)-sin(phi)*sin(delta)
cosphi_last=cosphi;
sinphi_last=sinphi;
cosphi=cosphi_last*d.cosdelta-sinphi_last*d.sindelta;
sinphi=sinphi_last*d.cosdelta+cosphi_last*d.sindelta;
}
starting_phase+=d.rate*PI*input_size;
while(starting_phase>PI) starting_phase-=2*PI; //@shift_addition_cc: normalize starting_phase
while(starting_phase<-PI) starting_phase+=2*PI;
while(starting_phase<-PI) starting_phase+=2*PI;
return starting_phase;
}
@ -109,12 +82,12 @@ void shift_addition_cc_test(shift_addition_data_t d)
sinphi=sinphi_last*d.cosdelta+cosphi_last*d.sindelta;
phi+=d.rate*PI;
while(phi>2*PI) phi-=2*PI; //@shift_addition_cc: normalize phase
if(i%SACCTEST_STEP==0)
if(i%SACCTEST_STEP==0)
{
avg_counter=avg_size;
avg=0;
}
if(avg_counter)
if(avg_counter)
{
avg+=fabs(cosphi-cos(phi));
if(!--avg_counter) printf("%g ", avg/avg_size);
@ -155,7 +128,7 @@ decimating_shift_addition_status_t decimating_shift_addition_cc(complexf *input,
s.starting_phase+=d.rate*PI*k;
s.output_size=k;
while(s.starting_phase>PI) s.starting_phase-=2*PI; //@shift_addition_cc: normalize starting_phase
while(s.starting_phase<-PI) s.starting_phase+=2*PI;
while(s.starting_phase<-PI) s.starting_phase+=2*PI;
return s;
}
@ -169,10 +142,10 @@ float agc_ff(float* input, float* output, int input_size, float reference, float
hang_time = (hang_time_ms / 1000) * sample_rate
hang_time is given in samples, and should be about 4ms.
hang_time can be switched off by setting it to zero (not recommended).
max_gain = pow(2, adc_bits)
max_gain should be no more than the dynamic range of your A/D converter.
gain_filter_alpha = 1 / ((fs/(2*PI*fc))+1)
max_gain should be no more than the dynamic range of your A/D converter.
gain_filter_alpha = 1 / ((fs/(2*PI*fc))+1)
>>> 1 / ((48000./(2*3.141592654*100))+1)
0.012920836043344543
@ -180,7 +153,7 @@ float agc_ff(float* input, float* output, int input_size, float reference, float
0.0013072857061786625
Literature:
Literature:
ww.qsl.net/va3iul/Files/Automatic_Gain_Control.pdf
page 7 of http://www.arrl.org/files/file/Technology/tis/info/pdf/021112qex027.pdf
@ -197,10 +170,10 @@ float agc_ff(float* input, float* output, int input_size, float reference, float
output[0]=last_gain*input[0]; //we skip this one sample, because it is easier this way
for(int i=1;i<input_size;i++) //@agc_ff
{
//The error is the difference between the required gain at the actual sample, and the previous gain value.
//The error is the difference between the required gain at the actual sample, and the previous gain value.
//We actually use an envelope detector.
input_abs=fabs(input[i]);
error=reference/input_abs-gain;
error=reference/input_abs-gain;
if(input[i]!=0) //We skip samples containing 0, as the gain would be infinity for those to keep up with the reference.
{
@ -211,12 +184,12 @@ float agc_ff(float* input, float* output, int input_size, float reference, float
//However, attack_rate should be higher than the decay_rate as we want to avoid clipping signals.
//that had a sudden increase in their amplitude.
//It's also important to note that this algorithm has an exponential gain ramp.
if(error<0) //INCREASE IN SIGNAL LEVEL
{
if(last_peak<input_abs)
if(last_peak<input_abs)
{
attack_wait_counter=attack_wait_time;
last_peak=input_abs;
}
@ -228,11 +201,11 @@ float agc_ff(float* input, float* output, int input_size, float reference, float
}
else
{
//If the signal level increases, we decrease the gain quite fast.
dgain=error*attack_rate;
//If the signal level increases, we decrease the gain quite fast.
dgain=error*attack_rate;
//Before starting to increase the gain next time, we will be waiting until hang_time for sure.
hang_counter=hang_time;
}
}
else //DECREASE IN SIGNAL LEVEL
@ -243,12 +216,13 @@ float agc_ff(float* input, float* output, int input_size, float reference, float
dgain=0; //..until then, AGC is inactive and gain doesn't change.
}
else dgain=error*decay_rate; //If the signal level decreases, we increase the gain quite slowly.
}
}
gain=gain+dgain;
//fprintf(stderr,"g=%f dg=%f\n",gain,dgain);
if(gain>max_gain) gain=max_gain; //We also have to limit our gain, it can't be infinity.
if(gain<0) gain=0;
}
if(gain>max_gain) gain=max_gain; //We also have to limit our gain, it can't be infinity.
if(gain<0) gain=0;
//output[i]=gain*input[i]; //Here we do the actual scaling of the samples.
//Here we do the actual scaling of the samples, but we run an IIR filter on the gain values:
output[i]=(gain=gain+last_gain-gain_filter_alpha*last_gain)*input[i]; //dc-pass-filter: freqz([1 -1],[1 -0.99]) y[i]=x[i]+y[i-1]-alpha*x[i-1]
@ -256,7 +230,8 @@ float agc_ff(float* input, float* output, int input_size, float reference, float
last_gain=gain;
}
return gain; //this will be the last_gain next time
return gain; //this will be the last_gain next time
}
#endif

View file

@ -31,7 +31,6 @@ typedef struct shift_addition_data_s
} shift_addition_data_t;
shift_addition_data_t shift_addition_init(float rate);
float shift_addition_cc(complexf *input, complexf* output, int input_size, shift_addition_data_t d, float starting_phase);
float shift_addition_fc(float *input, complexf* output, int input_size, shift_addition_data_t d, float starting_phase);
void shift_addition_cc_test(shift_addition_data_t d);
float agc_ff(float* input, float* output, int input_size, float reference, float attack_rate, float decay_rate, float max_gain, short hang_time, short attack_wait_time, float gain_filter_alpha, float last_gain);

380
nmux.cpp
View file

@ -1,380 +0,0 @@
/*
This software is part of libcsdr, a set of simple DSP routines for
Software Defined Radio.
Copyright (c) 2014, Andras Retzler <randras@sdr.hu>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ANDRAS RETZLER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "nmux.h"
char help_text[]="nmux is a TCP stream multiplexer. It reads data from the standard input, and sends it to each client connected through TCP sockets. Available command line options are:\n"
"\t--port (-p), --address (-a): TCP port and address to listen.\n"
"\t--bufsize (-b), --bufcnt (-n): Internal buffer size and count.\n"
"\t--help (-h): Show this message.\n";
int host_port = 0;
char host_address[100] = "127.0.0.1";
int thread_cntr = 0;
//CLI parameters
int bufsize = 1024;
int bufcnt = 1024;
char** global_argv;
int global_argc;
tsmpool* pool;
pthread_cond_t wait_condition;
pthread_mutex_t wait_mutex;
void sig_handler(int signo)
{
fprintf(stderr, MSG_START "signal %d caught, exiting...\n", signo);
fflush(stderr);
exit(0);
}
int main(int argc, char* argv[])
{
global_argv = argv;
global_argc = argc;
int c;
int no_options = 1;
for(;;)
{
int option_index = 0;
static struct option long_options[] = {
{"port", required_argument, 0, 'p' },
{"address", required_argument, 0, 'a' },
{"bufsize", required_argument, 0, 'b' },
{"bufcnt", required_argument, 0, 'n' },
{"help", no_argument, 0, 'h' },
{0, 0, 0, 0 }
};
c = getopt_long(argc, argv, "p:a:b:n:h", long_options, &option_index);
if(c==-1) break;
no_options = 0;
switch (c)
{
case 'a':
host_address[100-1]=0;
strncpy(host_address,optarg,100-1);
break;
case 'p':
host_port=atoi(optarg);
break;
case 'b':
bufsize=atoi(optarg);
break;
case 'n':
bufcnt=atoi(optarg);
break;
case 'h':
print_exit(help_text);
break;
case 0:
case '?':
case ':':
default:
print_exit(MSG_START "error in getopt_long()\n");
}
}
if(no_options) print_exit(help_text);
if(!host_port) print_exit(MSG_START "missing required command line argument, --port.\n");
if(bufsize<=0) print_exit(MSG_START "invalid value for --bufsize (should be >0)\n");
if(bufcnt<=0) print_exit(MSG_START "invalid value for --bufcnt (should be >0)\n");
//set signals
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = sig_handler;
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGKILL, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGHUP, &sa, NULL);
struct sockaddr_in addr_host;
int listen_socket;
std::vector<client_t*> clients;
clients.reserve(100);
listen_socket=socket(AF_INET,SOCK_STREAM,0);
int sockopt = 1;
if( setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&sockopt, sizeof(sockopt)) == -1 )
error_exit(MSG_START "cannot set SO_REUSEADDR"); //the best description on SO_REUSEADDR ever: http://stackoverflow.com/a/14388707/3182453
memset(&addr_host,'0',sizeof(addr_host));
addr_host.sin_family = AF_INET;
addr_host.sin_port = htons(host_port);
addr_host.sin_addr.s_addr = INADDR_ANY;
if( (addr_host.sin_addr.s_addr=inet_addr(host_address)) == INADDR_NONE )
error_exit(MSG_START "invalid host address");
if( bind(listen_socket, (struct sockaddr*) &addr_host, sizeof(addr_host)) < 0 )
error_exit(MSG_START "cannot bind() address to the socket");
if( listen(listen_socket, 10) == -1 )
error_exit(MSG_START "cannot listen() on socket");
fprintf(stderr, MSG_START "listening on %s:%d\n", inet_ntoa(addr_host.sin_addr), host_port);
struct sockaddr_in addr_cli;
socklen_t addr_cli_len = sizeof(addr_cli);
int new_socket;
int highfd = 0;
maxfd(&highfd, listen_socket);
maxfd(&highfd, STDIN_FILENO);
fd_set select_fds;
//Set stdin and listen_socket to non-blocking
if(set_nonblocking(STDIN_FILENO) || set_nonblocking(listen_socket))
error_exit(MSG_START "cannot set_nonblocking()");
//Create tsmpool
pool = new tsmpool(bufsize, bufcnt);
if(!pool->is_ok()) print_exit(MSG_START "tsmpool failed to initialize\n");
unsigned char* current_write_buffer = (unsigned char*)pool->get_write_buffer();
int index_in_current_write_buffer = 0;
//Create wait condition: client threads waiting for input data from the main thread will be
// waiting on this condition. They will be woken up with pthread_cond_broadcast() if new
// data arrives.
if(pthread_cond_init(&wait_condition, NULL))
print_exit(MSG_START "pthread_cond_init failed"); //cond_attrs is ignored by Linux
if(pthread_mutex_init(&wait_mutex, NULL))
print_exit(MSG_START "pthread_mutex_t failed"); //cond_attrs is ignored by Linux
for(;;)
{
FD_ZERO(&select_fds);
FD_SET(listen_socket, &select_fds);
FD_SET(STDIN_FILENO, &select_fds);
if(NMUX_DEBUG) fprintf(stderr, "mainfor: selecting...");
//Let's wait until there is any new data to read, or any new connection!
int select_ret = select(highfd, &select_fds, NULL, NULL, NULL);
if(NMUX_DEBUG) fprintf(stderr, "selected.\n");
if(select_ret == -1) error_exit("mainfor select() error");
//Is there a new client connection?
if( FD_ISSET(listen_socket, &select_fds) && ((new_socket = accept(listen_socket, (struct sockaddr*)&addr_cli, &addr_cli_len)) != -1) )
{
if(NMUX_DEBUG)
{
fprintf(stderr, "\x1b[1m\x1b[33mmainfor: clients before closing: ");
for(int i=0;i<clients.size();i++) fprintf(stderr, "%p ", clients[i]);
fprintf(stderr, "\x1b[0m\n");
}
if(NMUX_DEBUG) fprintf(stderr, "mainfor: accepted (socket = %d).\n", new_socket);
//Close all finished clients
for(int i=0;i<clients.size();i++)
{
if(clients[i]->status == CS_THREAD_FINISHED)
{
if(pthread_detach(clients[i]->thread)!=0)
{
fprintf(stderr,"nmux pthread_detach failed for client %d\n", i);
continue;
}
if(NMUX_DEBUG) fprintf(stderr, "mainfor: client removed: %d\n", i);
//client destructor
pool->remove_thread(clients[i]->tsmthread);
clients.erase(clients.begin()+i);
i--;
}
}
if(NMUX_DEBUG)
{
fprintf(stderr, "\x1b[1m\x1b[33mmainfor: clients after closing: ");
for(int i=0;i<clients.size();i++) fprintf(stderr, "%p ", clients[i]);
fprintf(stderr, "\x1b[0m\n");
}
//We're the parent, let's create a new client and initialize it
client_t* new_client = new client_t;
new_client->error = 0;
memcpy(&new_client->addr, &addr_cli, sizeof(struct sockaddr_in));
new_client->socket = new_socket;
new_client->status = CS_CREATED;
new_client->tsmthread = pool->register_thread();
new_client->lpool = pool;
new_client->sleeping = 0;
if(pthread_create(&new_client->thread, NULL, client_thread, (void*)new_client)==0)
{
clients.push_back(new_client);
fprintf(stderr, MSG_START "pthread_create() done, clients now: %d\n", (int)clients.size());
}
else
{
fprintf(stderr, MSG_START "pthread_create() failed.\n");
pool->remove_thread(new_client->tsmthread);
delete new_client;
}
}
if( FD_ISSET(STDIN_FILENO, &select_fds) )
{
if(index_in_current_write_buffer >= bufsize)
{
if(NMUX_DEBUG) fprintf(stderr, "mainfor: gwbing...");
current_write_buffer = (unsigned char*)pool->get_write_buffer();
if(NMUX_DEBUG) fprintf(stderr, "gwbed.\nmainfor: cond broadcasting...");
pthread_mutex_lock(&wait_mutex);
pthread_cond_broadcast(&wait_condition);
pthread_mutex_unlock(&wait_mutex);
if(NMUX_DEBUG) fprintf(stderr, "cond broadcasted.\n");
//Shouldn't we do it after we put data in?
// No, on get_write_buffer() actually the previous buffer is getting available
// for read for threads that wait for new data (wait on global pthead mutex
// wait_condition).
index_in_current_write_buffer = 0;
}
if(NMUX_DEBUG) fprintf(stderr, "mainfor: reading...\n");
int read_ret = read(STDIN_FILENO, current_write_buffer + index_in_current_write_buffer, bufsize - index_in_current_write_buffer);
if(NMUX_DEBUG) fprintf(stderr, "read %d\n", read_ret);
if(read_ret>0)
{
index_in_current_write_buffer += read_ret;
}
else if(read_ret==0)
{
//End of input stream, close clients and exit
print_exit(MSG_START "(main thread/for) end input stream, exiting.\n");
}
else if(read_ret==-1)
{
if(errno == EAGAIN) { if(NMUX_DEBUG) fprintf(stderr, "mainfor: read EAGAIN\n"); /* seems like select would block forever, so we just read again */ }
else error_exit(MSG_START "(main thread/for) error in read(), exiting.\n");
}
}
}
}
void* client_thread (void* param)
{
fprintf(stderr, "client %p: started!\n", param);
client_t* this_client = (client_t*)param;
this_client->status = CS_THREAD_RUNNING;
int retval;
tsmpool* lpool = this_client->lpool;
if(NMUX_DEBUG) fprintf(stderr, "client %p: socket = %d!\n", param, this_client->socket);
if(NMUX_DEBUG) fprintf(stderr, "client %p: poll init...", param);
struct pollfd pollfds[1];
pollfds[0].fd = this_client->socket;
pollfds[0].events = POLLOUT;
pollfds[0].revents = 0;
if(NMUX_DEBUG) fprintf(stderr, "client poll inited.\n");
//Set this_client->socket to non-blocking
if(set_nonblocking(this_client->socket))
error_exit(MSG_START "cannot set_nonblocking() on this_client->socket");
int client_buffer_index = 0;
int client_goto_source = 0;
char* pool_read_buffer = NULL;
for(;;)
{
//Wait until there is any data to send.
// If I haven't sent all the data from my last buffer, don't wait.
// (Wait for the server process to wake me up.)
while(!pool_read_buffer || client_buffer_index >= lpool->size)
{
if(NMUX_DEBUG) fprintf(stderr, "client %p: trying to grb\n", param);
pool_read_buffer = (char*)lpool->get_read_buffer(this_client->tsmthread);
if(pool_read_buffer) { client_buffer_index = 0; break; }
if(NMUX_DEBUG) fprintf(stderr, "client %p: cond_waiting for more data\n", param);
pthread_mutex_lock(&wait_mutex);
this_client->sleeping = 1;
pthread_cond_wait(&wait_condition, &wait_mutex);
pthread_mutex_unlock(&wait_mutex);
}
//Wait for the socket to be available for write.
if(NMUX_DEBUG) fprintf(stderr, "client %p: polling for socket write...", param);
int ret = poll(pollfds, 1, -1);
if(NMUX_DEBUG) fprintf(stderr, "client polled for socket write.\n");
if(ret == 0) continue;
else if (ret == -1) { client_goto_source = 1; goto client_thread_exit; }
//Read data from global tsmpool and write it to client socket
if(NMUX_DEBUG) fprintf(stderr, "client %p: sending...", param);
ret = send(this_client->socket, pool_read_buffer + client_buffer_index, lpool->size - client_buffer_index, MSG_NOSIGNAL);
if(NMUX_DEBUG) fprintf(stderr, "client sent.\n");
if(ret == -1)
{
switch(errno)
{
case EAGAIN: break;
default: client_goto_source = 2; goto client_thread_exit;
}
}
else client_buffer_index += ret;
}
client_thread_exit:
fprintf(stderr, "client %p: CS_THREAD_FINISHED, client_goto_source = %d, errno = %d", param, client_goto_source, errno);
this_client->status = CS_THREAD_FINISHED;
pthread_exit(NULL);
return NULL;
}
int set_nonblocking(int fd)
{
int flagtmp;
if((flagtmp = fcntl(fd, F_GETFL))!=-1)
if((flagtmp = fcntl(fd, F_SETFL, flagtmp|O_NONBLOCK))!=-1)
return 0;
return 1;
}
void error_exit(const char* why)
{
perror(why); //do we need a \n at the end of (why)?
exit(1);
}
void print_exit(const char* why)
{
fprintf(stderr, "%s", why);
exit(1);
}
void maxfd(int* maxfd, int fd)
{
if(fd>=*maxfd) *maxfd=fd+1;
}

45
nmux.h
View file

@ -1,45 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "tsmpool.h"
#define MSG_START "nmux: "
#define NMUX_DEBUG 0
typedef enum client_status_e
{
CS_CREATED,
CS_THREAD_RUNNING,
CS_THREAD_FINISHED
} client_status_t;
typedef struct client_s
{
struct sockaddr_in addr;
int socket;
int error; //set to non-zero on error (data transfer failed)
pthread_t thread;
tsmthread_t* tsmthread;
client_status_t status;
//the following members are there to give access to some global variables inside the thread:
tsmpool* lpool;
int sleeping;
} client_t;
void print_exit(const char* why);
void sig_handler(int signo);
void* client_thread (void* param);
void error_exit(const char* why);
void maxfd(int* maxfd, int fd);
int set_nonblocking(int fd);

View file

@ -41,8 +41,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define T_BUFSIZE (1024*1024/4)
#define T_N (200)
#define T_TAPS (1023)
#define T_DECFACT (200)
int main()
{
@ -60,21 +58,10 @@ int main()
qof(buf_c,i)=buf_u8[2*i+1]/128.0;
}
float* taps_f = (float*)malloc(sizeof(float)*T_TAPS);
firdes_lowpass_f(taps_f, T_TAPS, 1.0f/T_DECFACT, WINDOW_DEFAULT);
struct timespec start_time, end_time;
fprintf(stderr,"Starting tests of processing %d samples...\n", T_BUFSIZE*T_N);
//fir_decimate_cc
clock_gettime(CLOCK_MONOTONIC_RAW, &start_time);
for(int i=0;i<T_N;i++) fir_decimate_cc(buf_c, outbuf_c, T_BUFSIZE, 10, taps_f, T_TAPS);
clock_gettime(CLOCK_MONOTONIC_RAW, &end_time);
fprintf(stderr,"fir_decimate_cc done in %g seconds.\n",TIME_TAKEN(start_time,end_time));
//shift_math_cc
float starting_phase = 0;

View file

@ -1,74 +0,0 @@
#include "tsmpool.h"
tsmpool::tsmpool(size_t size, int num) :
size(size),
num(num) //number of buffers of (size) to alloc
{
this->threads_cntr = 0;
this->ok = 1;
this->lowest_read_index = -1;
this->write_index = 0;
this->my_read_index = index_before(0);
if (pthread_mutex_init(&this->mutex, NULL) != 0) { this->ok = 0; return; }
for(int i=0; i<num; i++)
{
void* newptr = (void*)new char[size];
if(!newptr) { this->ok = 0; return; }
buffers.push_back(newptr);
}
}
int tsmpool::is_ok() { return this->ok; }
void* tsmpool::get_write_buffer()
{
//if(write_index==index_before(lowest_read_index)) return NULL;
pthread_mutex_lock(&this->mutex);
void* to_return = buffers[write_index];
write_index = index_next(write_index);
pthread_mutex_unlock(&this->mutex);
if(TSM_DEBUG) fprintf(stderr, "gwb: write_index = %d\n", write_index);
return to_return;
}
tsmthread_t* tsmpool::register_thread()
{
if(!ok) return NULL;
pthread_mutex_lock(&this->mutex);
tsmthread_t* thread = new tsmthread_t();
thread->read_index = index_before(write_index);
threads.push_back(thread);
pthread_mutex_unlock(&this->mutex);
return thread;
}
void tsmpool::remove_thread(tsmthread_t* thread)
{
pthread_mutex_lock(&this->mutex);
for(int i=0;i<threads.size();i++)
if(threads[i] == thread)
{
delete threads[i];
threads.erase(threads.begin()+i);
break;
}
pthread_mutex_unlock(&this->mutex);
}
void* tsmpool::get_read_buffer(tsmthread_t* thread)
{
pthread_mutex_lock(&this->mutex);
int* actual_read_index = (thread==NULL) ? &my_read_index : &thread->read_index;
if(*actual_read_index==index_before(write_index))
{
if(TSM_DEBUG) fprintf(stderr, "grb: fail,"
"read_index %d is just before write_index\n", *actual_read_index);
pthread_mutex_unlock(&this->mutex);
return NULL;
}
void* to_return = buffers[*actual_read_index];
*actual_read_index=index_next(*actual_read_index);
pthread_mutex_unlock(&this->mutex);
if(TSM_DEBUG) fprintf(stderr, "grb: read_index = %d\n", *actual_read_index);
return to_return;
}

View file

@ -1,43 +0,0 @@
//tsmpool stands for Thread-Safe Memory Pool.
//It implements a big circular buffer that one thread writes into, and multiple threads read from.
//The reader threads have lower priority than the writer thread (they can be left behind if the don't read fast enough).
#include <vector>
#include <pthread.h>
#define TSM_DEBUG 0
#include <stdio.h>
using namespace std;
typedef struct tsmthread_s
{
int read_index; //it always points to the next buffer to be read
} tsmthread_t;
class tsmpool
{
private:
vector<tsmthread_t*> threads;
vector<void*> buffers;
int threads_cntr;
pthread_mutex_t mutex;
int ok; //tsmpool is expected to be included in C-style programs.
// If something fails in the constructor, it will be seen here instead of a try{}catch{}
int write_index; //it always points to the next buffer to be written
int lowest_read_index; //unused
int my_read_index; //it is used when tsmpool is used as a single writer - single reader circular buffer
public:
const size_t size;
const int num;
int is_ok();
tsmpool(size_t size, int num);
void* get_write_buffer();
tsmthread_t* register_thread();
void remove_thread(tsmthread_t* thread);
void* get_read_buffer(tsmthread_t* thread);
int index_next(int index) { return (index+1==num)?0:index+1; }
int index_before(int index) { return (index-1<0)?num-1:index-1; }
};