Skip to content

Commit c50ffaa

Browse files
committed
Added new features, e.g. the IMA ADPCM codec and sdr.js
1 parent 4646897 commit c50ffaa

17 files changed

+2684
-257
lines changed

Diff for: Makefile

+21-1
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ PARAMS_RASPI = -mfloat-abi=hard -mcpu=arm1176jzf-s -mfpu=vfp -funsafe-math-optim
3838
PARAMS_ARM = $(if $(call cpufeature,BCM2708,dummy-text),$(PARAMS_RASPI),$(PARAMS_NEON))
3939
PARAMS_SIMD = $(if $(call cpufeature,sse,dummy-text),$(PARAMS_SSE),$(PARAMS_ARM))
4040
PARAMS_LOOPVECT = -O3 -ffast-math -fdump-tree-vect-details -dumpbase dumpvect
41-
PARAMS_LIBS = -g -lm -lrt -lfftw3f -DUSE_FFTW -DLIBCSDR_GPL
41+
PARAMS_LIBS = -g -lm -lrt -lfftw3f -DUSE_FFTW -DLIBCSDR_GPL -DUSE_IMA_ADPCM
4242
PARAMS_SO = -fpic
4343
PARAMS_MISC = -Wno-unused-result
44+
FFTW_PACKAGE = fftw-3.3.3
4445

