-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Labels
bugSomething isn't workingSomething isn't working
Description
I get the following issue with a file of length 7866720 samples, 18 channels and word length of 3 bytes at 48kHz.
wav_file_splicer.cc:407] Check failed: processed_seg_length <= total_samples (7.86672e+06 vs. 7866719) Samples in segment should not be greater than actual samples in the wav file.
it may happen that the calculation of total_duration = 163.89 is stored as a double ≈ 163.88999999999998636. Then multiplied by 48000 is = 7866719.999999999. So casted is 7866719.
Using float instead of double may fix it.
To reproduce it:
#include <iostream>
#include <stdint.h>
struct FormatInfoChunk {
uint16_t format_tag;
uint16_t num_channels = 18;
uint32_t samples_per_sec = 48000;
uint32_t avg_bytes_per_sec;
uint16_t block_align;
uint16_t bits_per_sample = 24;
};
constexpr int32_t kBitsPerByte = 8;
double CalculateTotalDuration(const size_t& data_chunk_size,
const FormatInfoChunk& wav_file_fmt,
const size_t& total_channel_size) {
const auto& total_samples_per_channel = data_chunk_size / total_channel_size;
double total_duration = static_cast<double>(total_samples_per_channel) /
static_cast<double>(wav_file_fmt.samples_per_sec);
return total_duration;
}
int main()
{
FormatInfoChunk wav_file_fmt;
const size_t data_chunk_size = 0x1951FA40; //424802880; 0x40FA5119 -> 0x1951FA40
const int32_t bytes_per_sample =
static_cast<int32_t>(wav_file_fmt.bits_per_sample) / kBitsPerByte;
const size_t total_channel_size =
static_cast<size_t>(bytes_per_sample) * wav_file_fmt.num_channels;
const auto total_duration =
CalculateTotalDuration(data_chunk_size, wav_file_fmt, total_channel_size);
const size_t total_samples =
total_duration * static_cast<size_t>(wav_file_fmt.samples_per_sec);
const float total_samples_f =
total_duration * static_cast<size_t>(wav_file_fmt.samples_per_sec);
const size_t total_samples_f_i = static_cast<size_t>(total_samples_f);
size_t real_samples = data_chunk_size / (wav_file_fmt.bits_per_sample / kBitsPerByte) / wav_file_fmt.num_channels;
std::cout << "total_duration: " << total_duration << std::endl;
std::cout << "total_samples: " << total_samples << std::endl;
std::cout << "total_samples_f: " << total_samples_f << std::endl;
std::cout << "total_samples_f_i: " << total_samples_f_i << std::endl;
std::cout << "real_samples: " << real_samples << std::endl;
return 0;
}
Output:
total_duration: 163.89
total_samples: 7866719
total_samples_f: 7.86672e+06
total_samples_f_i: 7866720
real_samples: 7866720
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working