diff --git a/generated.cfile b/generated.cfile new file mode 100644 index 0000000..dddee17 Binary files /dev/null and b/generated.cfile differ diff --git a/hackrf-sample.cfile b/hackrf-sample.cfile new file mode 100644 index 0000000..8754576 Binary files /dev/null and b/hackrf-sample.cfile differ diff --git a/spectrogram.cpp b/spectrogram.cpp index 31af904..1ef2bf8 100644 --- a/spectrogram.cpp +++ b/spectrogram.cpp @@ -9,6 +9,8 @@ Spectrogram::Spectrogram() { inputSource = new InputSource("/home/mike/Downloads/hubsan-chopped.cfile", 1024); + powerMax = 0.0f; + powerRange = 40.0f; resize(inputSource->GetWidth(), inputSource->GetHeight()); } @@ -17,6 +19,62 @@ Spectrogram::~Spectrogram() delete inputSource; } +template const T& clamp (const T& value, const T& min, const T& max) { + return std::min(max, std::max(min, value)); +} + +void HSVtoRGB( float *r, float *g, float *b, float h, float s, float v ) +{ + int i; + float f, p, q, t; + + if( s == 0 ) { + // achromatic (grey) + *r = *g = *b = v; + return; + } + + h /= 60; // sector 0 to 5 + i = floor( h ); + f = h - i; // factorial part of h + p = v * ( 1 - s ); + q = v * ( 1 - s * f ); + t = v * ( 1 - s * ( 1 - f ) ); + + switch( i ) { + case 0: + *r = v; + *g = t; + *b = p; + break; + case 1: + *r = q; + *g = v; + *b = p; + break; + case 2: + *r = p; + *g = v; + *b = t; + break; + case 3: + *r = p; + *g = q; + *b = v; + break; + case 4: + *r = t; + *g = p; + *b = v; + break; + default: // case 5: + *r = v; + *g = p; + *b = q; + break; + } +} + void Spectrogram::paintEvent(QPaintEvent *event) { QElapsedTimer timer; @@ -37,8 +95,13 @@ void Spectrogram::paintEvent(QPaintEvent *event) QImage image(width, height, QImage::Format_RGB32); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { - uint8_t pixel = data[y*width + x] * -3; - image.setPixel(x, y, qRgb(0, 0, pixel)); + float normPower = (data[y*width + x] - powerMax) * -1.0f / powerRange; + normPower = clamp(normPower, 0.0f, 1.0f); + + float red, green, blue; + HSVtoRGB(&red, &green, &blue, normPower * 300.0f, 1, 1 - normPower); + + image.setPixel(x, y, qRgb(red * 255, green * 255, blue * 255)); } } @@ -56,4 +119,4 @@ void Spectrogram::setFFTSize(int size) inputSource->setFFTSize(size); update(); resize(inputSource->GetWidth(), inputSource->GetHeight()); -} \ No newline at end of file +} diff --git a/spectrogram.h b/spectrogram.h index 54a588f..d31b26f 100644 --- a/spectrogram.h +++ b/spectrogram.h @@ -19,4 +19,7 @@ protected: private: InputSource *inputSource; + + float powerMax; + float powerRange; }; \ No newline at end of file