diff options
Diffstat (limited to 'gr-vocoder')
21 files changed, 1509 insertions, 0 deletions
diff --git a/gr-vocoder/CMakeLists.txt b/gr-vocoder/CMakeLists.txt index 686378f2a7..29798318e7 100644 --- a/gr-vocoder/CMakeLists.txt +++ b/gr-vocoder/CMakeLists.txt @@ -58,6 +58,7 @@ if(LIBCODEC2_FOUND) #message(STATUS "libcodec2 has 700bps mode") endif() if (LIBCODEC2_HAS_FREEDV_API) + GR_APPEND_SUBCOMPONENT("freedv") #message(STATUS "libcodec2 had FreeDV api modes: ${FREEDV_MODES}") endif() endif(LIBCODEC2_FOUND) diff --git a/gr-vocoder/examples/CMakeLists.txt b/gr-vocoder/examples/CMakeLists.txt index e5895c8d8a..20e250fe29 100644 --- a/gr-vocoder/examples/CMakeLists.txt +++ b/gr-vocoder/examples/CMakeLists.txt @@ -36,6 +36,7 @@ if(LIBCODEC2_FOUND) GR_PYTHON_INSTALL( PROGRAMS codec2_audio_loopback.py + grfreedv.grc DESTINATION ${GR_PKG_VOCODER_EXAMPLES_DIR} ) endif(LIBCODEC2_FOUND) diff --git a/gr-vocoder/examples/grfreedv.grc b/gr-vocoder/examples/grfreedv.grc new file mode 100644 index 0000000000..9f6b95d5bd --- /dev/null +++ b/gr-vocoder/examples/grfreedv.grc @@ -0,0 +1,616 @@ +<?xml version='1.0' encoding='utf-8'?> +<?grc format='1' created='3.7.9'?> +<flow_graph> + <timestamp>Wed Jun 29 19:22:27 2016</timestamp> + <block> + <key>options</key> + <param> + <key>author</key> + <value>A. MAitland Bottoms</value> + </param> + <param> + <key>window_size</key> + <value></value> + </param> + <param> + <key>category</key> + <value>Custom</value> + </param> + <param> + <key>comment</key> + <value></value> + </param> + <param> + <key>description</key> + <value>A FreeDV Modulator</value> + </param> + <param> + <key>_enabled</key> + <value>True</value> + </param> + <param> + <key>_coordinate</key> + <value>(8, 8)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + <param> + <key>generate_options</key> + <value>qt_gui</value> + </param> + <param> + <key>hier_block_src_path</key> + <value>.:</value> + </param> + <param> + <key>id</key> + <value>grfreedv</value> + </param> + <param> + <key>max_nouts</key> + <value>0</value> + </param> + <param> + <key>qt_qss_theme</key> + <value></value> + </param> + <param> + <key>realtime_scheduling</key> + <value></value> + </param> + <param> + <key>run_command</key> + <value>{python} -u {filename}</value> + </param> + <param> + <key>run_options</key> + <value>prompt</value> + </param> + <param> + <key>run</key> + <value>True</value> + </param> + <param> + <key>thread_safe_setters</key> + <value></value> + </param> + <param> + <key>title</key> + <value>GNU Radio FreeDV</value> + </param> + </block> + <block> + <key>variable</key> + <param> + <key>comment</key> + <value></value> + </param> + <param> + <key>_enabled</key> + <value>True</value> + </param> + <param> + <key>_coordinate</key> + <value>(8, 160)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + <param> + <key>id</key> + <value>samp_rate</value> + </param> + <param> + <key>value</key> + <value>8000</value> + </param> + </block> + <block> + <key>variable_qtgui_range</key> + <param> + <key>comment</key> + <value></value> + </param> + <param> + <key>value</key> + <value>-120</value> + </param> + <param> + <key>_enabled</key> + <value>True</value> + </param> + <param> + <key>_coordinate</key> + <value>(232, 16)</value> + </param> + <param> + <key>gui_hint</key> + <value></value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + <param> + <key>id</key> + <value>squelch</value> + </param> + <param> + <key>label</key> + <value>squelch slider</value> + </param> + <param> + <key>min_len</key> + <value>256</value> + </param> + <param> + <key>orient</key> + <value>Qt.Horizontal</value> + </param> + <param> + <key>start</key> + <value>-127</value> + </param> + <param> + <key>step</key> + <value>1</value> + </param> + <param> + <key>stop</key> + <value>128</value> + </param> + <param> + <key>rangeType</key> + <value>float</value> + </param> + <param> + <key>widget</key> + <value>counter_slider</value> + </param> + </block> + <block> + <key>audio_sink</key> + <param> + <key>alias</key> + <value></value> + </param> + <param> + <key>comment</key> + <value></value> + </param> + <param> + <key>affinity</key> + <value></value> + </param> + <param> + <key>device_name</key> + <value></value> + </param> + <param> + <key>_enabled</key> + <value>True</value> + </param> + <param> + <key>_coordinate</key> + <value>(920, 228)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + <param> + <key>id</key> + <value>audio_sink_0</value> + </param> + <param> + <key>num_inputs</key> + <value>1</value> + </param> + <param> + <key>ok_to_block</key> + <value>True</value> + </param> + <param> + <key>samp_rate</key> + <value>samp_rate</value> + </param> + </block> + <block> + <key>audio_source</key> + <param> + <key>alias</key> + <value></value> + </param> + <param> + <key>comment</key> + <value></value> + </param> + <param> + <key>affinity</key> + <value></value> + </param> + <param> + <key>device_name</key> + <value>hw:2,0</value> + </param> + <param> + <key>_enabled</key> + <value>0</value> + </param> + <param> + <key>_coordinate</key> + <value>(16, 325)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + <param> + <key>id</key> + <value>audio_source_0</value> + </param> + <param> + <key>maxoutbuf</key> + <value>0</value> + </param> + <param> + <key>minoutbuf</key> + <value>0</value> + </param> + <param> + <key>num_outputs</key> + <value>1</value> + </param> + <param> + <key>ok_to_block</key> + <value>True</value> + </param> + <param> + <key>samp_rate</key> + <value>48000</value> + </param> + </block> + <block> + <key>blocks_float_to_short</key> + <param> + <key>alias</key> + <value></value> + </param> + <param> + <key>comment</key> + <value></value> + </param> + <param> + <key>affinity</key> + <value></value> + </param> + <param> + <key>_enabled</key> + <value>1</value> + </param> + <param> + <key>_coordinate</key> + <value>(256, 228)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + <param> + <key>id</key> + <value>blocks_float_to_short_0</value> + </param> + <param> + <key>maxoutbuf</key> + <value>0</value> + </param> + <param> + <key>minoutbuf</key> + <value>0</value> + </param> + <param> + <key>scale</key> + <value>32768</value> + </param> + <param> + <key>vlen</key> + <value>1</value> + </param> + </block> + <block> + <key>blocks_short_to_float</key> + <param> + <key>alias</key> + <value></value> + </param> + <param> + <key>comment</key> + <value></value> + </param> + <param> + <key>affinity</key> + <value></value> + </param> + <param> + <key>_enabled</key> + <value>1</value> + </param> + <param> + <key>_coordinate</key> + <value>(736, 228)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + <param> + <key>id</key> + <value>blocks_short_to_float_0</value> + </param> + <param> + <key>maxoutbuf</key> + <value>0</value> + </param> + <param> + <key>minoutbuf</key> + <value>0</value> + </param> + <param> + <key>scale</key> + <value>32768</value> + </param> + <param> + <key>vlen</key> + <value>1</value> + </param> + </block> + <block> + <key>blocks_wavfile_source</key> + <param> + <key>alias</key> + <value></value> + </param> + <param> + <key>comment</key> + <value></value> + </param> + <param> + <key>affinity</key> + <value></value> + </param> + <param> + <key>_enabled</key> + <value>1</value> + </param> + <param> + <key>file</key> + <value>/usr/share/codec2/wav/all.wav</value> + </param> + <param> + <key>_coordinate</key> + <value>(24, 221)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + <param> + <key>id</key> + <value>blocks_wavfile_source_0</value> + </param> + <param> + <key>maxoutbuf</key> + <value>0</value> + </param> + <param> + <key>minoutbuf</key> + <value>0</value> + </param> + <param> + <key>nchan</key> + <value>1</value> + </param> + <param> + <key>repeat</key> + <value>True</value> + </param> + </block> + <block> + <key>rational_resampler_xxx</key> + <param> + <key>alias</key> + <value></value> + </param> + <param> + <key>comment</key> + <value></value> + </param> + <param> + <key>affinity</key> + <value></value> + </param> + <param> + <key>decim</key> + <value>6</value> + </param> + <param> + <key>_enabled</key> + <value>0</value> + </param> + <param> + <key>fbw</key> + <value>0</value> + </param> + <param> + <key>_coordinate</key> + <value>(216, 303)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + <param> + <key>id</key> + <value>rational_resampler_xxx_0</value> + </param> + <param> + <key>interp</key> + <value>1</value> + </param> + <param> + <key>maxoutbuf</key> + <value>0</value> + </param> + <param> + <key>minoutbuf</key> + <value>0</value> + </param> + <param> + <key>taps</key> + <value></value> + </param> + <param> + <key>type</key> + <value>fff</value> + </param> + </block> + <block> + <key>vocoder_freedv_rx_ss</key> + <param> + <key>alias</key> + <value></value> + </param> + <param> + <key>comment</key> + <value></value> + </param> + <param> + <key>affinity</key> + <value></value> + </param> + <param> + <key>_enabled</key> + <value>1</value> + </param> + <param> + <key>_coordinate</key> + <value>(576, 325)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + <param> + <key>id</key> + <value>vocoder_freedv_rx_ss_0</value> + </param> + <param> + <key>maxoutbuf</key> + <value>0</value> + </param> + <param> + <key>minoutbuf</key> + <value>0</value> + </param> + <param> + <key>mode</key> + <value>freedv_api.MODE_1600</value> + </param> + <param> + <key>squelch_thresh</key> + <value>squelch</value> + </param> + </block> + <block> + <key>vocoder_freedv_tx_ss</key> + <param> + <key>alias</key> + <value></value> + </param> + <param> + <key>comment</key> + <value></value> + </param> + <param> + <key>affinity</key> + <value></value> + </param> + <param> + <key>_enabled</key> + <value>1</value> + </param> + <param> + <key>_coordinate</key> + <value>(424, 221)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + <param> + <key>id</key> + <value>vocoder_freedv_tx_ss_0</value> + </param> + <param> + <key>maxoutbuf</key> + <value>0</value> + </param> + <param> + <key>minoutbuf</key> + <value>0</value> + </param> + <param> + <key>mode</key> + <value>freedv_api.MODE_1600</value> + </param> + <param> + <key>txt_msg</key> + <value>'GNU Radio'</value> + </param> + </block> + <connection> + <source_block_id>audio_source_0</source_block_id> + <sink_block_id>rational_resampler_xxx_0</sink_block_id> + <source_key>0</source_key> + <sink_key>0</sink_key> + </connection> + <connection> + <source_block_id>blocks_float_to_short_0</source_block_id> + <sink_block_id>vocoder_freedv_tx_ss_0</sink_block_id> + <source_key>0</source_key> + <sink_key>0</sink_key> + </connection> + <connection> + <source_block_id>blocks_short_to_float_0</source_block_id> + <sink_block_id>audio_sink_0</sink_block_id> + <source_key>0</source_key> + <sink_key>0</sink_key> + </connection> + <connection> + <source_block_id>blocks_wavfile_source_0</source_block_id> + <sink_block_id>blocks_float_to_short_0</sink_block_id> + <source_key>0</source_key> + <sink_key>0</sink_key> + </connection> + <connection> + <source_block_id>rational_resampler_xxx_0</source_block_id> + <sink_block_id>blocks_float_to_short_0</sink_block_id> + <source_key>0</source_key> + <sink_key>0</sink_key> + </connection> + <connection> + <source_block_id>vocoder_freedv_rx_ss_0</source_block_id> + <sink_block_id>blocks_short_to_float_0</sink_block_id> + <source_key>0</source_key> + <sink_key>0</sink_key> + </connection> + <connection> + <source_block_id>vocoder_freedv_tx_ss_0</source_block_id> + <sink_block_id>vocoder_freedv_rx_ss_0</sink_block_id> + <source_key>0</source_key> + <sink_key>0</sink_key> + </connection> +</flow_graph> diff --git a/gr-vocoder/grc/CMakeLists.txt b/gr-vocoder/grc/CMakeLists.txt index fd320545ad..eef52179cb 100644 --- a/gr-vocoder/grc/CMakeLists.txt +++ b/gr-vocoder/grc/CMakeLists.txt @@ -44,6 +44,15 @@ if(LIBCODEC2_FOUND) ) endif(LIBCODEC2_FOUND) +if(LIBCODEC2_HAS_FREEDV_API) + install(FILES + vocoder_freedv_rx_ss.xml + vocoder_freedv_tx_ss.xml + DESTINATION ${GRC_BLOCKS_DIR} + COMPONENT "vocoder_python" + ) +endif(LIBCODEC2_HAS_FREEDV_API) + if(LIBGSM_FOUND) install(FILES vocoder_gsm_fr_decode_ps.xml diff --git a/gr-vocoder/grc/CMakeLists.txt.orig b/gr-vocoder/grc/CMakeLists.txt.orig new file mode 100644 index 0000000000..fd320545ad --- /dev/null +++ b/gr-vocoder/grc/CMakeLists.txt.orig @@ -0,0 +1,53 @@ +# Copyright 2011,2016 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +install(FILES + vocoder_alaw_decode_bs.xml + vocoder_alaw_encode_sb.xml + vocoder_block_tree.xml + vocoder_cvsd_decode_bs.xml + vocoder_cvsd_decode.xml + vocoder_cvsd_encode_sb.xml + vocoder_cvsd_encode.xml + vocoder_g721_decode_bs.xml + vocoder_g721_encode_sb.xml + vocoder_g723_24_decode_bs.xml + vocoder_g723_24_encode_sb.xml + vocoder_g723_40_decode_bs.xml + vocoder_g723_40_encode_sb.xml + vocoder_ulaw_decode_bs.xml + vocoder_ulaw_encode_sb.xml + DESTINATION ${GRC_BLOCKS_DIR} +) + +if(LIBCODEC2_FOUND) + install(FILES + vocoder_codec2_decode_ps.xml + vocoder_codec2_encode_sp.xml + DESTINATION ${GRC_BLOCKS_DIR} + ) +endif(LIBCODEC2_FOUND) + +if(LIBGSM_FOUND) + install(FILES + vocoder_gsm_fr_decode_ps.xml + vocoder_gsm_fr_encode_sp.xml + DESTINATION ${GRC_BLOCKS_DIR} + ) +endif(LIBGSM_FOUND) diff --git a/gr-vocoder/grc/vocoder_block_tree.xml b/gr-vocoder/grc/vocoder_block_tree.xml index 07d8ba8fd1..e47af4cdd5 100644 --- a/gr-vocoder/grc/vocoder_block_tree.xml +++ b/gr-vocoder/grc/vocoder_block_tree.xml @@ -38,6 +38,8 @@ <block>vocoder_cvsd_encode_sb</block> <block>vocoder_cvsd_decode_bf</block> <block>vocoder_cvsd_encode_fb</block> + <block>vocoder_freedv_tx_ss</block> + <block>vocoder_freedv_rx_ss</block> <block>vocoder_g721_decode_bs</block> <block>vocoder_g721_encode_sb</block> <block>vocoder_g723_24_decode_bs</block> diff --git a/gr-vocoder/grc/vocoder_freedv_rx_ss.xml b/gr-vocoder/grc/vocoder_freedv_rx_ss.xml new file mode 100644 index 0000000000..14e00a0979 --- /dev/null +++ b/gr-vocoder/grc/vocoder_freedv_rx_ss.xml @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<!-- +################################################### +## FreeDV audio modem demodulator +################################################### + --> +<block> + <name>FreeDV demodulator</name> + <key>vocoder_freedv_rx_ss</key> + <import>from gnuradio import vocoder</import> + <import>from gnuradio.vocoder import freedv_api</import> + <make>vocoder.freedv_rx_ss($mode,$squelch_thresh)</make> + <callback>set_squelch_thresh($squelch_thresh)</callback> + <param> + <name>Operating Mode</name> + <key>mode</key> + <value>freedv_api.MODE_1600</value> + <type>int</type> + <option> + <name>1600</name> + <key>freedv_api.MODE_1600</key> + </option> + <option> + <name>700</name> + <key>freedv_api.MODE_700</key> + </option> + <option> + <name>700B</name> + <key>freedv_api.MODE_700B</key> + </option> + <option> + <name>2400A</name> + <key>freedv_api.MODE_2400A</key> + </option> + <option> + <name>2400B</name> + <key>freedv_api.MODE_2400B</key> + </option> + <option> + <name>800XA</name> + <key>freedv_api.MODE_800XA</key> + </option> + </param> + <param> + <name>Squelch Threshold</name> + <key>squelch_thresh</key> + <value>-100.0</value> + <type>float</type> + </param> + <sink> + <name>in</name> + <type>short</type> + </sink> + <source> + <name>out</name> + <type>short</type> + </source> +</block> diff --git a/gr-vocoder/grc/vocoder_freedv_tx_ss.xml b/gr-vocoder/grc/vocoder_freedv_tx_ss.xml new file mode 100644 index 0000000000..54a49b730f --- /dev/null +++ b/gr-vocoder/grc/vocoder_freedv_tx_ss.xml @@ -0,0 +1,57 @@ +<?xml version="1.0"?> +<!-- +################################################### +## FreeDV audio modem modulator +################################################### + --> +<block> + <name>FreeDV modulator</name> + <key>vocoder_freedv_tx_ss</key> + <import>from gnuradio import vocoder</import> + <import>from gnuradio.vocoder import freedv_api</import> + <make>vocoder.freedv_tx_ss($mode,$txt_msg)</make> + <param> + <name>Operating Mode</name> + <key>mode</key> + <value>freedv_api.MODE_1600</value> + <type>int</type> + <option> + <name>1600</name> + <key>freedv_api.MODE_1600</key> + </option> + <option> + <name>700</name> + <key>freedv_api.MODE_700</key> + </option> + <option> + <name>700B</name> + <key>freedv_api.MODE_700B</key> + </option> + <option> + <name>2400A</name> + <key>freedv_api.MODE_2400A</key> + </option> + <option> + <name>2400B</name> + <key>freedv_api.MODE_2400B</key> + </option> + <option> + <name>800XA</name> + <key>freedv_api.MODE_800XA</key> + </option> + </param> + <param> + <name>Text Message</name> + <key>txt_msg</key> + <value>'GNU Radio'</value> + <type>string</type> + </param> + <sink> + <name>in</name> + <type>short</type> + </sink> + <source> + <name>out</name> + <type>short</type> + </source> +</block> diff --git a/gr-vocoder/include/gnuradio/vocoder/CMakeLists.txt b/gr-vocoder/include/gnuradio/vocoder/CMakeLists.txt index 172f18a730..65ec5238a0 100644 --- a/gr-vocoder/include/gnuradio/vocoder/CMakeLists.txt +++ b/gr-vocoder/include/gnuradio/vocoder/CMakeLists.txt @@ -44,6 +44,15 @@ install(FILES DESTINATION ${GR_INCLUDE_DIR}/gnuradio/vocoder ) endif(LIBCODEC2_FOUND) +if(LIBCODEC2_HAS_FREEDV_API) +install(FILES + freedv_api.h + freedv_rx_ss.h + freedv_tx_ss.h + DESTINATION ${GR_INCLUDE_DIR}/gnuradio/vocoder + COMPONENT "vocoder_devel" +) +endif(LIBCODEC2_HAS_FREEDV_API) if(LIBGSM_FOUND) install(FILES gsm_fr_decode_ps.h diff --git a/gr-vocoder/include/gnuradio/vocoder/CMakeLists.txt.orig b/gr-vocoder/include/gnuradio/vocoder/CMakeLists.txt.orig new file mode 100644 index 0000000000..172f18a730 --- /dev/null +++ b/gr-vocoder/include/gnuradio/vocoder/CMakeLists.txt.orig @@ -0,0 +1,53 @@ +# Copyright 2012,2013,2016 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +######################################################################## +# Install header files +######################################################################## +install(FILES + api.h + alaw_decode_bs.h + alaw_encode_sb.h + cvsd_decode_bs.h + cvsd_encode_sb.h + g721_decode_bs.h + g721_encode_sb.h + g723_24_decode_bs.h + g723_24_encode_sb.h + g723_40_decode_bs.h + g723_40_encode_sb.h + ulaw_decode_bs.h + ulaw_encode_sb.h + DESTINATION ${GR_INCLUDE_DIR}/gnuradio/vocoder +) +if(LIBCODEC2_FOUND) +install(FILES + codec2.h + codec2_decode_ps.h + codec2_encode_sp.h + DESTINATION ${GR_INCLUDE_DIR}/gnuradio/vocoder +) +endif(LIBCODEC2_FOUND) +if(LIBGSM_FOUND) +install(FILES + gsm_fr_decode_ps.h + gsm_fr_encode_sp.h + DESTINATION ${GR_INCLUDE_DIR}/gnuradio/vocoder +) +endif(LIBGSM_FOUND) diff --git a/gr-vocoder/include/gnuradio/vocoder/freedv_api.h b/gr-vocoder/include/gnuradio/vocoder/freedv_api.h new file mode 100644 index 0000000000..230da4e108 --- /dev/null +++ b/gr-vocoder/include/gnuradio/vocoder/freedv_api.h @@ -0,0 +1,68 @@ +/* -*- c++ -*- */ +/* + * Copyright 2016 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _VOCODER_FREEDV_H_ +#define _VOCODER_FREEDV_H_ + +#include <gnuradio/vocoder/api.h> + +extern "C" { +#include <codec2/codec2.h> +#include <codec2/freedv_api.h> +#include <codec2/modem_stats.h> +} + +namespace gr { + namespace vocoder { + + class VOCODER_API freedv_api { + public: + + enum freedv_modes { +#ifdef FREEDV_MODE_1600 + MODE_1600 = FREEDV_MODE_1600, +#endif +#ifdef FREEDV_MODE_700 + MODE_700 = FREEDV_MODE_700, +#endif +#ifdef FREEDV_MODE_700B + MODE_700B = FREEDV_MODE_700B, +#endif +#ifdef FREEDV_MODE_2400A + MODE_2400A = FREEDV_MODE_2400A, +#endif +#ifdef FREEDV_MODE_2400B + MODE_2400B = FREEDV_MODE_2400B, +#endif +#ifdef FREEDV_MODE_800XA + MODE_800XA = FREEDV_MODE_800XA, +#endif + }; + + private: + + }; + + } /* namespace vocoder */ +} /* namespace gr */ + +#endif /* _VOCODER_FREEDV_H_ */ diff --git a/gr-vocoder/include/gnuradio/vocoder/freedv_rx_ss.h b/gr-vocoder/include/gnuradio/vocoder/freedv_rx_ss.h new file mode 100644 index 0000000000..a6568dee7d --- /dev/null +++ b/gr-vocoder/include/gnuradio/vocoder/freedv_rx_ss.h @@ -0,0 +1,63 @@ +/* -*- c++ -*- */ +/* + * Copyright 2016 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_VOCODER_FREEDV_RX_H +#define INCLUDED_VOCODER_FREEDV_RX_H + +#include <gnuradio/vocoder/api.h> +#include <gnuradio/vocoder/freedv_api.h> +#include <gnuradio/block.h> + +namespace gr { + namespace vocoder { + + /*! + * \brief FreeDV demodulator + * \ingroup audio_blk + * + * Input: 16-bit short values of an audio signal with sampling rate 8 kHz. + * + * Output: 16-bit short values of an audio signal with sampling rate 8 kHz. + * + * See also gr::vocoder::freedv_tx_ss. + */ + class VOCODER_API freedv_rx_ss : virtual public gr::block + { + public: + typedef boost::shared_ptr<freedv_rx_ss> sptr; + + /*! + * \brief Make FreeDV modem demodulator block. + * + * \param mode Operating Mode designation + * \param squelch_thresh FreeDV modem squelch threshold value + */ + static sptr make(int mode=freedv_api::MODE_1600, float squelch_thresh=-100.0); + + virtual void set_squelch_thresh(float squelch_thresh) = 0; + virtual float squelch_thresh() = 0; + }; + + } /* namespace vocoder */ +} /* namespace gr */ + +#endif /* INCLUDED_VOCODER_FREEDV_RX_H */ diff --git a/gr-vocoder/include/gnuradio/vocoder/freedv_tx_ss.h b/gr-vocoder/include/gnuradio/vocoder/freedv_tx_ss.h new file mode 100644 index 0000000000..0e80d78bfb --- /dev/null +++ b/gr-vocoder/include/gnuradio/vocoder/freedv_tx_ss.h @@ -0,0 +1,59 @@ +/* -*- c++ -*- */ +/* + * Copyright 2016 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_VOCODER_FREEDV_TX_H +#define INCLUDED_VOCODER_FREEDV_TX_H + +#include <gnuradio/vocoder/api.h> +#include <gnuradio/vocoder/freedv_api.h> +#include <gnuradio/sync_block.h> + +namespace gr { + namespace vocoder { + + /*! + * \brief FreeDV modulator + * \ingroup audio_blk + * + * Input: Speech (audio) signal as 16-bit shorts, sampling rate 8 kHz. + * + * Output: Signal (audio) as 16-bit shorts, sampling rate 8 kHz. + * + */ + class VOCODER_API freedv_tx_ss : virtual public gr::sync_block + { + public: + typedef boost::shared_ptr<freedv_tx_ss> sptr; + + /*! + * \brief Make FreeDV Modem modulator block. + * + * \param mode Operating Mode designation + * \param msg_txt Low Rate message text (callsign, location) + */ + static sptr make(int mode=freedv_api::MODE_1600,const std::string msg_txt="GNU Radio"); + }; + + } /* namespace vocoder */ +} /* namespace gr */ + +#endif /* INCLUDED_VOCODER_FREEDV_TX_H */ diff --git a/gr-vocoder/lib/CMakeLists.txt b/gr-vocoder/lib/CMakeLists.txt index 5e806a2c2c..e26cb1820a 100644 --- a/gr-vocoder/lib/CMakeLists.txt +++ b/gr-vocoder/lib/CMakeLists.txt @@ -61,6 +61,13 @@ if(LIBCODEC2_FOUND) codec2_encode_sp_impl.cc ) endif(LIBCODEC2_FOUND) +if(LIBCODEC2_HAS_FREEDV_API) + list(APPEND gr_vocoder_sources + freedv_api.cc + freedv_rx_ss_impl.cc + freedv_tx_ss_impl.cc + ) +endif(LIBCODEC2_HAS_FREEDV_API) if(LIBGSM_FOUND) list(APPEND gr_vocoder_sources gsm_fr_decode_ps_impl.cc diff --git a/gr-vocoder/lib/freedv_api.cc b/gr-vocoder/lib/freedv_api.cc new file mode 100644 index 0000000000..063a6bb9f0 --- /dev/null +++ b/gr-vocoder/lib/freedv_api.cc @@ -0,0 +1,33 @@ +/* -*- c++ -*- */ +/* + * Copyright 2016 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <gnuradio/vocoder/freedv_api.h> + +namespace gr { + namespace vocoder { + + } /* namespace vocoder */ +} /* namespace gr */ diff --git a/gr-vocoder/lib/freedv_rx_ss_impl.cc b/gr-vocoder/lib/freedv_rx_ss_impl.cc new file mode 100644 index 0000000000..748a5c10aa --- /dev/null +++ b/gr-vocoder/lib/freedv_rx_ss_impl.cc @@ -0,0 +1,146 @@ +/* -*- c++ -*- */ +/* + * Copyright 2016 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "freedv_rx_ss_impl.h" + +#include <gnuradio/io_signature.h> +#include <stdexcept> +#include <assert.h> + +extern "C" { + void put_next_rx_char(void *callback_state, char c) { + struct freedv_rx_callback_state* pstate; + + pstate = (struct freedv_rx_callback_state*) callback_state; + if (pstate->ftxt != NULL) { + //fprintf(pstate->ftxt, "%c\n", c); + } + return; + } +} + + +namespace gr { + namespace vocoder { + + freedv_rx_ss::sptr + freedv_rx_ss::make(int mode, float squelch_thresh) + { + return gnuradio::get_initial_sptr + (new freedv_rx_ss_impl(mode, squelch_thresh)); + } + + freedv_rx_ss_impl::freedv_rx_ss_impl (int mode, float squelch_thresh) + : gr::block("vocoder_freedv_rx_ss", + io_signature::make(1, 1, sizeof(short)), + io_signature::make(1, 1, sizeof(short))), + d_mode(mode), d_squelch_thresh(squelch_thresh) + { + if((d_freedv = freedv_open(mode)) == NULL) + throw std::runtime_error("freedv_rx_ss_impl: freedv_open failed"); + freedv_set_snr_squelch_thresh(d_freedv, d_squelch_thresh); + freedv_set_squelch_en(d_freedv, 0); + freedv_set_callback_txt(d_freedv, put_next_rx_char, NULL, (void *) &d_cb_state); + d_speech_samples = freedv_get_n_speech_samples(d_freedv); + d_max_modem_samples = freedv_get_n_max_modem_samples(d_freedv); + d_nin = freedv_nin(d_freedv); + set_output_multiple(d_max_modem_samples); + } + + freedv_rx_ss_impl::~freedv_rx_ss_impl() + { + int total_bits; + int total_bit_errors; + + if (freedv_get_test_frames(d_freedv)) { + total_bits = freedv_get_total_bits(d_freedv); + total_bit_errors = freedv_get_total_bit_errors(d_freedv); + fprintf(stderr, "bits: %d errors: %d BER: %3.2f\n", total_bits, total_bit_errors, (1.0*total_bit_errors)/total_bits); + } + freedv_close(d_freedv); + } + + void + freedv_rx_ss_impl::forecast(int noutput_items, + gr_vector_int &ninput_items_required) + { + unsigned ninputs = ninput_items_required.size(); + for(unsigned i = 0; i < ninputs; i++) + ninput_items_required[i] = std::max(d_nin, noutput_items); + } + + int + freedv_rx_ss_impl::general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + short *in = (short *) input_items[0]; + short *out = (short *) output_items[0]; + + int in_offset = 0, out_offset = 0; + + while ((noutput_items - out_offset) >= d_max_modem_samples + && (ninput_items[0] - in_offset) >= d_nin) { + d_nout = freedv_rx(d_freedv, out + out_offset, in + in_offset); + out_offset += d_nout; + in_offset += d_nin; + d_nin = freedv_nin(d_freedv); + } + + freedv_get_modem_stats(d_freedv, &d_sync, &d_snr_est); + freedv_get_modem_extended_stats(d_freedv, &d_stats); + d_total_bit_errors = freedv_get_total_bit_errors(d_freedv); + + consume_each(in_offset); + return out_offset; + } + + void put_next_rx_proto(void *callback_state,char *proto_bits) { + return; + } + + void datarx(void *callback_state, unsigned char *packet, size_t size) { + return; + } + + void datatx(void *callback_state, unsigned char *packet, size_t *size) { + return; + } + + void freedv_rx_ss_impl::set_squelch_thresh(float squelch_thresh) + { + gr::thread::scoped_lock l(d_setlock); + d_squelch_thresh = squelch_thresh; + freedv_set_snr_squelch_thresh(d_freedv, d_squelch_thresh); + } + + float freedv_rx_ss_impl::squelch_thresh() { + return(d_squelch_thresh); + } + + } /* namespace vocoder */ +} /* namespace gr */ diff --git a/gr-vocoder/lib/freedv_rx_ss_impl.h b/gr-vocoder/lib/freedv_rx_ss_impl.h new file mode 100644 index 0000000000..acc49d9d82 --- /dev/null +++ b/gr-vocoder/lib/freedv_rx_ss_impl.h @@ -0,0 +1,81 @@ +/* -*- c++ -*- */ +/* + * Copyright 2016 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_VOCODER_FREEDV_RX_SS_IMPL_H +#define INCLUDED_VOCODER_FREEDV_RX_SS_IMPL_H + +#include <gnuradio/vocoder/freedv_rx_ss.h> + +extern "C" { + struct freedv_rx_callback_state { + FILE *ftxt; + }; + static void put_next_rx_char(void *callback_state, char c); + void put_next_rx_proto(void *callback_state,char *proto_bits); + void datarx(void *callback_state, unsigned char *packet, size_t size); + void datatx(void *callback_state, unsigned char *packet, size_t *size); +} + +namespace gr { + namespace vocoder { + + class freedv_rx_ss_impl : public freedv_rx_ss + { + private: + short *d_speech_out; + short *d_demod_in; + struct freedv *d_freedv; + int d_nin, d_nout, d_frame; + struct freedv_rx_callback_state d_cb_state; + struct MODEM_STATS d_stats; + int d_mode; + int d_sync; + int d_total_bits; + int d_total_bit_errors; + float d_snr_est; + float d_squelch_thresh; + int d_speech_samples; + int d_max_modem_samples; + float d_clock_offset; + int d_use_codecrx; + struct CODEC2 *d_c2 = NULL; + + public: + freedv_rx_ss_impl(int mode, float squelch_thresh); + ~freedv_rx_ss_impl(); + + void set_squelch_thresh(float squelch_thresh); + float squelch_thresh(); + + // Where all the action really happens + void forecast(int noutput_items, gr_vector_int &ninput_items_required); + + int general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace vocoder */ +} /* namespace gr */ + +#endif /* INCLUDED_VOCODER_FREEDV_RX_SS_IMPL_H */ diff --git a/gr-vocoder/lib/freedv_tx_ss_impl.cc b/gr-vocoder/lib/freedv_tx_ss_impl.cc new file mode 100644 index 0000000000..a375510050 --- /dev/null +++ b/gr-vocoder/lib/freedv_tx_ss_impl.cc @@ -0,0 +1,98 @@ +/* -*- c++ -*- */ +/* + * Copyright 2016 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "freedv_tx_ss_impl.h" + +#include <gnuradio/io_signature.h> +#include <stdexcept> +#include <iostream> +#include <iomanip> + +extern "C" { + char + get_next_tx_char(void *callback_state) + { + char c; + struct freedv_tx_callback_state* pstate; + + pstate = (struct freedv_tx_callback_state*)callback_state; + c = *pstate->ptx_str++; + + if (*pstate->ptx_str == 0) { + pstate->ptx_str = pstate->tx_str; + c = 0x0d; // FreeDV uses Carriage Return termination + } + + return c; + } +} + +namespace gr { + namespace vocoder { + + freedv_tx_ss::sptr + freedv_tx_ss::make(int mode, const std::string msg_txt) + { + return gnuradio::get_initial_sptr + (new freedv_tx_ss_impl(mode, msg_txt)); + } + + freedv_tx_ss_impl::freedv_tx_ss_impl(int mode, const std::string msg_txt) + : sync_block("vocoder_freedv_tx_ss", + io_signature::make(1, 1, sizeof(short)), + io_signature::make(1, 1, sizeof(short))), + d_mode(mode), d_msg_text(msg_txt) + { + if((d_freedv = freedv_open(mode)) == NULL) + throw std::runtime_error("freedv_tx_ss_impl: freedv_open failed"); + snprintf(d_cb_state.tx_str,79,"%s",d_msg_text.c_str()); + d_cb_state.ptx_str = d_cb_state.tx_str; + freedv_set_callback_txt(d_freedv, NULL, get_next_tx_char, (void *) &d_cb_state); + d_nom_modem_samples = freedv_get_n_nom_modem_samples(d_freedv); + set_output_multiple(d_nom_modem_samples); + } + + freedv_tx_ss_impl::~freedv_tx_ss_impl() + { + freedv_close(d_freedv); + } + + int + freedv_tx_ss_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + short *in = (short*)input_items[0]; + short *out = (short*)output_items[0]; + int i; + + for(i=0;i<(noutput_items/d_nom_modem_samples);i++) + freedv_tx(d_freedv, &(out[i*d_nom_modem_samples]), &(in[i*d_nom_modem_samples])); + return noutput_items; + } + + } /* namespace vocoder */ +} /* namespace gr */ diff --git a/gr-vocoder/lib/freedv_tx_ss_impl.h b/gr-vocoder/lib/freedv_tx_ss_impl.h new file mode 100644 index 0000000000..a023b67f5b --- /dev/null +++ b/gr-vocoder/lib/freedv_tx_ss_impl.h @@ -0,0 +1,72 @@ +/* -*- c++ -*- */ +/* + * Copyright 2016 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_VOCODER_FREEDV_TX_SS_IMPL_H +#define INCLUDED_VOCODER_FREEDV_TX_SS_IMPL_H + +#include <gnuradio/vocoder/freedv_tx_ss.h> + +extern "C" { + struct freedv_tx_callback_state { + char tx_str[80]; + char *ptx_str; + int calls; + }; + char get_next_tx_char(void *callback_state); + void get_next_proto(void *callback_state,char *proto_bits); + void datarx(void *callback_state, unsigned char *packet, size_t size); + void datatx(void *callback_state, unsigned char *packet, size_t *size); +} + +namespace gr { + namespace vocoder { + + class freedv_tx_ss_impl : public freedv_tx_ss + { + private: + short *d_speech_in; + short *d_mod_out; + struct freedv_tx_callback_state d_cb_state; + struct freedv *d_freedv; + int d_mode; + float d_squelch_thresh; + int d_speech_samples; + int d_nom_modem_samples; + int d_use_codectx; + int d_use_datatx; + std::string d_msg_text; + struct CODEC2 *d_c2; + + public: + freedv_tx_ss_impl(int mode, const std::string txt_msg); + ~freedv_tx_ss_impl(); + + // Where all the action really happens + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace vocoder */ +} /* namespace gr */ + +#endif /* INCLUDED_VOCODER_FREEDV_TX_SS_IMPL_H */ diff --git a/gr-vocoder/swig/CMakeLists.txt b/gr-vocoder/swig/CMakeLists.txt index 8597fb115c..60f2f47329 100644 --- a/gr-vocoder/swig/CMakeLists.txt +++ b/gr-vocoder/swig/CMakeLists.txt @@ -37,6 +37,10 @@ if(LIBCODEC2_FOUND) list(APPEND GR_SWIG_FLAGS "-DLIBCODEC2_FOUND") endif(LIBCODEC2_FOUND) +if(LIBCODEC2_HAS_FREEDV_API) + list(APPEND GR_SWIG_FLAGS "-DLIBCODEC2_HAS_FREEDV_API") +endif(LIBCODEC2_HAS_FREEDV_API) + if(LIBGSM_FOUND) list(APPEND GR_SWIG_FLAGS "-DLIBGSM_FOUND") endif(LIBGSM_FOUND) diff --git a/gr-vocoder/swig/vocoder_swig.i b/gr-vocoder/swig/vocoder_swig.i index 43d0d1f79b..1bf451539d 100644 --- a/gr-vocoder/swig/vocoder_swig.i +++ b/gr-vocoder/swig/vocoder_swig.i @@ -85,6 +85,25 @@ GR_SWIG_BLOCK_MAGIC2(vocoder, codec2_decode_ps); GR_SWIG_BLOCK_MAGIC2(vocoder, codec2_encode_sp); #endif +#ifdef LIBCODEC2_HAS_FREEDV_API +%{ +#include <codec2/freedv_api.h> +#include "gnuradio/vocoder/freedv_api.h" +#include "gnuradio/vocoder/freedv_rx_ss.h" +#include "gnuradio/vocoder/freedv_tx_ss.h" +%} + +%ignore freedv_set_smooth_symbols; +%ignore freedv_set_clip; +%include <codec2/freedv_api.h> +%include "gnuradio/vocoder/freedv_api.h" +%include "gnuradio/vocoder/freedv_rx_ss.h" +%include "gnuradio/vocoder/freedv_tx_ss.h" + +GR_SWIG_BLOCK_MAGIC2(vocoder, freedv_rx_ss); +GR_SWIG_BLOCK_MAGIC2(vocoder, freedv_tx_ss); +#endif + #ifdef LIBGSM_FOUND %{ #include "gnuradio/vocoder/gsm_fr_decode_ps.h" |