mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2026-10-04 14:51:50 +00:00
Replace C-style cast by C++ casts
This commit is contained in:
@@ -40,12 +40,14 @@ struct byte_2bit_struct
|
||||
signed sample_3:2; // <- 2 bits wide only
|
||||
};
|
||||
|
||||
|
||||
union byte_and_samples
|
||||
{
|
||||
int8_t byte;
|
||||
byte_2bit_struct samples;
|
||||
};
|
||||
|
||||
|
||||
bool systemIsBigEndian()
|
||||
{
|
||||
union
|
||||
@@ -57,6 +59,7 @@ bool systemIsBigEndian()
|
||||
return test_int.c[0] == 1;
|
||||
}
|
||||
|
||||
|
||||
bool systemBytesAreBigEndian()
|
||||
{
|
||||
byte_and_samples b;
|
||||
@@ -65,6 +68,7 @@ bool systemBytesAreBigEndian()
|
||||
else return true;
|
||||
}
|
||||
|
||||
|
||||
void swapEndianness( int8_t const *in, std::vector< int8_t > &out, size_t item_size, unsigned int ninput_items )
|
||||
{
|
||||
unsigned int i;
|
||||
@@ -74,16 +78,17 @@ void swapEndianness( int8_t const *in, std::vector< int8_t > &out, size_t item_s
|
||||
size_t skip = item_size - 1;
|
||||
|
||||
for( i = 0; i < ninput_items; ++i )
|
||||
{
|
||||
k = j + skip;
|
||||
l = j;
|
||||
while( k >= l )
|
||||
{
|
||||
out[j++] = in[k--];
|
||||
k = j + skip;
|
||||
l = j;
|
||||
while( k >= l )
|
||||
{
|
||||
out[j++] = in[k--];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unpack_2bit_samples_sptr make_unpack_2bit_samples( bool big_endian_bytes,
|
||||
size_t item_size,
|
||||
bool big_endian_items,
|
||||
@@ -97,6 +102,7 @@ unpack_2bit_samples_sptr make_unpack_2bit_samples( bool big_endian_bytes,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpack_2bit_samples::unpack_2bit_samples( bool big_endian_bytes,
|
||||
size_t item_size,
|
||||
bool big_endian_items,
|
||||
@@ -111,7 +117,6 @@ unpack_2bit_samples::unpack_2bit_samples( bool big_endian_bytes,
|
||||
swap_endian_items_(false),
|
||||
reverse_interleaving_(reverse_interleaving)
|
||||
{
|
||||
|
||||
bool big_endian_system = systemIsBigEndian();
|
||||
|
||||
// Only swap the item bytes if the item size > 1 byte and the system
|
||||
@@ -122,30 +127,31 @@ unpack_2bit_samples::unpack_2bit_samples( bool big_endian_bytes,
|
||||
bool big_endian_bytes_system = systemBytesAreBigEndian();
|
||||
|
||||
swap_endian_bytes_ = ( big_endian_bytes_system != big_endian_bytes_ );
|
||||
|
||||
}
|
||||
|
||||
|
||||
unpack_2bit_samples::~unpack_2bit_samples()
|
||||
{}
|
||||
|
||||
|
||||
int unpack_2bit_samples::work(int noutput_items,
|
||||
gr_vector_const_void_star &input_items,
|
||||
gr_vector_void_star &output_items)
|
||||
{
|
||||
signed char const *in = (signed char const *)input_items[0];
|
||||
int8_t *out = (int8_t*)output_items[0];
|
||||
signed char const *in = reinterpret_cast<signed char const *>(input_items[0]);
|
||||
int8_t *out = reinterpret_cast<int8_t*>(output_items[0]);
|
||||
|
||||
size_t ninput_bytes = noutput_items/4;
|
||||
size_t ninput_items = ninput_bytes/item_size_;
|
||||
|
||||
|
||||
// Handle endian swap if needed
|
||||
if( swap_endian_items_ )
|
||||
{
|
||||
work_buffer_.reserve( ninput_bytes );
|
||||
swapEndianness( in, work_buffer_, item_size_, ninput_items );
|
||||
{
|
||||
work_buffer_.reserve( ninput_bytes );
|
||||
swapEndianness( in, work_buffer_, item_size_, ninput_items );
|
||||
|
||||
in = const_cast< signed char const *> ( &work_buffer_[0] );
|
||||
}
|
||||
in = const_cast< signed char const *> ( &work_buffer_[0] );
|
||||
}
|
||||
|
||||
// Here the in pointer can be interpreted as a stream of bytes to be
|
||||
// converted. But we now have two possibilities:
|
||||
@@ -156,68 +162,63 @@ int unpack_2bit_samples::work(int noutput_items,
|
||||
int n = 0;
|
||||
|
||||
if( !reverse_interleaving_ )
|
||||
{
|
||||
if( swap_endian_bytes_ )
|
||||
{
|
||||
for(unsigned int i = 0; i < ninput_bytes; ++i)
|
||||
{
|
||||
// Read packed input sample (1 byte = 4 samples)
|
||||
raw_byte.byte = in[i];
|
||||
if( swap_endian_bytes_ )
|
||||
{
|
||||
for(unsigned 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++] = static_cast<int8_t>( 2*raw_byte.samples.sample_3 + 1 );
|
||||
out[n++] = static_cast<int8_t>( 2*raw_byte.samples.sample_2 + 1 );
|
||||
out[n++] = static_cast<int8_t>( 2*raw_byte.samples.sample_1 + 1 );
|
||||
out[n++] = static_cast<int8_t>( 2*raw_byte.samples.sample_0 + 1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(unsigned int i = 0; i < ninput_bytes; ++i )
|
||||
{
|
||||
// Read packed input sample (1 byte = 4 samples)
|
||||
raw_byte.byte = in[i];
|
||||
|
||||
}
|
||||
out[n++] = static_cast<int8_t>( 2*raw_byte.samples.sample_0 + 1 );
|
||||
out[n++] = static_cast<int8_t>( 2*raw_byte.samples.sample_1 + 1 );
|
||||
out[n++] = static_cast<int8_t>( 2*raw_byte.samples.sample_2 + 1 );
|
||||
out[n++] = static_cast<int8_t>( 2*raw_byte.samples.sample_3 + 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(unsigned 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
|
||||
{
|
||||
|
||||
if( swap_endian_bytes_ )
|
||||
{
|
||||
for(unsigned int i = 0; i < ninput_bytes; ++i)
|
||||
{
|
||||
// Read packed input sample (1 byte = 4 samples)
|
||||
raw_byte.byte = in[i];
|
||||
if( swap_endian_bytes_ )
|
||||
{
|
||||
for(unsigned 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_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++] = static_cast<int8_t>( 2*raw_byte.samples.sample_2 + 1 );
|
||||
out[n++] = static_cast<int8_t>( 2*raw_byte.samples.sample_3 + 1 );
|
||||
out[n++] = static_cast<int8_t>( 2*raw_byte.samples.sample_0 + 1 );
|
||||
out[n++] = static_cast<int8_t>( 2*raw_byte.samples.sample_1 + 1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(unsigned int i = 0; i < ninput_bytes; ++i )
|
||||
{
|
||||
// Read packed input sample (1 byte = 4 samples)
|
||||
raw_byte.byte = in[i];
|
||||
|
||||
}
|
||||
out[n++] = static_cast<int8_t>( 2*raw_byte.samples.sample_1 + 1 );
|
||||
out[n++] = static_cast<int8_t>( 2*raw_byte.samples.sample_0 + 1 );
|
||||
out[n++] = static_cast<int8_t>( 2*raw_byte.samples.sample_3 + 1 );
|
||||
out[n++] = static_cast<int8_t>( 2*raw_byte.samples.sample_2 + 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(unsigned 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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return noutput_items;
|
||||
}
|
||||
|
||||
@@ -47,21 +47,24 @@ unpack_byte_2bit_cpx_samples_sptr make_unpack_byte_2bit_cpx_samples()
|
||||
return unpack_byte_2bit_cpx_samples_sptr(new unpack_byte_2bit_cpx_samples());
|
||||
}
|
||||
|
||||
|
||||
unpack_byte_2bit_cpx_samples::unpack_byte_2bit_cpx_samples() : sync_interpolator("unpack_byte_2bit_cpx_samples",
|
||||
gr::io_signature::make(1, 1, sizeof(signed char)),
|
||||
gr::io_signature::make(1, 1, sizeof(short)),
|
||||
4)
|
||||
{}
|
||||
|
||||
|
||||
unpack_byte_2bit_cpx_samples::~unpack_byte_2bit_cpx_samples()
|
||||
{}
|
||||
|
||||
|
||||
int unpack_byte_2bit_cpx_samples::work(int noutput_items,
|
||||
gr_vector_const_void_star &input_items,
|
||||
gr_vector_void_star &output_items)
|
||||
{
|
||||
const signed char *in = (const signed char *)input_items[0];
|
||||
short *out = (short*)output_items[0];
|
||||
const signed char *in = reinterpret_cast<const signed char *>(input_items[0]);
|
||||
short *out = reinterpret_cast<short *>(output_items[0]);
|
||||
|
||||
byte_2bit_struct sample;
|
||||
int n = 0;
|
||||
@@ -91,16 +94,16 @@ int unpack_byte_2bit_cpx_samples::work(int noutput_items,
|
||||
signed char c = in[i];
|
||||
//I[n]
|
||||
sample.two_bit_sample = (c >> 4) & 3;
|
||||
out[n++] = (2*(short)sample.two_bit_sample + 1);
|
||||
out[n++] = (2 * static_cast<short>(sample.two_bit_sample) + 1);
|
||||
//Q[n]
|
||||
sample.two_bit_sample = (c >> 6) & 3;
|
||||
out[n++] = (2*(short)sample.two_bit_sample + 1);
|
||||
out[n++] = (2 * static_cast<short>(sample.two_bit_sample) + 1);
|
||||
//I[n+1]
|
||||
sample.two_bit_sample = c & 3;
|
||||
out[n++] = (2*(short)sample.two_bit_sample + 1);
|
||||
out[n++] = (2 * static_cast<short>(sample.two_bit_sample) + 1);
|
||||
//Q[n+1]
|
||||
sample.two_bit_sample = (c >> 2) & 3;
|
||||
out[n++] = (2*(short)sample.two_bit_sample + 1);
|
||||
out[n++] = (2 * static_cast<short>(sample.two_bit_sample) + 1);
|
||||
}
|
||||
return noutput_items;
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ int unpack_byte_2bit_samples::work(int noutput_items,
|
||||
gr_vector_const_void_star &input_items,
|
||||
gr_vector_void_star &output_items)
|
||||
{
|
||||
const signed char *in = (const signed char *)input_items[0];
|
||||
float *out = (float*)output_items[0];
|
||||
const signed char *in = reinterpret_cast<const signed char *>(input_items[0]);
|
||||
float *out = reinterpret_cast<float *>(output_items[0]);
|
||||
|
||||
byte_2bit_struct sample;
|
||||
int n = 0;
|
||||
|
||||
@@ -55,8 +55,8 @@ int unpack_intspir_1bit_samples::work(int noutput_items,
|
||||
gr_vector_const_void_star &input_items,
|
||||
gr_vector_void_star &output_items)
|
||||
{
|
||||
const signed int *in = (const signed int *)input_items[0];
|
||||
float *out = (float*)output_items[0];
|
||||
const signed int *in = reinterpret_cast<const signed int *>(input_items[0]);
|
||||
float *out = reinterpret_cast<float*>(output_items[0]);
|
||||
|
||||
int n = 0;
|
||||
int channel = 1;
|
||||
|
||||
Reference in New Issue
Block a user