I’m not quite sure I have all the bugs worked out yet, but I implemented simple averaging, as well and the frequency display. The latter required implementing fft-shift to move center frequency to the center. The above plot shows FM stations at 101.1, 102.5, 103.9, and 104.7 Mhz, matching local stations I know about.
These simple things took quite a while, mainly because of the busyness of other life responsibilities; but also because the process of implementation led to fixing some bugs, which led to cleaning up some code, which led to learning new things about Guile scheme and C.
In Guile scheme, I learned how to implement a procedure to auto-close unreachable ports:
(define ports-guardian #f) (define (close-guarded-ports) (let f () (let ((p (ports-guardian))) (when p (begin (close-port p) (f)))))) (define (initialize-ports-guardian) (when (not ports-guardian) (set! ports-guardian (make-guardian)) (add-hook! after-gc-hook (lambda () (close-guarded-ports))))) (initialize-ports-guardian) (define (register-autoclose p) (ports-guardian p) p)
register-autoclose can simply be wrapped around the port, e.g.:
(define (hackrf-cb-rx-to-file filename) (hackrf-cb-rx-to-stream (register-autoclose (open-output-file filename))))
This uses Guile scheme “guardian” functionality, which is an object that can return registered objects if the have become unreachable everywhere else.
git clone git://git.librehacker.com/pub/git/hackrf-rkt.git