Skip to content
Snippets Groups Projects
Commit 2ac967ff authored by ferrari's avatar ferrari
Browse files

Fix total length option

parent c1bee851
No related branches found
No related tags found
2 merge requests!2HighBlueParser dev branch merged to empty main branch,!1High blue rec
......@@ -66,6 +66,7 @@ int record(size_t channels, size_t rate, size_t depth, size_t filter, std::stri
size_t total_samples_wanted = totallen * rate;
size_t total_samples_read = 0;
size_t failed_attempts = 0;
size_t sample_size = channels * depth;
std::vector<std::uint8_t> samples;
try {
std::cout << "Setting recording format to " << channels << " channels at " << rate << " Hz " << (1<<(2+depth)) << " bits" << std::endl;
......@@ -78,10 +79,10 @@ int record(size_t channels, size_t rate, size_t depth, size_t filter, std::stri
}
recorder.get_samples(samples, false, 500);
if (samples.size() > 0) {
total_samples_read += samples.size() / channels;
total_samples_read += samples.size() / sample_size;
// if we have too much now, crop the last packet
if ((total_samples_wanted > 0) && (total_samples_read > total_samples_wanted)) {
samples.resize(samples.size() - (total_samples_read - total_samples_wanted) * channels);
samples.resize(samples.size() - (total_samples_read - total_samples_wanted) * sample_size);
}
// pass it on to the file writer
filewriter->write(samples);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment