File: freedv_tx_ss_impl.cc

package info (click to toggle)
gnuradio 3.7.13.4-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 45,992 kB
  • sloc: cpp: 155,723; python: 88,934; xml: 42,165; ansic: 41,036; fortran: 927; asm: 803; sh: 224; lisp: 31; makefile: 17
file content (141 lines) | stat: -rw-r--r-- 4,110 bytes parent folder | download
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* -*- c++ -*- */
/*
 * Copyright 2016-2018 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, int interleave_frames)
    {
      return gnuradio::get_initial_sptr
        (new freedv_tx_ss_impl(mode, msg_txt, interleave_frames));
    }

    freedv_tx_ss_impl::freedv_tx_ss_impl(int mode, const std::string msg_txt, int interleave_frames)
      : 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), d_interleave_frames(interleave_frames)
    {
#ifdef FREEDV_MODE_700D
      if (mode == FREEDV_MODE_700D) {
      d_adv.interleave_frames = interleave_frames;
      if((d_freedv = freedv_open_advanced(mode, &d_adv)) ==NULL)
	throw std::runtime_error("freedv_tx_ss_impl: freedv_open_advanced failed");
      } else {
	if((d_freedv = freedv_open(mode)) == NULL)
	  throw std::runtime_error("freedv_tx_ss_impl: freedv_open failed");
      }
#else
      if((d_freedv = freedv_open(mode)) == NULL)
        throw std::runtime_error("freedv_tx_ss_impl: freedv_open failed");
#endif
      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);
    }

    void freedv_tx_ss_impl::set_clip(int val)
    {
      d_clip = val;
#if defined(FREEDV_MODE_700C) || defined(FREEDV_MODE_700D)
      freedv_set_clip(d_freedv, d_clip);
#endif
    }

    void freedv_tx_ss_impl::set_clip(bool val)
    {
      if (val)
	freedv_tx_ss_impl::set_clip(1);
      else
	freedv_tx_ss_impl::set_clip(0);
    }

    void freedv_tx_ss_impl::set_tx_bpf(int val)
    {
      d_tx_bpf = val;
#ifdef FREEDV_MODE_700D
      freedv_set_tx_bpf(d_freedv, d_tx_bpf);
#endif
    }

    void freedv_tx_ss_impl::set_tx_bpf(bool val)
    {
      if (val)
	freedv_tx_ss_impl::set_tx_bpf(1);
      else
	freedv_tx_ss_impl::set_tx_bpf(0);
    }

    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 */