Skip to content

Commit

Permalink
Clean up interleaver
Browse files Browse the repository at this point in the history
  • Loading branch information
Cam K. committed May 15, 2024
1 parent de2c20f commit 9c05148
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions lib/interleaver.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@
void cats_interleave(uint8_t* data, size_t len)
{
uint8_t buf[len];
int bitIndex = 0;
int bit_index = 0;
for(int i = 0; i < 32; i++) {
for(int j = 0; j < len*8; j += 32) {
if(i+j >= len*8)
for(int j = 0; j < len * 8; j += 32) {
if(i+j >= len * 8) {
continue;
}

if(GET_BIT(data[(i+j)/8], (i+j)%8))
SET_BIT(buf[bitIndex/8], bitIndex%8);
else
CLEAR_BIT(buf[bitIndex/8], bitIndex%8);
if(GET_BIT(data[(i+j) / 8], (i+j) % 8)) {
SET_BIT(buf[bit_index / 8], bit_index % 8);
}
else {
CLEAR_BIT(buf[bit_index / 8], bit_index % 8);
}

bitIndex++;
bit_index++;
}
}
memcpy(data, buf, len);
Expand All @@ -28,18 +31,21 @@ void cats_interleave(uint8_t* data, size_t len)
void cats_deinterleave(uint8_t* data, size_t len)
{
uint8_t buf[len];
int bitIndex = 0;
int bit_index = 0;
for(int i = 0; i < 32; i++) {
for(int j = 0; j < len*8; j+= 32) {
if(i+j >= len*8)
for(int j = 0; j < len * 8; j+= 32) {
if(i+j >= len * 8) {
continue;
}

if(GET_BIT(data[bitIndex/8], bitIndex%8))
SET_BIT(buf[(i+j)/8], (i+j)%8);
else
CLEAR_BIT(buf[(i+j)/8], (i+j)%8);
if(GET_BIT(data[bit_index / 8], bit_index % 8)) {
SET_BIT(buf[(i+j) / 8], (i+j) % 8);
}
else {
CLEAR_BIT(buf[(i+j) / 8], (i+j) % 8);
}

bitIndex++;
bit_index++;
}
}
memcpy(data, buf, len);
Expand Down

0 comments on commit 9c05148

Please sign in to comment.