4546
all: clean-vect
4647
@echo NOTE: you may have to manually edit Makefile to optimize for your CPU \(especially if you compile on ARM, please edit PARAMS_NEON\).
@@ -64,3 +65,22 @@ install:
6465
uninstall:
6566
rm /usr/lib/libcsdr.so /usr/bin/csdr /usr/bin/csdr-fm
6667
ldconfig
68+
emcc-clean:
69+
-rm sdr.js/sdr.js
70+
-rm sdr.js/sdrjs-compiled.js
71+
-rm -rf sdr.js/$(FFTW_PACKAGE)
72+
emcc-get-deps:
73+
echo "getting and compiling fftw3 with emscripten..."
74+
cd sdr.js; \
75+
wget http://fftw.org/$(FFTW_PACKAGE).tar.gz; \
76+
tar -xvf $(FFTW_PACKAGE).tar.gz; \
77+
rm $(FFTW_PACKAGE).tar.gz; \
78+
cd $(FFTW_PACKAGE); \
79+
emconfigure ./configure --enable-float --disable-fortran --prefix=`pwd`/emscripten-install --libdir=`pwd`/emscripten-lib; \
80+
emmake make; \
81+
emmake make install
82+
emcc:
83+
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`"
84+
cat sdr.js/sdrjs-header.js sdr.js/sdrjs-compiled.js sdr.js/sdrjs-footer.js > sdr.js/sdr.js
85+
emcc-beautify:
86+
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'

Diff for: README.md

+74-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Most of the code is available under the permissive BSD license, with some option
1010
- The code of *libcsdr* was intended to be easy to follow.
1111
- *libcsdr* was designed to use auto-vectorization available in *gcc*. It means that it can achieve some speedup by taking advantage of SIMD command sets available in today's CPUs (e.g. SSE on x86 and NEON on ARM).
1212

13+
Moreover, *libcsdr* serves as the base for the new, experimental <a href="#sdr.js">sdr.js</a>, which takes Software Defined Radio DSP to today's web browsers that provide JavScript JIT compilation.
14+
1315
How to compile
1416
--------------
1517
The project was only tested on Linux. It has the following dependencies: `libfftw3-dev`
@@ -155,15 +157,33 @@ It multiplies all samples by `gain`.
155157

156158
It copies the input to the output.
157159

160+
none
161+
162+
The `csdr` process just exits with 0.
163+
158164
yes_f <to_repeat> [buf_times]
159165

160166
It outputs continously the `to_repeat` float number.
161167
If `buf_times` is not given, it never stops.
162168
Else, after outputing `buf_times` number of buffers (the size of which is stated in the `BUFSIZE` macro), it exits.
163169

170+
detect_nan_ff
171+
172+
Along with copying its input samples to the output, it prints a warning message to *stderr* if it finds any IEEE floating point NaN values among the samples.
173+
174+
floatdump_f
175+
176+
It prints any floating point input samples.
177+
The format string used is `"%g "`.
178+
179+
flowcontrol <data_rate> <reads_per_second>
180+
181+
It limits the data rate of a stream to a given `data_rate` number of bytes per second.
182+
It copies `data_rate / reads_per_second` bytes from the input to the output, doing it `reads_per_second` times every second.
183+
164184
shift_math_cc <rate>
165185

166-
It shifts the complex spectrum by `rate`.
186+
It shifts the signal in the frequency domain by `rate`.
167187
`rate` is a floating point number between -0.5 and 0.5.
168188
`rate` is relative to the sampling rate.
169189

@@ -179,6 +199,17 @@ Internally, this function uses trigonometric addition formulas to generate sine
179199

180200
This function was used to test the accuracy of the method above.
181201

202+
shift_table_cc <rate> [table_size]
203+
204+
Operation is the same as with `shift_math_cc`.
205+
Internally, this function uses a look-up table (LUT) to recall the values of the sine function (for the first quadrant).
206+
The higher the table size is, the smaller the phase error is.
207+
208+
decimating_shift_addition_cc <rate> [decimation]
209+
210+
It shifts the input signal in the frequency domain, and also decimates it, without filtering. It will be useful as a part of the FFT channelizer implementation (to be done).
211+
It cannot be used as a channelizer by itself, use `fir_decimate_cc` instead.
212+
182213
dcblock_ff
183214

184215
This is a DC blocking IIR filter.
@@ -214,7 +245,7 @@ It uses fixed filters so it works only on predefined sample rates, for the actua
214245

215246
It is an AM demodulator that uses `sqrt`. On some architectures `sqrt` can be directly calculated by dedicated CPU instructions, but on others it may be slower.
216247

217-
amdemod_estimator_cf
248+
amdemod_estimator_cf
218249

219250
It is an AM demodulator that uses an estimation method that is faster but less accurate than `amdemod_cf`.
220251

@@ -296,10 +327,28 @@ FFTW can be faster if we let it optimalize a while before starting the first tra
296327
It measures the time taken to process `fft_cycles` transforms of `fft_size`.
297328
It lets FFTW optimalize if used with the `--benchmark` switch.
298329

299-
lowpower_cf [add_db]
330+
logpower_cf [add_db]
300331

301332
Calculates `10*log10(i^2+q^2)+add_db` for the input complex samples. It is useful for drawing power spectrum graphs.
302333

334+
encode_ima_adpcm_i16_u8
335+
336+
Encodes the audio stream to IMA ADPCM, which decreases the size to 25% of the original.
337+
338+
decode_ima_adpcm_u8_i16
339+
340+
Decodes the audio stream from IMA ADPCM.
341+
342+
compress_fft_adpcm_f_u8 <fft_size>
343+
344+
Encodes the FFT output vectors of `fft_size`. It should be used on the data output from `logpower_cf`.
345+
It resets the ADPCM encoder at the beginning of every vector, and to compensate it, `COMPRESS_FFT_PAD_N` samples are added at beginning (these equal to the first relevant sample).
346+
The actual number of padding samples can be determined by running `cat csdr.c | grep "define COMPRESS_FFT_PAD_N"`.
347+
348+
fft_exchange_sides_ff <fft_size>
349+
350+
It exchanges the first and second part of the FFT vector, to prepare it for the waterfall/spectrum display. It should operate on the data output from `logpower_cf`.
351+
303352
#### Control via pipes
304353

305354
Some parameters can be changed while the `csdr` process is running. To achieve this, some `csdr` functions have special parameters. You have to supply a fifo previously created by the `mkfifo` command. Processing will only start after the first control command has been received by `csdr` over the FIFO.
@@ -326,6 +375,28 @@ E.g. you can send `-0.05 0.02\n`
326375

327376
`csdr` was tested with GNU Radio Companion flowgraphs. These flowgraphs are available under the directory `grc_tests`, and they require the <a href="https://github.com/simonyiszk/gr-ha5kfu">gr-ha5kfu</a> set of blocks for GNU Radio.
328377

378+
## [sdr.js] (#sdr.js)
379+
380+
*sdr.js* is *libcsdr* compiled to JavaScript code with *Emscripten*. Nowadays JavaScript runs quite fast in browsers, as all major browser vendors included JavaScript JIT machines into their product. You can find a <a href="https://kripken.github.io/mloc_emscripten_talk/cppcon.html">great introductory slideshow here</a> about *Emscripten*.
381+
382+
The purpose of *sdr.js* is to make SDR DSP processing available in the web browser. However, it is not easy to use in production yet. By now, only those functions have wrappers that the front-end of OpenWebRX uses.
383+
384+
To compile *sdr.js*, you will need <a href="http://emscripten.org/">emscripten</a>. (It turns out that *emscripten* is already included in Ubuntu repositories.)
385+
386+
To install and build dependencies (for now, only FFTW3):
387+
388+
make emcc-get-deps
389+
390+
To compile *sdr.js* (which will be created in the `sdr.js` subdirectory):
391+
392+
make emcc
393+
394+
You can test *sdr.js* by opening *sdr.html*. It contains a test for *firdes_lowpass_f* for this time.
395+
396+
To remove *sdr.js* and the compiled dependencies:
397+
398+
make emcc-clean
399+
329400
## [Licensing] (#licensing)
330401

331402
Most of the code of `libcsdr` is under BSD license.

0 commit comments

Comments
 (0)