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
|
/* -*- c++ -*- */
/*
* Copyright 2018 Ron Economos.
*
* This 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.
*
* This software 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 this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
/*
* This file has been adapted from https://github.com/drmpeg/gr-dvbs2rx
*/
#include "bbframe_descramble.h"
#include <algorithm>
namespace dvbs2
{
BBFrameDescrambler::BBFrameDescrambler(dvbs2_framesize_t framesize, dvbs2_code_rate_t rate)
{
if (framesize == FECFRAME_NORMAL)
{
switch (rate)
{
case C1_4:
kbch = 16008;
break;
case C1_3:
kbch = 21408;
break;
case C2_5:
kbch = 25728;
break;
case C1_2:
kbch = 32208;
break;
case C3_5:
kbch = 38688;
break;
case C2_3:
kbch = 43040;
break;
case C3_4:
kbch = 48408;
break;
case C4_5:
kbch = 51648;
break;
case C5_6:
kbch = 53840;
break;
case C8_9:
kbch = 57472;
break;
case C9_10:
kbch = 58192;
break;
default:
kbch = 0;
break;
}
}
else if (framesize == FECFRAME_SHORT)
{
switch (rate)
{
case C1_4:
kbch = 3072;
break;
case C1_3:
kbch = 5232;
break;
case C2_5:
kbch = 6312;
break;
case C1_2:
kbch = 7032;
break;
case C3_5:
kbch = 9552;
break;
case C2_3:
kbch = 10632;
break;
case C3_4:
kbch = 11712;
break;
case C4_5:
kbch = 12432;
break;
case C5_6:
kbch = 13152;
break;
case C8_9:
kbch = 14232;
break;
default:
kbch = 0;
break;
}
}
init();
}
BBFrameDescrambler::~BBFrameDescrambler()
{
}
void BBFrameDescrambler::init()
{
std::fill(bb_derandomise, &bb_derandomise[FRAME_SIZE_NORMAL / 8], 0);
int sr = 0x4A80;
for (int i = 0; i < FRAME_SIZE_NORMAL; i++)
{
int b = ((sr) ^ (sr >> 1)) & 1;
bb_derandomise[i / 8] = b << (7 - (i % 8)) | bb_derandomise[i / 8];
sr >>= 1;
if (b)
sr |= 0x4000;
}
}
int BBFrameDescrambler::work(uint8_t *frame)
{
for (int j = 0; j < (int)kbch / 8; ++j)
frame[j] = frame[j] ^ bb_derandomise[j];
return 0;
}
}
|