Merge pull request #392 from xiaoqiang306/fix_example_cpp

fix int16_t bytes normalized to float
This commit is contained in:
Alexander Veysov
2023-11-13 15:20:08 +03:00
committed by GitHub

View File

@@ -46,10 +46,10 @@ public:
// Call it in predict func. if you prefer raw bytes input.
void bytes_to_float_tensor(const char *pcm_bytes)
{
std::memcpy(input.data(), pcm_bytes, window_size_samples * sizeof(int16_t));
const int16_t * in_data = reinterpret_cast<const int16_t*>(pcm_bytes);
for (int i = 0; i < window_size_samples; i++)
{
input[i] = static_cast<float>(input[i]) / 32768; // int16_t normalized to float
input[i] = static_cast<float>(in_data[i]) / 32768; // int16_t normalized to float
}
}