Skip to content
Snippets Groups Projects
Commit b5dee4eb authored by Jan Schlüter's avatar Jan Schlüter
Browse files

Exit with an error if no audio data is received for a while

parent 44730161
Branches
No related tags found
2 merge requests!2HighBlueParser dev branch merged to empty main branch,!1High blue rec
......@@ -4,7 +4,7 @@ if(POLICY CMP0063)
endif()
project(jasonrec)
set(JASONREC_VERSION "1.2")
set(JASONREC_VERSION "1.3")
add_definitions(-DJASONREC_VERSION="${JASONREC_VERSION}")
find_path(LIBUSB_INCLUDE_DIR
......
......@@ -56,6 +56,7 @@ int record(size_t channels, size_t rate, std::string &filename, float chunklen,
allow_clean_exit();
size_t total_samples_wanted = totallen * rate;
size_t total_samples_read = 0;
size_t failed_attempts = 0;
std::vector<std::int16_t> samples;
try {
recorder.start_recording();
......@@ -74,6 +75,14 @@ int record(size_t channels, size_t rate, std::string &filename, float chunklen,
}
// pass it on to the file writer
filewriter->write(samples);
failed_attempts = 0;
}
else {
// if we received no message or no audio data 20x in a row, abort
failed_attempts += 1;
if (failed_attempts >= 20) {
throw std::runtime_error("Device does not send audio data.");
}
}
}
recorder.stop_recording();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment