common-lisp - 如何在 Common Lisp 中的声卡上播放 FM 解调样本?
问题描述
我为 libbladerf 创建了一个 Common Lisp 库绑定,并且可以在 Common Lisp 中接收信号。我有一个解调FM信号的函数,定义如下:
(defun fm-demodulate-sc16-q11-samples (device frequency)
(configure-channel device (channel-rx 0) frequency 1000 40000000 30)
(init-sync device)
(enable-module device (channel-rx 0) t)
(with-foreign-objects ((rx-samples :uint16 8192)
(metadata :pointer))
(let ((status (bladerf_sync_rx (mem-ref device :pointer) rx-samples 4096 metadata 5000))
(samples-array (make-array 8192 :element-type 'float :initial-element 0.0 :fill-pointer 0)))
(if (< status 0)
(error "Failed to recieve IQ samples error: ~S" status)
(progn
(loop for i below 4096 by 4
do
(let* ((previous-i (mem-aref rx-samples :int16 (1+ i)))
(previous-q (mem-aref rx-samples :int16 i))
(current-i (mem-aref rx-samples :int16 (+ i 3)))
(current-q (mem-aref rx-samples :int16 (+ i 2)))
(previous-complex (complex previous-i previous-q))
(current-complex (complex current-i current-q))
(dif-complex (* (conjugate previous-complex) current-complex)))
(vector-push (atan-complex-number dif-complex) samples-array)))
samples-array)))))
然后我使用以下代码将其传递给 cl-portaudio:
(defconstant +frames-per-buffer+ 1024)
(defconstant +sample-rate+ 44100d0)
(defconstant +sample-format+ :float)
(defconstant +num-channels+ 2)
(defun play-demodulated-fm ()
(with-audio
(with-default-audio-stream (astream +num-channels+ +num-channels+ :sample-format +sample-format+ :sample-rate +sample-rate+ :frames-per-buffer +frames-per-buffer+)
(dotimes (i 20)
(write-stream astream (fm-demodulate-sc16-q11-samples *dev* 863000000)))))
当我播放这个时,我听到的只是一个削波声和以下警告:
array is copied and/or coerced, lisp type is T, requested CFFI type is FLOAT
ALSA lib pcm.c:8432:(snd_pcm_recover) underrun occurred
用 cl-portaudio 播放 FM 解调信号的正确方法是什么?
解决方案
推荐阅读
- ffmpeg - 是否可以使用 Memory Stream 如何为 FFMpeg 输入文件?
- python - 如何将 bs4 值保存在 xls 或 csv 中?
- php - Laravel 8 测试 GET http 请求误报
- python - 如何使用 selenium 和 python 在 instagram 通知中单击“not now”
- c - 使用管道和 fork() 将 Unix Shell 命令读入字符串/链接列表
- excel - excel中的_xlfn和_xlpm是什么意思?
- java - 从 java 7 中的 ArrayList 中删除备用元素
- windows - 破解 BLE 设备
- java - 存储的变量总是读为假?
- javascript - 为什么我的简单对等应用程序无法在服务器上运行