微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Gnuradio:SineWave 生成​​器 python 块断断续续的音频输出

如何解决Gnuradio:SineWave 生成​​器 python 块断断续续的音频输出

为了测试一些东西,我正在尝试使用 gnuradio 中的 python 块开发我自己的 SineWave 发生器

在这里

"""
Embedded Python Blocks:

Each time this file is saved,GRC will instantiate the first class it finds
to get ports and parameters of your block. The arguments to __init__  will
be the parameters. All of them are required to have default values!
"""

import numpy as np
from gnuradio import gr


class blk(gr.sync_block):  # other base classes are basic_block,decim_block,interp_block
    """Embedded Python Block example - a simple multiply const"""

    def __init__(self,sample_rate=192e3,frequency=1e3,amplitude=1):  # only default arguments here
        """arguments to this function show up as parameters in GRC"""
        gr.sync_block.__init__(
            self,name='SineWave Generator',# will show up in GRC
            in_sig=[np.float32],#in_sig=None,out_sig=[np.float32]
        )
        # if an attribute with the same name as a parameter is found,# a callback is registered (properties work,too).
        self.sample_rate = sample_rate
        self.frequency = frequency
        self.amplitude = amplitude
        

    def work(self,input_items,output_items):
        """example: multiply with constant"""
        print "length of input =",len(input_items[0])
        print "length of output =",len(output_items[0])
        
        for i in range(0,len(output_items[0])): #8192
            output_items[0][i] = np.sin(2 * np.pi * self.frequency * (i / self.sample_rate)) * self.amplitude 
        
        
        
        return len(output_items[0])

并在我的流程图中使用 https://imgur.com/28kE1Sj

这个块产生正弦波 corecly 但音频真的很糟糕,就像我不能足够快地生成正弦波或其他东西(sample_rate 应该不是问题,因为如果我用 Signal 替换我的块,那么相同的流程图可以corecly 工作来源)

我也在使用 Null 源(因为我还没有弄清楚如何在没有任何源的情况下创建一个 python 块(一旦我设置了 in_sig=None,我的块就没有声音了,所以我不确定信号源如何在没有任何源连接到其输入的情况下生成音频)

感谢您的回答和问候

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。