-
Notifications
You must be signed in to change notification settings - Fork 324
Raise exceptions if passing int-like data into process.
#408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -174,6 +174,44 @@ processFloat32(const py::array_t<float, py::array::c_style> inputArray, | |||||
| juce::AudioBuffer<float> ioBuffer = | ||||||
| copyPyArrayIntoJuceBuffer(inputArray, {inputChannelLayout}); | ||||||
|
|
||||||
| // ======= DETECTION FOR INT16-CONVERTED FLOAT DATA ======= | ||||||
| bool allIntegers = true; | ||||||
| bool looksLikeInt16 = true; | ||||||
|
|
||||||
| for (int c = 0; c < ioBuffer.getNumChannels(); c++) { | ||||||
| float *channelData = ioBuffer.getWritePointer(c); | ||||||
| for (int i = 0; i < ioBuffer.getNumSamples(); i++) { | ||||||
| float value = channelData[i]; | ||||||
|
|
||||||
| // Check if the value is very close to an integer | ||||||
| if (std::abs(value - std::round(value)) > 1e-6) { | ||||||
| allIntegers = false; | ||||||
| } | ||||||
|
|
||||||
| // Check if the value is within int16 range | ||||||
| if (value < -32768.0 || value > 32767.0) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need another check here to ensure that at least some values are outside of |
||||||
| looksLikeInt16 = false; | ||||||
| } | ||||||
|
|
||||||
| // If both conditions are already violated, break early | ||||||
| if (!allIntegers && !looksLikeInt16) { | ||||||
| break; | ||||||
| } | ||||||
| } | ||||||
| if (!allIntegers && !looksLikeInt16) { | ||||||
| break; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // If all values are integers or look like int16, raise an error | ||||||
| if (allIntegers) { | ||||||
| throw std::runtime_error("Error: Input contains only integer values. Ensure proper floating-point conversion."); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need
Suggested change
|
||||||
| } | ||||||
| if (looksLikeInt16) { | ||||||
| throw std::runtime_error("Error: Input appears to be improperly converted from 16-bit integer audio. Use proper scaling."); | ||||||
| } | ||||||
|
|
||||||
| // ======= Continue normal processing ======= | ||||||
| if (ioBuffer.getNumChannels() == 0) { | ||||||
| unsigned int numChannels = 0; | ||||||
| unsigned int numSamples = ioBuffer.getNumSamples(); | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to use
if (f == std::trunc(f))here instead, as the use case that we're trying to detect is when a user passes in anint16(or, rarely, anint32array containing 24-bit integer data) and PyBind11 automatically casts it to float. In such cases, the values should be exactly integers, asfloatcan represent all 24-bit integers exactly.