1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-14 12:10:34 +00:00

Added interleaving reversal to unpack_2bit_samples

This commit is contained in:
Cillian O'Driscoll 2015-10-08 12:04:07 +01:00
parent f389fc5042
commit c20accbf26
2 changed files with 66 additions and 23 deletions

View File

@ -87,18 +87,21 @@ void swapEndianness( int8_t const *in, std::vector< int8_t > &out, size_t item_s
unpack_2bit_samples_sptr make_unpack_2bit_samples( bool big_endian_bytes,
size_t item_size,
bool big_endian_items )
bool big_endian_items,
bool reverse_interleaving )
{
return unpack_2bit_samples_sptr(
new unpack_2bit_samples( big_endian_bytes,
item_size,
big_endian_items )
big_endian_items,
reverse_interleaving )
);
}
unpack_2bit_samples::unpack_2bit_samples( bool big_endian_bytes,
size_t item_size,
bool big_endian_items )
bool big_endian_items,
bool reverse_interleaving )
: sync_interpolator("unpack_2bit_samples",
gr::io_signature::make(1, 1, item_size),
gr::io_signature::make(1, 1, sizeof(char)),
@ -106,7 +109,8 @@ unpack_2bit_samples::unpack_2bit_samples( bool big_endian_bytes,
big_endian_bytes_(big_endian_bytes),
item_size_(item_size),
big_endian_items_(big_endian_items),
swap_endian_items_(false)
swap_endian_items_(false),
reverse_interleaving_(reverse_interleaving)
{
bool big_endian_system = systemIsBigEndian();
@ -138,7 +142,7 @@ int unpack_2bit_samples::work(int noutput_items,
// Handle endian swap if needed
if( swap_endian_items_ )
{
work_buffer_.resize( ninput_bytes );
work_buffer_.reserve( ninput_bytes );
swapEndianness( in, work_buffer_, item_size_, ninput_items );
in = const_cast< signed char const *> ( &work_buffer_[0] );
@ -152,32 +156,67 @@ int unpack_2bit_samples::work(int noutput_items,
byte_and_samples raw_byte;
int n = 0;
if( swap_endian_bytes_ )
if( !reverse_interleaving_ )
{
for(int i = 0; i < ninput_bytes; ++i)
if( swap_endian_bytes_ )
{
// Read packed input sample (1 byte = 4 samples)
raw_byte.byte = in[i];
for(int i = 0; i < ninput_bytes; ++i)
{
// Read packed input sample (1 byte = 4 samples)
raw_byte.byte = in[i];
out[n++] = (int8_t)( 2*raw_byte.samples.sample_3 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_2 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_1 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_0 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_3 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_2 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_1 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_0 + 1 );
}
}
else
{
for( int i = 0; i < ninput_bytes; ++i )
{
// Read packed input sample (1 byte = 4 samples)
raw_byte.byte = in[i];
out[n++] = (int8_t)( 2*raw_byte.samples.sample_0 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_1 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_2 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_3 + 1 );
}
}
}
else
{
for( int i = 0; i < ninput_bytes; ++i )
if( swap_endian_bytes_ )
{
for(int i = 0; i < ninput_bytes; ++i)
{
// Read packed input sample (1 byte = 4 samples)
raw_byte.byte = in[i];
// Read packed input sample (1 byte = 4 samples)
raw_byte.byte = in[i];
out[n++] = (int8_t)( 2*raw_byte.samples.sample_2 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_3 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_0 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_1 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_0 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_1 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_2 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_3 + 1 );
}
}
else
{
for( int i = 0; i < ninput_bytes; ++i )
{
// Read packed input sample (1 byte = 4 samples)
raw_byte.byte = in[i];
out[n++] = (int8_t)( 2*raw_byte.samples.sample_1 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_0 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_3 + 1 );
out[n++] = (int8_t)( 2*raw_byte.samples.sample_2 + 1 );
}
}
}

View File

@ -76,7 +76,8 @@ typedef boost::shared_ptr<unpack_2bit_samples> unpack_2bit_samples_sptr;
unpack_2bit_samples_sptr make_unpack_2bit_samples( bool big_endian_bytes,
size_t item_size,
bool big_endian_items );
bool big_endian_items,
bool reverse_interleaving = false );
/*!
* \brief This class takes 2 bit samples that have been packed into bytes or
@ -89,12 +90,14 @@ private:
friend unpack_2bit_samples_sptr
make_unpack_2bit_samples_sptr( bool big_endian_bytes,
size_t item_size,
bool big_endian_items );
bool big_endian_items,
bool reverse_interleaving);
public:
unpack_2bit_samples( bool big_endianBytes,
size_t item_size,
bool big_endian_items );
bool big_endian_items,
bool reverse_interleaving );
~unpack_2bit_samples();
@ -108,6 +111,7 @@ private:
bool big_endian_items_;
bool swap_endian_items_;
bool swap_endian_bytes_;
bool reverse_interleaving_;
std::vector< int8_t > work_buffer_;
};