I am trying to control the frequency sampling rate of my dial_tone python code through a AJAX for to flask server.
The problem is I don't have a control over the sampling rate value. Meaning, when I start running the program and start sliding/dragging the round slider to change the freq samp value it doesn't have any impact! It doesn't change the 'tone' sound. The output 'tone' or audio starts only when I end the process (hit ctrl + c).
Any help would be highly appreciated.
This is the Python code:
And this is the html script:
The problem is I don't have a control over the sampling rate value. Meaning, when I start running the program and start sliding/dragging the round slider to change the freq samp value it doesn't have any impact! It doesn't change the 'tone' sound. The output 'tone' or audio starts only when I end the process (hit ctrl + c).
Any help would be highly appreciated.
This is the Python code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
#!/usr/bin/env python2 # -*- coding: utf-8 -*- ################################################## # GNU Radio Python Flow Graph # Title: Top Block 22 # Generated: Tue Jul 23 15:54:16 2019 ################################################## from gnuradio import analog from gnuradio import audio from gnuradio import blocks from gnuradio import eng_notation from gnuradio import gr from gnuradio.eng_option import eng_option from gnuradio. filter import firdes from optparse import OptionParser from flask import Flask, render_template, jsonify, request, redirect, url_for from random import randint class top_block_22(gr.top_block): def __init__( self ): gr.top_block.__init__( self , "Top Block 22" ) ################################################## # Variables ################################################## self .samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## self .blocks_add_xx = blocks.add_vff( 1 ) self .audio_sink = audio.sink( 32000 , '', True ) self .analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 440 , 0.4 , 0 ) self .analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 350 , 0.4 , 0 ) self .analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 0.005 , - 42 ) ################################################## # Connections ################################################## self .connect(( self .analog_noise_source_x_0, 0 ), ( self .blocks_add_xx, 2 )) self .connect(( self .analog_sig_source_x_0, 0 ), ( self .blocks_add_xx, 0 )) self .connect(( self .analog_sig_source_x_1, 0 ), ( self .blocks_add_xx, 1 )) self .connect(( self .blocks_add_xx, 0 ), ( self .audio_sink, 0 )) app = Flask(__name__) @app .route( '/' ) def hex_color(): return render_template( "index.html" ) @app .route( '/valueofslider' ) def samp_rate(): samp_rate_val = request.args.get( 'samp_rate_val' ) print (samp_rate_val) return samp_rate_val app.run(debug = True ) def main(top_block_cls = top_block_22, options = None ): tb = top_block_cls() tb.start() try : raw_input ( 'Press Enter to quit: ' ) except EOFError: pass tb.stop() tb.wait() if __name__ = = '__main__' : main() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<!DOCTYPE html> <html> <head> <meta charset = "utf-8" > <title>jQuery roundSlider - JS Bin < / title> <link href = "https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.css" rel = "stylesheet" / > < / head> <body> <! - - Only html needed - - > <div id = "slider" >< / div> <script> var val; $( "#slider" ).roundSlider({ radius: 215 , min : 0 , max : 40000 , change: function () { var obj1 = $( "#slider" ).data( "roundSlider" ); val = obj1.getValue(); value: 1 $.getJSON( '/valueofslider' , { samp_rate_val: val }); } }); < / script> < / body> |