-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpcm1subline.cpp
More file actions
231 lines (202 loc) · 5.01 KB
/
pcm1subline.cpp
File metadata and controls
231 lines (202 loc) · 5.01 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#include "pcm1subline.h"
PCM1SubLine::PCM1SubLine()
{
clear();
}
PCM1SubLine::PCM1SubLine(const PCM1SubLine &in_object)
{
// Copy misc. field.
frame_number = in_object.frame_number;
line_number = in_object.line_number;
picked_bits_left = in_object.picked_bits_left;
picked_bits_right = in_object.picked_bits_right;
line_part = in_object.line_part;
bw_set = in_object.bw_set;
crc = in_object.crc;
// Copy data words.
for(uint8_t i=0;i<WORD_CNT;i++)
{
words[i] = in_object.words[i];
}
}
PCM1SubLine& PCM1SubLine::operator= (const PCM1SubLine &in_object)
{
if(this==&in_object) return *this;
// Copy misc. field.
frame_number = in_object.frame_number;
line_number = in_object.line_number;
picked_bits_left = in_object.picked_bits_left;
picked_bits_right = in_object.picked_bits_right;
line_part = in_object.line_part;
bw_set = in_object.bw_set;
crc = in_object.crc;
// Copy data words.
for(uint8_t i=0;i<WORD_CNT;i++)
{
words[i] = in_object.words[i];
}
return *this;
}
//------------------------ Reset object.
void PCM1SubLine::clear()
{
frame_number = line_number = 0;
picked_bits_left = picked_bits_right = 0;
setLinePart(PART_LEFT);
setBWLevels(false);
setCRCValid(false);
setSilent();
}
//------------------------ Zero out all data words.
void PCM1SubLine::setSilent()
{
for(uint8_t i=WORD_L;i<=WORD_R;i++)
{
words[i] = PCM1Line::BIT_RANGE_POS;
}
}
//------------------------ Copy the word into the object.
void PCM1SubLine::setWord(uint8_t index, uint16_t in_word)
{
if(index<WORD_CNT)
{
words[index] = in_word&DATA_WORD_MASK;
}
}
//------------------------ Copy word for the left channel into object.
void PCM1SubLine::setLeft(uint16_t in_word)
{
setWord(WORD_L, in_word);
}
//------------------------ Copy word for the right channel into object.
void PCM1SubLine::setRight(uint16_t in_word)
{
setWord(WORD_R, in_word);
}
//------------------------ Set part of the source video line.
void PCM1SubLine::setLinePart(uint8_t index)
{
if(index<PART_MAX)
{
line_part = index;
}
}
//------------------------ Set presence of BLACK and WHITE levels.
void PCM1SubLine::setBWLevels(bool bw_ok)
{
bw_set = bw_ok;
}
//------------------------ Set validity of the words.
void PCM1SubLine::setCRCValid(bool crc_ok)
{
crc = crc_ok;
}
//------------------------ Were BLACK and WHITE levels set for the line?
bool PCM1SubLine::hasBWSet()
{
return bw_set;
}
//------------------------ Were the leftmost word's bits picked during binarization?
bool PCM1SubLine::hasPickedLeft()
{
if(picked_bits_left>0)
{
return true;
}
return false;
}
//------------------------ Were the rightmost word's bits picked during binarization?
bool PCM1SubLine::hasPickedRight()
{
if(picked_bits_right>0)
{
return true;
}
return false;
}
//------------------------ Check if words are marked as valid.
bool PCM1SubLine::isCRCValid()
{
return crc;
}
//------------------------ Get word data by its index.
uint16_t PCM1SubLine::getWord(uint8_t index)
{
if(index<WORD_CNT)
{
return words[index];
}
return 0;
}
//------------------------ Get left sample word.
uint16_t PCM1SubLine::getLeft()
{
return getWord(WORD_L);
}
//------------------------ Get right sample word.
uint16_t PCM1SubLine::getRight()
{
return getWord(WORD_R);
}
//------------------------ Get part of the source video line.
uint8_t PCM1SubLine::getLinePart()
{
return line_part;
}
//------------------------ Convert PCM data to string for debug.
std::string PCM1SubLine::dumpWordsString()
{
std::string text_out;
uint8_t ind, bit_pos;
// Printing 13 bit words data.
for(ind=WORD_L;ind<=WORD_R;ind++)
{
bit_pos = BITS_PER_WORD;
do
{
bit_pos--;
if((ind==WORD_L)&&(bit_pos>=(BITS_PER_WORD-picked_bits_left)))
{
if((words[ind]&(1<<bit_pos))==0)
{
text_out += DUMP_BIT_ZERO_BAD;
}
else
{
text_out += DUMP_BIT_ONE_BAD;
}
}
else
{
if((words[ind]&(1<<bit_pos))==0)
{
text_out += DUMP_BIT_ZERO;
}
else
{
text_out += DUMP_BIT_ONE;
}
}
}
while(bit_pos>0);
}
return text_out;
}
//------------------------ Output full information about the line.
std::string PCM1SubLine::dumpContentString()
{
std::string text_out;
char c_buf[256];
sprintf(c_buf, "F[%03u] L[%03u] P[%01u] ", (unsigned int)frame_number, line_number, line_part);
text_out += c_buf;
text_out += dumpWordsString();
if(isCRCValid()==false)
{
text_out += " BD CRC!";
}
else
{
text_out += " CRC OK";
}
return text_out;
}