gpt4 book ai didi

gnuradio - 中断简单的 GNURadio 流

转载 作者:行者123 更新时间:2023-12-02 21:01:25 28 4
gpt4 key购买 nike

我正在尝试用 python 编写 GNURadio 脚本。我的最终目标是有一个例程,可以定期将 GNUradio 进程内的浮点结果写入串行端口。作为第一步,我想简单地暂停一个简单的例程以下代码通过声卡播放 1kHz 音调:

`#!/usr/bin/env python
##################################################
# Gnuradio Python Flow Graph
# Title: simpleTone
# Generated: Wed Jun 29 07:26:02 2016
##################################################

from gnuradio import analog
from gnuradio import audio
from gnuradio import blocks
from gnuradio import gr
import time

class simpleTone(gr.top_block):

def __init__(self):
gr.top_block.__init__(self)

##################################################
# Variables
##################################################
self.samp_rate = samp_rate = 32000

##################################################
# Blocks
##################################################
self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate)
self.audio_sink_0 = audio.sink(samp_rate, "", True)
self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 1000, 1, 0)

##################################################
# Connections
##################################################
self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0))
self.connect((self.blocks_throttle_0, 0), (self.audio_sink_0, 0))


if __name__ == '__main__':
simpleTone().run()`

上面的代码工作正常,除了一些溢出和音频点击之外。但是,如果我进行以下替换:

`        
if __name__ == '__main__':
simpleTone().start()
time.sleep(3)
simpleTone().stop()`

结果是文件运行,并在 3 秒后结束,但没有产生任何音频。

我确信我错过了一些相当基本的东西,任何帮助将不胜感激。谢谢。

-编辑

最佳答案

这个问题也在这里提出:

http://lists.gnu.org/archive/html/discuss-gnuradio

并得到答复。如果有人遇到这个问题,我将在这里分享这个答案:

Your problem is that you're constructing three unrelated top blocks: you have three separate occurrences of "simpleTone()". Instead you need to create one and continue to use it, like so:

tb = simpleTone()
tb.start()
...
tb.stop()

You have another problem, too, which you will find after fixing the first one. .wait() means to wait for the flowgraph to finish all processing, and your flowgraph has no elements within it to finish such as a Head block, so the .stop() will never be reached.

Instead, you need to proceed like this:

tb = simpleTone()
tb.start()
# the flowgraph is now running independently
time.sleep(3)
tb.stop()
tb.wait()

The final .wait() is not actually necessary in this case -- what it does is wait for the flowgraph to finish, which will happen shortly after .stop() is called, but if you later wish to start the same top block again, you must have called .wait() before you call .start(), so always having a matched set of [start, stop, wait] or [start, wait, stop] is good practice.

关于gnuradio - 中断简单的 GNURadio 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38099471/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com