SoDaRadio-5.0.3-master:8901fb5
CWGenerator.hxx
Go to the documentation of this file.
1 /*
2 Copyright (c) 2012,2013,2014 Matthew H. Reilly (kb1vc)
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8 
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 #ifndef CW_GENERATOR_HDR
29 #define CW_GENERATOR_HDR
30 
31 #include "SoDaBase.hxx"
32 #include "MultiMBox.hxx"
33 #include "Command.hxx"
34 #include "Params.hxx"
35 #include <map>
36 
37 namespace SoDa {
44  class CWGenerator {
45  public:
52  CWGenerator(DatMBox * cw_env_stream, double _samp_rate, unsigned int _env_buf_len);
53 
58  void setCWSpeed(unsigned int wpm);
59 
64  unsigned int getCWSpeed() { return words_per_minute; }
65 
70  bool readyForMore();
71 
77  bool sendChar(char c);
78 
79  private:
80 
86  void appendToOut(const float * v, unsigned int vlen);
87 
91  void flushBuffer();
92 
96  void clearBuffer();
97 
103  SoDaBuf * sb = NULL;
104  if(env_stream != NULL) {
105  sb = env_stream->alloc();
106  }
107  if(sb == NULL) {
108  sb = new SoDaBuf(env_buf_len);
109  }
110  return sb;
111  }
112 
116  void initMorseMap();
117 
118  // configuration params.
120  double sample_rate;
121  unsigned int env_buf_len;
122 
123  // timing parameters
124  unsigned int words_per_minute;
125  unsigned int edge_sample_count;
126 
127  unsigned int bufs_per_sec;
128 
129  // envelopes are float buffers.
130  float * dit;
131  unsigned int dit_len;
132  float * dah;
133  unsigned int dah_len;
135  unsigned int ics_len;
137  unsigned int first_iws_len;
138  unsigned int iws_len;
139 
140  // edges are float buffers too
141  float * rising_edge;
142  float * falling_edge;
143 
144  static std::map<char, std::string> morse_map;
145 
146  // current output buffer
148  unsigned int cur_buf_idx;
149  unsigned int cur_buf_len;
150 
151  // state of the translator
152  bool in_digraph;
154  };
155 }
156 
157 #endif
float * inter_char_space
prototype space between characters
The Baseclass for all SoDa objects, and useful commonly used classes.
unsigned int words_per_minute
unsigned int env_buf_len
the length of an envelope buffer
unsigned int bufs_per_sec
number of envelope buffers required per second.
bool in_digraph
if true, we&#39;re sending a two-character (no inter-char space) sequence (like _AR)
unsigned int cur_buf_len
how much of the buffer is unfilled?
float * dah
prototype dah buffer
unsigned int first_iws_len
number of samples in prototype space between words
void flushBuffer()
push the current buffer out to the transmitter, filling it with zeros
The Buffer Class.
Definition: SoDaBase.hxx:72
bool last_was_space
if true, next interword space should be a little short
float * inter_word_space
prototype space between words
unsigned int getCWSpeed()
tell us what the current CW speed is
Definition: CWGenerator.hxx:64
void setCWSpeed(unsigned int wpm)
set the speed of the cw stream in words per minute
float * dit
prototype dit buffer
double sample_rate
we need to know how long a sample is (in time)
float * rising_edge
a gentle shape for the leading edge of a pulse
bool sendChar(char c)
encode a character into the envelope buffer
void initMorseMap()
setup the mapping from ascii character to morse sequence
DatMBox * env_stream
this is the stream we send envelope buffers into.
unsigned int ics_len
number of samples in prototype space between characters
unsigned int dit_len
number of samples in prototype dit
SoDaBuf * getFreeSoDaBuf()
get an envelope that we can fill in
float * falling_edge
a gentle shape for the trailing edge of a pulse
void clearBuffer()
empty the current envelope, don&#39;t send it along to the TX unit
unsigned int edge_sample_count
edges are &#39;pre-built&#39; this is the length of an edge, in samples
SoDaBuf * cur_buf
the current envelope to be filled in
unsigned int dah_len
number of samples in prototype dah
bool readyForMore()
check envelope stream to see if we have less than 1 second&#39;s worth of stuff enqueued ...
Definition: CWGenerator.cxx:92
A text to morse envelope converter.
Definition: CWGenerator.hxx:44
void appendToOut(const float *v, unsigned int vlen)
add a buffer of envelope pieces to the outgoing envelope buffer
unsigned int cur_buf_idx
where are we in the buffer?
CWGenerator(DatMBox *cw_env_stream, double _samp_rate, unsigned int _env_buf_len)
Constructor.
Definition: CWGenerator.cxx:41
static std::map< char, std::string > morse_map
map from ascii character to dits-and-dahs
unsigned int iws_len
if space is repeated, number of samples in prototype space between words