fix fft, display and hw settings

This commit is contained in:
Sebastien Bourdeauducq 2023-09-07 21:00:22 +08:00
parent fcd5d64053
commit 03e46f97eb
1 changed files with 14 additions and 17 deletions

View File

@ -24,29 +24,24 @@ static std::atomic<bool> terminate_dsp;
struct bladerf* bladerf_dev;
static std::mutex waterfall_data_mutex;
static int waterfall_width = 1600;
static int waterfall_height = 700;
static unsigned int waterfall_data[1600*700];
static int waterfall_width = 1000;
static int waterfall_height = 2000;
static unsigned int waterfall_data[1000*2000];
static std::atomic<int> fps;
static void dsp_thread() {
using namespace std::literals::chrono_literals;
size_t len = 8192;
size_t len = 16384;
std::vector<std::complex<int16_t>> frames(len);
std::vector<std::complex<float>> frames_f(len);
pocketfft::shape_t shape{len};
pocketfft::stride_t stride(shape.size());
size_t tmp=sizeof(float);
for (int i=shape.size()-1; i>=0; --i) {
stride[i] = tmp;
tmp *= shape[i];
};
pocketfft::stride_t stride(1);
stride[0] = 2*sizeof(float);
pocketfft::shape_t axes;
for(size_t i=0; i<shape.size(); ++i)
axes.push_back(i);
axes.push_back(0);
std::vector<std::complex<float>> frames_ft(len);
int iterations = 0;
auto last_second = std::chrono::steady_clock::now();
@ -58,12 +53,14 @@ static void dsp_thread() {
}
for(size_t i=0;i<len;i++)
frames_f[i] = frames[i];
pocketfft::c2c(shape, stride, stride, axes, true, frames_f.data(), frames_ft.data(), 1.0f);
pocketfft::c2c(shape, stride, stride, axes, pocketfft::FORWARD, frames_f.data(), frames_ft.data(), 1.0f);
{
std::lock_guard<std::mutex> guard(waterfall_data_mutex);
std::memmove(&waterfall_data[waterfall_width], &waterfall_data[0], sizeof(int)*waterfall_width*(waterfall_height - 1));
for(int i=0;i<waterfall_width;i++) {
waterfall_data[i] = 0xff000000 | 0x010101*std::min(int(abs(frames_ft[i*len/(2*waterfall_width)])/300.), 255);
int j = i*len/waterfall_width;
j = (j + len/2) % len; // display negative frequencies first
waterfall_data[i] = 0xff000000 | 0x010101*std::min(int(abs(frames_ft[j])/900.), 255);
}
}
iterations++;
@ -84,7 +81,7 @@ int main(int argc, char* argv[])
std::atexit(glfwTerminate);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
static GLFWwindow* window = glfwCreateWindow(1900, 720, "fastsa", nullptr, nullptr);
static GLFWwindow* window = glfwCreateWindow(1280, 2200, "fastsa", nullptr, nullptr);
if(window == nullptr) {
std::cerr << "failed to create GLFW window" << std::endl;
return 1;
@ -129,7 +126,7 @@ int main(int argc, char* argv[])
bladerf_close(bladerf_dev);
};
std::atexit(BladeRFClose);
if((status = bladerf_set_frequency(bladerf_dev, BLADERF_CHANNEL_RX(0), 1'650'000'000)) != 0) {
if((status = bladerf_set_frequency(bladerf_dev, BLADERF_CHANNEL_RX(0), 1'664'000'000)) != 0) {
std::cerr << "failed to set bladeRF frequency: " << bladerf_strerror(status) << std::endl;
return 1;
}
@ -196,7 +193,7 @@ int main(int argc, char* argv[])
ImGui::BeginTable("fastsa", 2, ImGuiTableFlags_SizingStretchSame | ImGuiTableFlags_Resizable);
ImGui::TableSetupColumn("", 0, 280.0);
ImGui::TableSetupColumn("", 0, 1600.0);
ImGui::TableSetupColumn("", 0, 1000.0);
ImGui::TableNextColumn();
if(ImGui::Button("Exit"))
exit = true;