Skip to content
Snippets Groups Projects

High blue rec

Closed Pierre Mahe requested to merge pierre.mahe/highblueparsers:HighBlueRec into main
1 file
+ 3
2
Compare changes
  • Side-by-side
  • Inline
+ 3
2
@@ -66,6 +66,7 @@ int record(size_t channels, size_t rate, size_t depth, size_t filter, std::stri
@@ -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_wanted = totallen * rate;
size_t total_samples_read = 0;
size_t total_samples_read = 0;
size_t failed_attempts = 0;
size_t failed_attempts = 0;
 
size_t sample_size = channels * depth;
std::vector<std::uint8_t> samples;
std::vector<std::uint8_t> samples;
try {
try {
std::cout << "Setting recording format to " << channels << " channels at " << rate << " Hz " << (1<<(2+depth)) << " bits" << std::endl;
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
@@ -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);
recorder.get_samples(samples, false, 500);
if (samples.size() > 0) {
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 we have too much now, crop the last packet
if ((total_samples_wanted > 0) && (total_samples_read > total_samples_wanted)) {
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
// pass it on to the file writer
filewriter->write(samples);
filewriter->write(samples);
Loading