-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwav_48kHz.py
executable file
·109 lines (79 loc) · 3.13 KB
/
wav_48kHz.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# SPDX-License-Identifier: GPL-3.0
#
# GNU Radio Python Flow Graph
# Title: WAV 48KHz file streamer
# Author: Daniel Estevez
# Description: Streams a WAV 48kHz file
# GNU Radio version: 3.8.1.0
from gnuradio import blocks
from gnuradio import gr
from gnuradio.filter import firdes
import sys
import signal
from argparse import ArgumentParser
from gnuradio.eng_arg import eng_float, intx
from gnuradio import eng_notation
class wav_48kHz(gr.top_block):
def __init__(self, destination='localhost', input_file='', port=7355):
gr.top_block.__init__(self, "WAV 48KHz file streamer ")
##################################################
# Parameters
##################################################
self.destination = destination
self.input_file = input_file
self.port = port
##################################################
# Blocks
##################################################
self.blocks_wavfile_source_0 = blocks.wavfile_source(input_file, False)
self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_short*1, destination, port, 1472, True)
self.blocks_throttle_0 = blocks.throttle(gr.sizeof_short*1, 48000,True)
self.blocks_float_to_short_0 = blocks.float_to_short(1, 32767)
##################################################
# Connections
##################################################
self.connect((self.blocks_float_to_short_0, 0), (self.blocks_throttle_0, 0))
self.connect((self.blocks_throttle_0, 0), (self.blocks_udp_sink_0, 0))
self.connect((self.blocks_wavfile_source_0, 0), (self.blocks_float_to_short_0, 0))
def get_destination(self):
return self.destination
def set_destination(self, destination):
self.destination = destination
def get_input_file(self):
return self.input_file
def set_input_file(self, input_file):
self.input_file = input_file
def get_port(self):
return self.port
def set_port(self, port):
self.port = port
def argument_parser():
description = 'Streams a WAV 48kHz file'
parser = ArgumentParser(description=description)
parser.add_argument(
"--destination", dest="destination", type=str, default='localhost',
help="Set localhost [default=%(default)r]")
parser.add_argument(
"-f", "--input-file", dest="input_file", type=str, default='',
help="Set file [default=%(default)r]")
parser.add_argument(
"--port", dest="port", type=intx, default=7355,
help="Set port [default=%(default)r]")
return parser
def main(top_block_cls=wav_48kHz, options=None):
if options is None:
options = argument_parser().parse_args()
tb = top_block_cls(destination=options.destination, input_file=options.input_file, port=options.port)
def sig_handler(sig=None, frame=None):
tb.stop()
tb.wait()
sys.exit(0)
signal.signal(signal.SIGINT, sig_handler)
signal.signal(signal.SIGTERM, sig_handler)
tb.start()
tb.wait()
if __name__ == '__main__':
main()