Skip to content

Commit

Permalink
add notes to data transform utils
Browse files Browse the repository at this point in the history
  • Loading branch information
stephprince committed Sep 6, 2024
1 parent cb6257e commit 8a6b776
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,21 @@ inline std::shared_ptr<BaseIO> createIO(const std::string& type,
}
}

/**
* @brief Method to convert float values to uint16 values. This method
* was adapted from JUCE AudioDataConverters using a default value of
* destBytesPerSample = 2.
* @param source The source float data to convert
* @param dest The destination for the converted uint16 data
* @param numSamples The number of samples to convert
*/
inline void convertFloatToInt16LE(const float* source,
void* dest,
int numSamples)
{
// TODO - several steps in this function may be unnecessary for our use
// case. Consider simplifying the intermediate cast to char and the
// final cast to uint16_t.
auto maxVal = static_cast<double>(0x7fff);
auto intData = static_cast<char*>(dest);

Expand All @@ -89,6 +100,12 @@ inline void convertFloatToInt16LE(const float* source,
}
}

/**
* @brief Method to scale float values and convert to int16 values
* @param numSamples The number of samples to convert
* @param conversion_factor The conversion factor to scale the data
* @param data The data to convert
*/
inline std::unique_ptr<int16_t[]> transformToInt16(SizeType numSamples,
float conversion_factor,
const float* data)
Expand Down

0 comments on commit 8a6b776

Please sign in to comment.