mirror of
https://github.com/SatDump/SatDump
synced 2026-08-13 17:47:30 -04:00
48 lines
No EOL
1 KiB
C++
48 lines
No EOL
1 KiB
C++
#include "utils.h"
|
|
#include <cmath>
|
|
#include <sstream>
|
|
|
|
void char_array_to_uchar(int8_t *in, uint8_t *out, int nsamples)
|
|
{
|
|
for (int i = 0; i < nsamples; i++)
|
|
{
|
|
double r = in[i] * 127.0;
|
|
if (r < 0)
|
|
r = 0;
|
|
else if (r > 255)
|
|
r = 255;
|
|
out[i] = floor(r);
|
|
}
|
|
}
|
|
|
|
void signed_soft_to_unsigned(int8_t *in, uint8_t *out, int nsamples)
|
|
{
|
|
for (int i = 0; i < nsamples; i++)
|
|
{
|
|
out[i] = in[i] + 127;
|
|
|
|
if (out[i] == 128) // 128 is for erased syms
|
|
out[i] = 127;
|
|
}
|
|
}
|
|
|
|
std::vector<std::string> splitString(std::string input, char del)
|
|
{
|
|
std::stringstream stcStream(input);
|
|
std::string seg;
|
|
std::vector<std::string> segs;
|
|
|
|
while (std::getline(stcStream, seg, del))
|
|
segs.push_back(seg);
|
|
|
|
return segs;
|
|
}
|
|
|
|
// Return filesize
|
|
size_t getFilesize(std::string filepath)
|
|
{
|
|
std::ifstream file(filepath, std::ios::binary | std::ios::ate);
|
|
std::size_t fileSize = file.tellg();
|
|
file.close();
|
|
return fileSize;
|
|
} |