Loading...
Searching...
No Matches
ConverterPrimitives.hpp
Go to the documentation of this file.
#pragma once
#include <stdint.h>
namespace SoapySDR
{
const uint32_t U32_ZERO_OFFSET = uint32_t(1<<31);
const uint16_t U16_ZERO_OFFSET = uint16_t(1<<15);
const uint8_t U8_ZERO_OFFSET = uint8_t(1<<7);
const uint32_t S32_FULL_SCALE = uint32_t(1<<31);
const uint16_t S16_FULL_SCALE = uint16_t(1<<15);
const uint8_t S8_FULL_SCALE = uint8_t(1<<7);
// type conversion: float <> signed integers
inline int32_t F32toS32(float from){
return int32_t(from * S32_FULL_SCALE);
}
inline float S32toF32(int32_t from){
return float(from) / S32_FULL_SCALE;
}
inline int16_t F32toS16(float from){
return int16_t(from * S16_FULL_SCALE);
}
inline float S16toF32(int16_t from){
return float(from) / S16_FULL_SCALE;
}
inline int8_t F32toS8(float from){
return int8_t(from * S8_FULL_SCALE);
}
inline float S8toF32(int8_t from){
return float(from) / S8_FULL_SCALE;
}
// type conversion: offset binary <> two's complement (signed) integers
inline int32_t U32toS32(uint32_t from){
return int32_t(from - U32_ZERO_OFFSET);
}
inline uint32_t S32toU32(int32_t from){
return uint32_t(from) + U32_ZERO_OFFSET;
}
inline int16_t U16toS16(uint16_t from){
return int16_t(from - U16_ZERO_OFFSET);
}
inline uint16_t S16toU16(int16_t from){
return uint16_t(from) + U16_ZERO_OFFSET;
}
inline int8_t U8toS8(uint8_t from){
return int8_t(from - U8_ZERO_OFFSET);
}
inline uint8_t S8toU8(int8_t from){
return uint8_t(from) + U8_ZERO_OFFSET;
}
// size conversion: signed <> signed
inline int16_t S32toS16(int32_t from){
return int16_t(from >> 16);
}
inline int32_t S16toS32(int16_t from){
return int32_t(from << 16);
}
inline int8_t S16toS8(int16_t from){
return int8_t(from >> 8);
}
inline int16_t S8toS16(int8_t from){
return int16_t(from << 8);
}
// compound conversions
// float <> unsigned (type and size)
inline uint32_t F32toU32(float from){
return S32toU32(F32toS32(from));
}
inline float U32toF32(uint32_t from){
return S32toF32(U32toS32(from));
}
inline uint16_t F32toU16(float from){
return S16toU16(F32toS16(from));
}
inline float U16toF32(uint16_t from){
return S16toF32(U16toS16(from));
}
inline uint8_t F32toU8(float from){
return S8toU8(F32toS8(from));
}
inline float U8toF32(uint8_t from){
return S8toF32(U8toS8(from));
}
// signed <> unsigned (type and size)
inline uint16_t S32toU16(int32_t from){
return S16toU16(S32toS16(from));
}
inline int32_t U16toS32(uint16_t from){
return S16toS32(U16toS16(from));
}
inline uint8_t S32toU8(int32_t from){
return S8toU8(S16toS8(S32toS16(from)));
}
inline int32_t U8toS32(uint8_t from){
return S16toS32(S8toS16(U8toS8(from)));
}
inline uint8_t S16toU8(int16_t from){
return S8toU8(S16toS8(from));
}
inline int16_t U8toS16(uint8_t from){
return S8toS16(U8toS8(from));
}
inline uint16_t S8toU16(int8_t from){
return S16toU16(S8toS16(from));
}
inline int8_t U16toS8(uint16_t from){
return S16toS8(U16toS16(from));
}
}
SoapySDR
Definition ConverterPrimitives.hpp:15
SoapySDR::F32toU8
uint8_t F32toU8(float from)
Definition ConverterPrimitives.hpp:115
SoapySDR::S16toU8
uint8_t S16toU8(int16_t from)
Definition ConverterPrimitives.hpp:138
SoapySDR::U16toS8
int8_t U16toS8(uint16_t from)
Definition ConverterPrimitives.hpp:148
SoapySDR::S8toS16
int16_t S8toS16(int8_t from)
Definition ConverterPrimitives.hpp:93
SoapySDR::S32toS16
int16_t S32toS16(int32_t from)
Definition ConverterPrimitives.hpp:83
SoapySDR::F32toS32
int32_t F32toS32(float from)
Definition ConverterPrimitives.hpp:33
SoapySDR::S32toU8
uint8_t S32toU8(int32_t from)
Definition ConverterPrimitives.hpp:131
SoapySDR::S16toS8
int8_t S16toS8(int16_t from)
Definition ConverterPrimitives.hpp:90
SoapySDR::U8_ZERO_OFFSET
const uint8_t U8_ZERO_OFFSET
Definition ConverterPrimitives.hpp:19
SoapySDR::S8toU8
uint8_t S8toU8(int8_t from)
Definition ConverterPrimitives.hpp:77
SoapySDR::F32toU16
uint16_t F32toU16(float from)
Definition ConverterPrimitives.hpp:108
SoapySDR::S8toF32
float S8toF32(int8_t from)
Definition ConverterPrimitives.hpp:50
SoapySDR::U16_ZERO_OFFSET
const uint16_t U16_ZERO_OFFSET
Definition ConverterPrimitives.hpp:18
SoapySDR::S32toU16
uint16_t S32toU16(int32_t from)
Definition ConverterPrimitives.hpp:124
SoapySDR::S16toF32
float S16toF32(int16_t from)
Definition ConverterPrimitives.hpp:43
SoapySDR::U32_ZERO_OFFSET
const uint32_t U32_ZERO_OFFSET
Definition ConverterPrimitives.hpp:17
SoapySDR::U16toF32
float U16toF32(uint16_t from)
Definition ConverterPrimitives.hpp:111
SoapySDR::S8_FULL_SCALE
const uint8_t S8_FULL_SCALE
Definition ConverterPrimitives.hpp:23
SoapySDR::U16toS16
int16_t U16toS16(uint16_t from)
Definition ConverterPrimitives.hpp:65
SoapySDR::S8toU16
uint16_t S8toU16(int8_t from)
Definition ConverterPrimitives.hpp:145
SoapySDR::U8toS16
int16_t U8toS16(uint8_t from)
Definition ConverterPrimitives.hpp:141
SoapySDR::F32toS16
int16_t F32toS16(float from)
Definition ConverterPrimitives.hpp:40
SoapySDR::U16toS32
int32_t U16toS32(uint16_t from)
Definition ConverterPrimitives.hpp:127
SoapySDR::U32toF32
float U32toF32(uint32_t from)
Definition ConverterPrimitives.hpp:104
SoapySDR::S16toU16
uint16_t S16toU16(int16_t from)
Definition ConverterPrimitives.hpp:69
SoapySDR::U8toF32
float U8toF32(uint8_t from)
Definition ConverterPrimitives.hpp:118
SoapySDR::U8toS32
int32_t U8toS32(uint8_t from)
Definition ConverterPrimitives.hpp:134
SoapySDR::F32toU32
uint32_t F32toU32(float from)
Definition ConverterPrimitives.hpp:101
SoapySDR::S32toF32
float S32toF32(int32_t from)
Definition ConverterPrimitives.hpp:36
SoapySDR::S32_FULL_SCALE
const uint32_t S32_FULL_SCALE
Definition ConverterPrimitives.hpp:21
SoapySDR::S16toS32
int32_t S16toS32(int16_t from)
Definition ConverterPrimitives.hpp:86
SoapySDR::S32toU32
uint32_t S32toU32(int32_t from)
Definition ConverterPrimitives.hpp:61
SoapySDR::F32toS8
int8_t F32toS8(float from)
Definition ConverterPrimitives.hpp:47
SoapySDR::S16_FULL_SCALE
const uint16_t S16_FULL_SCALE
Definition ConverterPrimitives.hpp:22
SoapySDR::U32toS32
int32_t U32toS32(uint32_t from)
Definition ConverterPrimitives.hpp:57
SoapySDR::U8toS8
int8_t U8toS8(uint8_t from)
Definition ConverterPrimitives.hpp:73