From e36c0f19b2c6e6d16bb9bb5c57bdd0c8b9382f5b Mon Sep 17 00:00:00 2001 From: Vanya Sergeev Date: Wed, 17 Aug 2016 02:39:18 -0700 Subject: [PATCH] blocks/sources/hackrf: fix 8-bit unsigned to float sample conversion this block presumed HackRF samples were encoded as unsigned 8-bit values, with negative values from 0 - 127, zero at 128, and positive values from 129 to 255, but the samples are actually signed 8-bit values in two's complement representation. --- radio/blocks/sources/hackrf.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/radio/blocks/sources/hackrf.lua b/radio/blocks/sources/hackrf.lua index 0813d2b2b..7cfb53fda 100644 --- a/radio/blocks/sources/hackrf.lua +++ b/radio/blocks/sources/hackrf.lua @@ -213,10 +213,10 @@ local function read_callback_factory(...) -- Resize output vector out:resize(transfer.valid_length/2) - -- Convert complex u8 in buf to complex floats in output vector + -- Convert complex s8 in buf to complex floats in output vector for i = 0, out.length-1 do - out.data[i].real = (transfer.buffer[2*i] - 127.5) * (1/127.5) - out.data[i].imag = (transfer.buffer[2*i+1] - 127.5) * (1/127.5) + out.data[i].real = ffi.cast("int8_t *", transfer.buffer)[2*i] * (1/127.5) + out.data[i].imag = ffi.cast("int8_t *", transfer.buffer)[2*i+1] * (1/127.5) end -- Write to each output fd