VIANC/pw_plugin/main.cc

74 lines
1.7 KiB
C++
Raw Normal View History

2025-01-16 23:35:35 +01:00
#include <random>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
2025-01-28 22:09:02 +01:00
#include <chrono>
#include <thread>
2025-01-27 09:58:36 +01:00
#include <array>
#include <atomic>
2025-01-16 23:35:35 +01:00
#include "pipewire/pipewire.h"
#include "spa/param/audio/format-utils.h"
#include "spa/param/latency-utils.h"
2025-01-16 23:35:35 +01:00
2025-01-27 18:25:45 +01:00
#include "passthrough.h"
2025-01-28 22:09:02 +01:00
#include "micpath.h"
2025-01-16 23:35:35 +01:00
int main(int argc, char** argv) {
pw_init(&argc, &argv);
2025-01-27 18:25:45 +01:00
auto* tloop = pw_thread_loop_new("thread", NULL);
2025-01-28 22:09:02 +01:00
{
2025-01-27 18:25:45 +01:00
ringbuffer rb;
if(tloop == nullptr) {
std::cerr << "Could not create loop!\n";
return 1;
}
2025-01-27 18:25:45 +01:00
logger_record lr(pw_thread_loop_get_loop(tloop), &rb);
2025-01-30 01:57:30 +01:00
logger_playback lp(pw_thread_loop_get_loop(tloop), &rb);//, true, false);
2025-01-28 22:09:02 +01:00
ringbuffer mic_rb;
logger_record mic_lr(pw_thread_loop_get_loop(tloop),&mic_rb, "aec-record", "Capture");
aec_stream aec(pw_thread_loop_get_loop(tloop), &rb, &mic_rb, lr);
2025-01-27 18:25:45 +01:00
pw_thread_loop_start(tloop);
2025-01-16 23:35:35 +01:00
2025-01-28 22:09:02 +01:00
aec_params x;
do {
std::this_thread::sleep_for(std::chrono::seconds(1));
x = aec.get_aec_params();
} while(!x.valid);
2025-01-30 01:57:30 +01:00
while(true) {
std::this_thread::sleep_for(std::chrono::seconds(60));
}
2025-01-28 22:09:02 +01:00
std::puts("L = [");
for(int i = 0; i < 8192; ++i) {
std::printf("%f,", aec.cov[i]);
}
std::puts("]");
std::printf("Noise power : %f dB\n", 10*std::log10(x.noise_power));
std::printf("Echo return loss : %f dB (-20dB input power)\n",
-10*std::log10(x.echo_return_gain));
2025-01-30 01:57:30 +01:00
std::printf("Delay : %d samples\n", x.sample_delay);
2025-01-28 22:09:02 +01:00
2025-01-30 01:57:30 +01:00
std::this_thread::sleep_for(std::chrono::seconds(600));
2025-01-27 18:25:45 +01:00
pw_thread_loop_stop(tloop);
2025-01-30 01:57:30 +01:00
std::puts("h = [");
for(int i = 0; i < 128; ++i) {
std::printf("%e,", (float)aec.h[i]);
}
std::puts("]");
2025-01-28 22:09:02 +01:00
}
2025-01-27 18:25:45 +01:00
pw_thread_loop_destroy(tloop);
pw_deinit();
2025-01-28 22:09:02 +01:00
std::puts("See you space cowboy...");
2025-01-16 23:35:35 +01:00
return 0;
}