mirror of
https://github.com/SatDump/SatDump
synced 2026-08-13 17:47:30 -04:00
57 lines
No EOL
1.3 KiB
C++
57 lines
No EOL
1.3 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;
|
|
}
|
|
|
|
bool isStringPresent(std::string searched, std::string keyword)
|
|
{
|
|
std::transform(searched.begin(), searched.end(), searched.begin(), tolower);
|
|
std::transform(keyword.begin(), keyword.end(), keyword.begin(), tolower);
|
|
|
|
auto found_it = searched.find(keyword, 0);
|
|
return found_it != std::string::npos;
|
|
} |