diff --git a/CMakeLists.txt b/CMakeLists.txt index 3eaad61d151a225bb5e87ab90cdbdb0933cb6415..aa8d40e0ba897b356b3304cad728b48029657f74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/main.cpp b/src/main.cpp index 20c7756354ce4c891e86a9dd6b089bf6d0bcbfd8..3e6e06bd91ce7530e62903208be88e36f7cfe1e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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();