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
|
/* -*- 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.
*/
#include "bbframe_ldpc.h"
#include "codings/dvb-s2/ldpc/dvb_s2_tables.hh"
#include <cstring>
namespace dvbs2
{
BBFrameLDPC::BBFrameLDPC(dvbs2_framesize_t framesize, dvbs2_code_rate_t rate)
{
if (framesize == FECFRAME_NORMAL)
{
switch (rate)
{
case C1_4:
ldpc = new LDPC<DVB_S2_TABLE_B1>();
break;
case C1_3:
ldpc = new LDPC<DVB_S2_TABLE_B2>();
break;
case C2_5:
ldpc = new LDPC<DVB_S2_TABLE_B3>();
break;
case C1_2:
ldpc = new LDPC<DVB_S2_TABLE_B4>();
break;
case C3_5:
ldpc = new LDPC<DVB_S2_TABLE_B5>();
break;
case C2_3:
ldpc = new LDPC<DVB_S2_TABLE_B6>();
break;
case C3_4:
ldpc = new LDPC<DVB_S2_TABLE_B7>();
break;
case C4_5:
ldpc = new LDPC<DVB_S2_TABLE_B8>();
break;
case C5_6:
ldpc = new LDPC<DVB_S2_TABLE_B9>();
break;
case C8_9:
ldpc = new LDPC<DVB_S2_TABLE_B10>();
break;
case C9_10:
ldpc = new LDPC<DVB_S2_TABLE_B11>();
break;
default:
break;
}
}
else if (framesize == FECFRAME_SHORT)
{
switch (rate)
{
case C1_4:
ldpc = new LDPC<DVB_S2_TABLE_C1>();
break;
case C1_3:
ldpc = new LDPC<DVB_S2_TABLE_C2>();
break;
case C2_5:
ldpc = new LDPC<DVB_S2_TABLE_C3>();
break;
case C1_2:
ldpc = new LDPC<DVB_S2_TABLE_C4>();
break;
case C3_5:
ldpc = new LDPC<DVB_S2_TABLE_C5>();
break;
case C2_3:
ldpc = new LDPC<DVB_S2_TABLE_C6>();
break;
case C3_4:
ldpc = new LDPC<DVB_S2_TABLE_C7>();
break;
case C4_5:
ldpc = new LDPC<DVB_S2_TABLE_C8>();
break;
case C5_6:
ldpc = new LDPC<DVB_S2_TABLE_C9>();
break;
case C8_9:
ldpc = new LDPC<DVB_S2_TABLE_C10>();
break;
default:
break;
}
}
decoder.init(ldpc);
encoder.init(ldpc);
aligned_buffer = new simd_type[68400];
}
BBFrameLDPC::~BBFrameLDPC()
{
delete ldpc;
}
int BBFrameLDPC::decode(int8_t *frame, int max_trials)
{
int trials = decoder((void *)aligned_buffer, (code_type *)frame, max_trials);
if (trials < 0)
return trials;
else
return max_trials - trials;
}
void BBFrameLDPC::encode(uint8_t *frame)
{
int8_t *soft_buffer = new int8_t[ldpc->code_len()];
// Convert to soft
for (int i = 0; i < ldpc->data_len(); i++)
soft_buffer[i] = ((frame[i / 8] >> (7 - (i % 8))) & 1) ? 127 : -127;
encoder(soft_buffer, &soft_buffer[ldpc->data_len()]);
// Repack to bytes
memset(&frame[ldpc->data_len() / 8], 0, (ldpc->code_len() - ldpc->data_len()) / 8);
for (int i = 0; i < (ldpc->code_len() - ldpc->data_len()); i++)
frame[(ldpc->data_len() / 8) + i / 8] = frame[(ldpc->data_len() / 8) + i / 8] << 1 | (soft_buffer[ldpc->data_len() + i] < 0);
delete[] soft_buffer;
}
}
|