From 7507e78a3c7107f820a501620da630fa8d48ea56 Mon Sep 17 00:00:00 2001 From: Arnaud Blanchard <arnaud.blanchard@ensea.fr> Date: Mon, 16 Apr 2018 16:40:50 +0200 Subject: [PATCH] Add -n option to limit the numbers of samples --- i_sndfile/i_sndfile.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/i_sndfile/i_sndfile.cpp b/i_sndfile/i_sndfile.cpp index c579956..a51bb12 100644 --- a/i_sndfile/i_sndfile.cpp +++ b/i_sndfile/i_sndfile.cpp @@ -8,8 +8,8 @@ int main(int argc, char**argv){ blc_channel output; - char const *filename, *output_name, *type_str, *length_str, *period_str, *samplerate_str; - int period, samplerate; + char const *filename, *output_name, *type_str, *length_str, *period_str, *samplerate_str, *iterations_nb_str; + int period, samplerate, iterations_nb; size_t length; uint32_t type; SF_INFO sfinfo; @@ -18,6 +18,7 @@ int main(int argc, char**argv){ blc_program_set_description("Record blc_channel input in a sound file"); blc_program_add_option(&filename, 'f', "file", "string", "filename of the file to write", NULL); + blc_program_add_option(&iterations_nb_str, 'n', "number", "integer", "number of samples to acquire (-1 for infinity)", "-1"); blc_program_add_option(&output_name, 'o', "output", "string", "Channel where to put the sound", DEFAULT_OUTPUT_NAME); blc_program_add_option(&period_str, 'p', "period", "integer", "Period between each sample in ms (0 as fast as possible)", "0"); blc_program_add_option(&length_str, 's', "size", "integer", "Sample size", "4096"); @@ -37,6 +38,7 @@ int main(int argc, char**argv){ if (sscanf(length_str, "%ld", &length)!=1) EXIT_ON_ERROR("Reading size '%s'", length_str); if (sscanf(period_str, "%d", &period)!=1) EXIT_ON_ERROR("Reading period in '%s'", period_str); + iterations_nb=strtol(iterations_nb_str, NULL, 10); if (strcmp(DEFAULT_OUTPUT_NAME, output_name)==0) asprintf((char**)&output_name, ":sound%d", getpid()); output.create_or_open(output_name, BLC_CHANNEL_WRITE, type, 'LPCM', 1, length); @@ -51,6 +53,7 @@ int main(int argc, char**argv){ blc_loop_try_add_posting_semaphore(output.sem_new_data); BLC_COMMAND_LOOP(period*1000){ + if (iterations_nb==blc_loop_iteration) blc_command_ask_quit(); read_items_nb=sf_read_float(sndfile, output.floats, output.total_length); if (read_items_nb!=output.total_length) { color_eprintf(BLC_YELLOW, "%s: Iteration %llu: Missing data. Read '%lld' items instead of '%ld'. It is probably the end of the file\n", blc_program_name, blc_loop_iteration, read_items_nb, output.total_length); -- GitLab