Skip to content

Commit

Permalink
Specify number of radio channel threads
Browse files Browse the repository at this point in the history
  • Loading branch information
williamyang98 committed Oct 11, 2023
1 parent a3248e3 commit 7099954
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
13 changes: 9 additions & 4 deletions examples/basic_radio_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class App
PortAudio_Output pa_output;
std::unordered_map<subchannel_id_t, std::unique_ptr<Resampled_PCM_Player>> dab_plus_audio_players;
public:
App(const int transmission_mode, const int total_demod_threads, FILE* const _fp_in, const int _block_size)
App(const int transmission_mode, const int total_demod_threads, const int total_radio_threads, FILE* const _fp_in, const int _block_size)
: fp_in(_fp_in)
{
auto params = get_dab_parameters(transmission_mode);
Expand All @@ -72,7 +72,7 @@ class App
frame_double_buffer = std::make_unique<DoubleBuffer<viterbi_bit_t>>(params.nb_frame_bits);

ofdm_demod = Create_OFDM_Demodulator(transmission_mode, total_demod_threads);
radio = std::make_unique<BasicRadio>(params);
radio = std::make_unique<BasicRadio>(params, total_radio_threads);
radio_view_controller = std::make_unique<BasicRadioViewController>(*(radio.get()));

using namespace std::placeholders;
Expand Down Expand Up @@ -244,6 +244,7 @@ void usage() {
"\t[-b block size (default: 8192)]\n"
"\t[-M dab transmission mode (default: 1)]\n"
"\t[-t total ofdm demod threads (default: auto)]\n"
"\t[-T total radio threads (default: auto)]\n"
"\t[-C toggle coarse frequency correction (default: true)]\n"
"\t[-h (show usage)]\n"
);
Expand All @@ -252,14 +253,15 @@ void usage() {
INITIALIZE_EASYLOGGINGPP
int main(int argc, char** argv) {
int total_demod_threads = 0;
int total_radio_threads = 0;
char* rd_filename = NULL;
int block_size = 8192;
bool is_logging = false;
int transmission_mode = 1;
bool is_coarse_freq_correction = true;

int opt;
while ((opt = getopt_custom(argc, argv, "i:b:M:t:vCh")) != -1) {
while ((opt = getopt_custom(argc, argv, "i:b:M:t:T:vCh")) != -1) {
switch (opt) {
case 'i':
rd_filename = optarg;
Expand All @@ -273,6 +275,9 @@ int main(int argc, char** argv) {
case 't':
total_demod_threads = (int)(atof(optarg));
break;
case 'T':
total_radio_threads = (int)(atof(optarg));
break;
case 'v':
is_logging = true;
break;
Expand Down Expand Up @@ -325,7 +330,7 @@ int main(int argc, char** argv) {

auto port_audio_handler = ScopedPaHandler();

auto app = App(transmission_mode, total_demod_threads, fp_in, block_size);
auto app = App(transmission_mode, total_demod_threads, total_radio_threads, fp_in, block_size);
auto& config = app.GetOFDMDemod().GetConfig();
config.sync.is_coarse_freq_correction = is_coarse_freq_correction;

Expand Down
13 changes: 9 additions & 4 deletions examples/basic_radio_app_no_demod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class App
PortAudio_Output pa_output;
std::unordered_map<subchannel_id_t, std::unique_ptr<Resampled_PCM_Player>> dab_plus_audio_players;
public:
App(const int transmission_mode, FILE* const _fp_in)
App(const int transmission_mode, const int total_demod_threads, FILE* const _fp_in)
: fp_in(_fp_in) {
auto params = get_dab_parameters(transmission_mode);
frame_bits.resize(params.nb_frame_bits);
radio = std::make_unique<BasicRadio>(params);
radio = std::make_unique<BasicRadio>(params, total_demod_threads);
gui_controller = std::make_unique<BasicRadioViewController>(*(radio.get()));

using namespace std::placeholders;
Expand Down Expand Up @@ -165,6 +165,7 @@ void usage() {
"\t[-i input filename (default: None)]\n"
"\t If no file is provided then stdin is used\n"
"\t[-M dab transmission mode (default: 1)]\n"
"\t[-T total radio threads (default: auto)]\n"
"\t[-v Enable logging (default: false)]\n"
"\t[-h (show usage)]\n"
);
Expand All @@ -175,16 +176,20 @@ int main(int argc, char** argv) {
char* rd_filename = NULL;
bool is_logging = false;
int transmission_mode = 1;
int total_radio_threads = 0;

int opt;
while ((opt = getopt_custom(argc, argv, "i:M:vh")) != -1) {
while ((opt = getopt_custom(argc, argv, "i:M:T:vh")) != -1) {
switch (opt) {
case 'i':
rd_filename = optarg;
break;
case 'M':
transmission_mode = (int)(atof(optarg));
break;
case 'T':
total_radio_threads = (int)(atof(optarg));
break;
case 'v':
is_logging = true;
break;
Expand Down Expand Up @@ -226,7 +231,7 @@ int main(int argc, char** argv) {
el::Helpers::setThreadName("main-thread");

auto port_audio_handler = ScopedPaHandler();
auto app = App(transmission_mode, fp_in);
auto app = App(transmission_mode, total_radio_threads, fp_in);
auto renderer = Renderer(app);
const int rv = RenderImguiSkeleton(&renderer);
return rv;
Expand Down
12 changes: 8 additions & 4 deletions examples/basic_radio_scraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class App
std::unique_ptr<std::thread> ofdm_demod_thread;
std::unique_ptr<std::thread> basic_radio_thread;
public:
App(const int transmission_mode, const int total_demod_threads, FILE* const _fp_in, const int _block_size, const char* dir)
App(const int transmission_mode, const int total_demod_threads, const int total_radio_threads, FILE* const _fp_in, const int _block_size, const char* dir)
: fp_in(_fp_in)
{
auto params = get_dab_parameters(transmission_mode);
Expand All @@ -49,7 +49,7 @@ class App
rd_in_float.resize(_block_size);
frame_double_buffer = std::make_unique<DoubleBuffer<viterbi_bit_t>>(params.nb_frame_bits);

radio = std::make_unique<BasicRadio>(params);
radio = std::make_unique<BasicRadio>(params, total_radio_threads);
scraper = std::make_unique<BasicScraper>(*(radio.get()), dir);
ofdm_demod = Create_OFDM_Demodulator(transmission_mode, total_demod_threads);

Expand Down Expand Up @@ -143,13 +143,14 @@ int main(int argc, char** argv) {
const char* output_dir = NULL;
const char* rd_filename = NULL;
int total_demod_threads = 0;
int total_radio_threads = 0;
int block_size = 8192;
bool is_logging = false;
int transmission_mode = 1;
bool is_coarse_freq_correction = true;

int opt;
while ((opt = getopt_custom(argc, argv, "o:i:b:M:t:vCh")) != -1) {
while ((opt = getopt_custom(argc, argv, "o:i:b:M:t:T:vCh")) != -1) {
switch (opt) {
case 'o':
output_dir = optarg;
Expand All @@ -166,6 +167,9 @@ int main(int argc, char** argv) {
case 't':
total_demod_threads = (int)(atof(optarg));
break;
case 'T':
total_radio_threads = (int)(atof(optarg));
break;
case 'v':
is_logging = true;
break;
Expand Down Expand Up @@ -228,7 +232,7 @@ int main(int argc, char** argv) {
basic_scraper_logger->configure(scraper_conf);

fprintf(stderr, "Writing to directory %s\n", output_dir);
auto app = App(transmission_mode, total_demod_threads, fp_in, block_size, output_dir);
auto app = App(transmission_mode, total_demod_threads, total_radio_threads, fp_in, block_size, output_dir);
auto& config = app.GetDemod().GetConfig();
config.sync.is_coarse_freq_correction = is_coarse_freq_correction;
app.Run();
Expand Down
13 changes: 9 additions & 4 deletions examples/basic_radio_scraper_no_demod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class App
std::unique_ptr<BasicRadio> radio;
std::unique_ptr<BasicScraper> scraper;
public:
App(const int transmission_mode, FILE* const _fp_in, const char* dir)
App(const int transmission_mode, const int total_demod_threads, FILE* const _fp_in, const char* dir)
: fp_in(_fp_in)
{
auto params = get_dab_parameters(transmission_mode);
frame_bits.resize(params.nb_frame_bits);
radio = std::make_unique<BasicRadio>(params);
radio = std::make_unique<BasicRadio>(params, total_demod_threads);
scraper = std::make_unique<BasicScraper>(*(radio.get()), dir);
}
void Run() {
Expand All @@ -56,6 +56,7 @@ void usage() {
"\t If no file is provided then stdin is used\n"
"\t[-v Enable logging (default: false)]\n"
"\t[-M dab transmission mode (default: 1)]\n"
"\t[-T total radio threads (default: auto)]\n"
"\t[-h (show usage)]\n"
);
}
Expand All @@ -66,9 +67,10 @@ int main(int argc, char** argv) {
const char* rd_filename = NULL;
bool is_logging = false;
int transmission_mode = 1;
int total_radio_threads = 0;

int opt;
while ((opt = getopt_custom(argc, argv, "o:i:M:vh")) != -1) {
while ((opt = getopt_custom(argc, argv, "o:i:M:T:vh")) != -1) {
switch (opt) {
case 'o':
output_dir = optarg;
Expand All @@ -79,6 +81,9 @@ int main(int argc, char** argv) {
case 'M':
transmission_mode = (int)(atof(optarg));
break;
case 'T':
total_radio_threads = (int)(atof(optarg));
break;
case 'v':
is_logging = true;
break;
Expand Down Expand Up @@ -130,7 +135,7 @@ int main(int argc, char** argv) {
scraper_conf.setGlobally(el::ConfigurationType::Format, "[%level] [%thread] [%logger] %msg");
basic_scraper_logger->configure(scraper_conf);

auto app = App(transmission_mode, fp_in, output_dir);
auto app = App(transmission_mode, total_radio_threads, fp_in, output_dir);
app.Run();
return 0;
}
Expand Down

0 comments on commit 7099954

Please sign in to comment.