Skip to content

Commit

Permalink
[AudioContainer] Clipped the output value in range -1 to 1 (#112)
Browse files Browse the repository at this point in the history
* clipped the output in a given range

* Clipped the values between -1 to 1 for floating format
  • Loading branch information
amanchhaparia authored Oct 16, 2023
1 parent f923039 commit 2357feb
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion frontend/Interfaces/buddy/DAP/AudioContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,17 @@ template <typename T, size_t N> class Audio {

template <typename T, size_t N> bool Audio<T, N>::save(std::string filename) {
if (!this->audioFile.samples) {
this->audioFile.samples.reset(this->data->release());
auto temp = this->data->release();
if constexpr (std::is_same_v<T, float>) {
for (int i = 0; i < audioFile.numSamples; i++) {
if (temp[i] != temp[i]) { // To handle NaN values
temp[i] = 0.9999999;
} else { // Clamp the values between -1.0 to 1.0
temp[i] = std::clamp(temp[i], float(-1.0), float(0.9999999));
}
}
}
this->audioFile.samples.reset(temp);
}
return this->audioFile.save(filename);
}
Expand Down

0 comments on commit 2357feb

Please sign in to comment.