aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHoernchen <la@tfc-server.de>2014-02-20 19:04:00 +0100
committerDimitri Stolnikov <horiz0n@gmx.net>2014-02-20 19:47:20 +0100
commitcc083037fe4cd6d3b90cb59e35a44fba44aa95f3 (patch)
tree3526f352c2a60ac717ad0e502398e4f4302bf6e3
parent7a1f12cfcff1ecdfd91284f1f9ba3f9b59f33b94 (diff)
hackrf: signed samples, following commit fd77cfe8a6
-rw-r--r--lib/hackrf/hackrf_sink_c.cc28
-rw-r--r--lib/hackrf/hackrf_sink_c.h2
-rw-r--r--lib/hackrf/hackrf_source_c.cc8
3 files changed, 18 insertions, 20 deletions
diff --git a/lib/hackrf/hackrf_sink_c.cc b/lib/hackrf/hackrf_sink_c.cc
index 1bb6f7e..1017151 100644
--- a/lib/hackrf/hackrf_sink_c.cc
+++ b/lib/hackrf/hackrf_sink_c.cc
@@ -217,7 +217,7 @@ hackrf_sink_c::hackrf_sink_c (const std::string &args)
set_if_gain( 16 ); /* preset to a reasonable default (non-GRC use case) */
- _buf = (unsigned char *) malloc( BUF_LEN );
+ _buf = (char *) malloc( BUF_LEN );
cb_init( &_cbuf, _buf_num, BUF_LEN );
@@ -325,11 +325,9 @@ bool hackrf_sink_c::stop()
}
#ifdef USE_AVX
-void convert_avx(const float* inbuf, unsigned char* outbuf,const unsigned int count)
+void convert_avx(const float* inbuf, char* outbuf,const unsigned int count)
{
__m256 mulme = _mm256_set_ps(127.0f, 127.0f, 127.0f, 127.0f, 127.0f, 127.0f, 127.0f, 127.0f);
- __m128i addme = _mm_set_epi16(127, 127, 127, 127, 127, 127, 127, 127);
-
for(unsigned int i=0; i<count;i++){
__m256i itmp3 = _mm256_cvtps_epi32(_mm256_mul_ps(_mm256_loadu_ps(&inbuf[i*16+0]), mulme));
@@ -340,19 +338,19 @@ void convert_avx(const float* inbuf, unsigned char* outbuf,const unsigned int co
__m128i a3 = _mm256_extractf128_si256(itmp4, 1);
__m128i a2 = _mm256_castsi256_si128(itmp4);
- __m128i outshorts1 = _mm_add_epi16(_mm_packs_epi32(a0, a1), addme);
- __m128i outshorts2 = _mm_add_epi16(_mm_packs_epi32(a2, a3), addme);
- __m128i outbytes = _mm_packus_epi16(outshorts1, outshorts2);
+ __m128i outshorts1 = _mm_packs_epi32(a0, a1);
+ __m128i outshorts2 = _mm_packs_epi32(a2, a3);
+
+ __m128i outbytes = _mm_packs_epi16(outshorts1, outshorts2);
_mm_storeu_si128 ((__m128i*)&outbuf[i*16], outbytes);
}
}
#elif USE_SSE2
-void convert_sse2(const float* inbuf, unsigned char* outbuf,const unsigned int count)
+void convert_sse2(const float* inbuf, char* outbuf,const unsigned int count)
{
const register __m128 mulme = _mm_set_ps( 127.0f, 127.0f, 127.0f, 127.0f );
- __m128i addme = _mm_set_epi16( 127, 127, 127, 127, 127, 127, 127, 127);
__m128 itmp1,itmp2,itmp3,itmp4;
__m128i otmp1,otmp2,otmp3,otmp4;
@@ -371,20 +369,20 @@ void convert_sse2(const float* inbuf, unsigned char* outbuf,const unsigned int c
otmp3 = _mm_cvtps_epi32(itmp3);
otmp4 = _mm_cvtps_epi32(itmp4);
- outshorts1 = _mm_add_epi16(_mm_packs_epi32(otmp1, otmp2), addme);
- outshorts2 = _mm_add_epi16(_mm_packs_epi32(otmp3, otmp4), addme);
+ outshorts1 = _mm_packs_epi32(otmp1, otmp2);
+ outshorts2 = _mm_packs_epi32(otmp3, otmp4);
- outbytes = _mm_packus_epi16(outshorts1, outshorts2);
+ outbytes = _mm_packs_epi16(outshorts1, outshorts2);
_mm_storeu_si128 ((__m128i*)&outbuf[i*16], outbytes);
}
}
#endif
-void convert_default(float* inbuf, unsigned char* outbuf,const unsigned int count)
+void convert_default(float* inbuf, char* outbuf,const unsigned int count)
{
for(unsigned int i=0; i<count;i++){
- outbuf[i]= inbuf[i]*127+127;
+ outbuf[i]= inbuf[i]*127;
}
}
@@ -401,7 +399,7 @@ int hackrf_sink_c::work( int noutput_items,
_buf_cond.wait( lock );
}
- unsigned char *buf = _buf + _buf_used;
+ char *buf = _buf + _buf_used;
unsigned int prev_buf_used = _buf_used;
unsigned int remaining = (BUF_LEN-_buf_used)/2; //complex
diff --git a/lib/hackrf/hackrf_sink_c.h b/lib/hackrf/hackrf_sink_c.h
index f4c533f..7750026 100644
--- a/lib/hackrf/hackrf_sink_c.h
+++ b/lib/hackrf/hackrf_sink_c.h
@@ -134,7 +134,7 @@ private:
// gr::thread::thread _thread;
circular_buffer_t _cbuf;
- unsigned char *_buf;
+ char *_buf;
unsigned int _buf_num;
unsigned int _buf_used;
boost::mutex _buf_mutex;
diff --git a/lib/hackrf/hackrf_source_c.cc b/lib/hackrf/hackrf_source_c.cc
index 022af7f..6a06f15 100644
--- a/lib/hackrf/hackrf_source_c.cc
+++ b/lib/hackrf/hackrf_source_c.cc
@@ -120,11 +120,11 @@ hackrf_source_c::hackrf_source_c (const std::string &args)
// create a lookup table for gr_complex values
for (unsigned int i = 0; i <= 0xffff; i++) {
#ifdef BOOST_LITTLE_ENDIAN
- _lut.push_back( gr_complex( (float(i & 0xff) - 127.5f) * (1.0f/128.0f),
- (float(i >> 8) - 127.5f) * (1.0f/128.0f) ) );
+ _lut.push_back( gr_complex( (float(char(i & 0xff))) * (1.0f/128.0f),
+ (float(char(i >> 8))) * (1.0f/128.0f) ) );
#else // BOOST_BIG_ENDIAN
- _lut.push_back( gr_complex( (float(i >> 8) - 127.5f) * (1.0f/128.0f),
- (float(i & 0xff) - 127.5f) * (1.0f/128.0f) ) );
+ _lut.push_back( gr_complex( (float(char(i >> 8))) * (1.0f/128.0f),
+ (float(char(i & 0xff))) * (1.0f/128.0f) ) );
#endif
}