SoDaRadio-12.2.0-cut_dependencies:6c82803
Loading...
Searching...
No Matches
CWGenerator.hxx
Go to the documentation of this file.
1/*
2Copyright (c) 2012,2013,2014, 2025 Matthew H. Reilly (kb1vc)
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are
7met:
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
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28#pragma once
29
30#include "SoDaBase.hxx"
31#include "Command.hxx"
32#include "Params.hxx"
33#include <map>
34#include <memory>
35
36namespace SoDa {
43 class CWGenerator;
44 typedef std::shared_ptr<CWGenerator> CWGeneratorPtr;
45
47 protected:
54 CWGenerator(FDatMBoxPtr cw_env_stream, double _samp_rate, unsigned int _env_buf_len);
55
56 public:
57 static CWGeneratorPtr make(FDatMBoxPtr cw_env_stream,
58 double _samp_rate,
59 unsigned int _env_buf_len) {
60 auto ret = std::shared_ptr<CWGenerator>(new CWGenerator(cw_env_stream,
61 _samp_rate,
62 _env_buf_len));
63 return ret;
64 }
65
70 void setCWSpeed(unsigned int wpm);
71
76 unsigned int getCWSpeed() { return words_per_minute; }
77
83
89 bool sendChar(char c);
90
91 private:
92
97 void appendToOut(std::vector<float> & v);
98
103
108
113
114 // configuration params.
116 double sample_rate;
117 unsigned int env_buf_len;
118
119 // timing parameters
120 unsigned int words_per_minute;
121 unsigned int edge_sample_count;
122
123 unsigned int bufs_per_sec;
124
125 // envelopes are float buffers.
126 std::vector<float> dit;
127 std::vector<float> dah;
128 std::vector<float> inter_char_space;
129 std::vector<float> inter_word_space;
130
131 // edges are float buffers too
132 std::vector<float> rising_edge;
133 std::vector<float> falling_edge;
134
135 static std::map<char, std::string> morse_map;
136
137 // current output buffer
139 unsigned int cur_buf_idx;
140
141 // state of the translator
144 };
145}
146
The Baseclass for all SoDa objects, and useful commonly used classes.
unsigned int edge_sample_count
edges are 'pre-built' this is the length of an edge, in samples
std::vector< float > falling_edge
a gentle shape for the trailing edge of a pulse
FDatMBoxPtr env_stream
this is the stream we send envelope buffers into.
void flushBuffer()
push the current buffer out to the transmitter, filling it with zeros
bool sendChar(char c)
encode a character into the envelope buffer
void clearBuffer()
empty the current envelope, don't send it along to the TX unit
void setCWSpeed(unsigned int wpm)
set the speed of the cw stream in words per minute
void initMorseMap()
setup the mapping from ascii character to morse sequence
unsigned int cur_buf_idx
where are we in the buffer?
std::vector< float > inter_char_space
prototype space between characters
std::vector< float > dit
prototype dit buffer
unsigned int getCWSpeed()
tell us what the current CW speed is
bool in_digraph
if true, we're sending a two-character (no inter-char space) sequence (like _AR)
unsigned int env_buf_len
the length of an envelope buffer
bool readyForMore()
check envelope stream to see if we have less than 1 second's worth of stuff enqueued
unsigned int words_per_minute
unsigned int bufs_per_sec
number of envelope buffers required per second.
SoDa::FBufPtr cur_buf
the current envelope to be filled in
CWGenerator(FDatMBoxPtr cw_env_stream, double _samp_rate, unsigned int _env_buf_len)
Constructor.
std::vector< float > inter_word_space
prototype space between words
void appendToOut(std::vector< float > &v)
add a buffer of envelope pieces to the outgoing envelope buffer
static std::map< char, std::string > morse_map
map from ascii character to dits-and-dahs
std::vector< float > dah
prototype dah buffer
double sample_rate
we need to know how long a sample is (in time)
static CWGeneratorPtr make(FDatMBoxPtr cw_env_stream, double _samp_rate, unsigned int _env_buf_len)
std::vector< float > rising_edge
a gentle shape for the leading edge of a pulse
bool last_was_space
if true, next interword space should be a little short
std::shared_ptr< FBuf > FBufPtr
Definition SoDaBase.hxx:61
std::shared_ptr< CWGenerator > CWGeneratorPtr
std::shared_ptr< FDatMBox > FDatMBoxPtr
Definition SoDaBase.hxx:85