Skip to content

Add new options to MISRC Capture #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 53 additions & 8 deletions misrc_tools/misrc_capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
#if LIBFLAC_ENABLED == 1
#include "FLAC/metadata.h"
#include "FLAC/stream_encoder.h"
#define GETOPT_STRING "d:a:b:fl:vx:r:ph"
#define GETOPT_STRING "d:a:b:fl:vx:r:wABph:n:t:"
#else
#define GETOPT_STRING "d:a:b:x:r:ph"
#define GETOPT_STRING "d:a:b:x:r:wABph:n:t:"
#endif

#include "ringbuffer.h"
Expand Down Expand Up @@ -102,11 +102,15 @@ void usage(void)
"Usage:\n"
"\t[-d device_index (default: 0)]\n"
"\t[-n number of samples to read (default: 0, infinite)]\n"
"\t[-t seconds to capture (-n takes priority, assumes 40msps with a single ADC)]\n"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if -t is the best option, maybe that's better for FLAC threads. Why not -s?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Harry suggested that this could be extended into hh:mm:ss (a single value is treated as seconds, if there is a single colon it's mm:ss, with two colons it's hh:mm:ss). Then -s doesn't make much sense

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a better method. I initially choose t for time. I thought about doing it where the user could enter "4h5m34s", but I am not well versed in the C language and didn't want to learn to deal with pointers, memory, etc. The languages I primarily work in are PHP, Java, and RPGLE, so it's hard for me to create the parsing for that in C.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most things are harder in C, but I could add that at a later point

"\t[-w overwrite any files without asking]\n"
"\t[-a ADC A output file (use '-' to write on stdout)]\n"
"\t[-b ADC B output file (use '-' to write on stdout)]\n"
"\t[-x AUX output file (use '-' to write on stdout)]\n"
"\t[-r raw data output file (use '-' to write on stdout)]\n"
"\t[-p pad lower 4 bits of 16 bit output with 0 instead of upper 4]\n"
"\t[-A suppress clipping messages for ADC A (need to specify -a or -r as well)]\n"
"\t[-B suppress clipping messages for ADC B (need to specify -b or -r as well)]\n"
#if LIBFLAC_ENABLED == 1
"\t[-f compress ADC output as FLAC]\n"
"\t[-l LEVEL set flac compression level (default: 1)]\n"
Expand Down Expand Up @@ -310,6 +314,16 @@ int main(int argc, char **argv)
char *output_name_aux = NULL;
char *output_name_raw = NULL;

//show clipping messages
bool suppress_a_clipping = false;
bool suppress_b_clipping = false;

//overwrite option
bool overwrite_files = false;

//number of samples to take
uint64_t total_samples_before_exit = 0;

//output files
FILE *output_aux = NULL;
FILE *output_raw = NULL;
Expand Down Expand Up @@ -362,18 +376,45 @@ int main(int argc, char **argv)
case 'p':
pad = 1;
break;
case 'w':
overwrite_files = true;
break;
case 'n':
total_samples_before_exit = (uint64_t)atoi(optarg);
break;
case 't':
if(total_samples_before_exit == 0) {
total_samples_before_exit = ((uint64_t)atoi(optarg)) * 40000000;
}
break;
case 'A':
suppress_a_clipping = true;
break;
case 'B':
suppress_b_clipping = true;
break;
case 'h':
default:
usage();
break;
}
}

if(output_names[0] == NULL && output_names[1] == NULL && output_name_aux == NULL && output_name_raw == NULL)
if((output_names[0] == NULL && output_names[1] == NULL && output_name_aux == NULL && output_name_raw == NULL))
{
usage();
}

if(suppress_a_clipping) {
fprintf(stderr, "Suppressing clipping messages from ADC A\n");
}
if(suppress_b_clipping) {
fprintf(stderr, "Suppressing clipping messages from ADC B\n");
}
if(total_samples_before_exit > 0) {
fprintf(stderr, "Capturing %ld samples before exiting\n", total_samples_before_exit);
}

#ifndef _WIN32
sigact.sa_handler = sighandler;
sigemptyset(&sigact.sa_mask);
Expand All @@ -393,7 +434,7 @@ int main(int argc, char **argv)
}
else
{
if (access(output_names[i], F_OK) == 0) {
if (access(output_names[i], F_OK) == 0 && !overwrite_files) {
char ch = 0;
fprintf(stderr, "File '%s' already exists. Overwrite? (y/n) ", output_names[i]);
scanf("%c",&ch);
Expand Down Expand Up @@ -428,7 +469,7 @@ int main(int argc, char **argv)
}
else if(output_name_aux != NULL)
{
if (access(output_name_aux, F_OK) == 0) {
if (access(output_name_aux, F_OK) == 0 && !overwrite_files) {
char ch = 0;
fprintf(stderr, "File '%s' already exists. Overwrite? (y/n) ", output_name_aux);
scanf("%c",&ch);
Expand All @@ -451,7 +492,7 @@ int main(int argc, char **argv)
}
else if(output_name_raw != NULL)
{
if (access(output_name_raw, F_OK) == 0) {
if (access(output_name_raw, F_OK) == 0 && !overwrite_files) {
char ch = 0;
fprintf(stderr, "File '%s' already exists. Overwrite? (y/n) ", output_name_raw);
scanf("%c",&ch);
Expand Down Expand Up @@ -506,14 +547,14 @@ int main(int argc, char **argv)

total_samples += BUFFER_READ_SIZE;

if(clip[0] > 0)
if(clip[0] > 0 && !suppress_a_clipping)
{
fprintf(stderr,"ADC A : %ld samples clipped\n",clip[0]);
clip[0] = 0;
new_line = 1;
}

if(clip[1] > 0)
if(clip[1] > 0 && !suppress_b_clipping)
{
fprintf(stderr,"ADC B : %ld samples clipped\n",clip[1]);
clip[1] = 0;
Expand All @@ -525,6 +566,10 @@ int main(int argc, char **argv)
fprintf(stderr,"\033[A\33[2K\r Progress: %13lu samples, %2uh %2um %2us\n", total_samples, (uint32_t)(total_samples/(144000000000)), (uint32_t)((total_samples/(2400000000)) % 60), (uint32_t)((total_samples/(40000000)) % 60));
fflush(stdout);
}
if (total_samples >= total_samples_before_exit && total_samples_before_exit != 0) {
fprintf(stderr, "%ld total samples have been collected, exiting early!\n", total_samples);
do_exit = true;
}
}

if (do_exit)
Expand Down