MCPcopy Create free account
hub / github.com/adamstark/AudioFile / sampleToUnsignedByte

Method sampleToUnsignedByte

AudioFile.h:1459–1474  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1457//=============================================================
1458template <class T>
1459uint8_t AudioSampleConverter<T>::sampleToUnsignedByte (T sample)
1460{
1461 if constexpr (std::is_floating_point<T>::value)
1462 {
1463 sample = clamp (sample, -1., 1.);
1464 sample = (sample + static_cast<T> (1.)) / static_cast<T> (2.);
1465 return static_cast<uint8_t> (1 + (sample * 254));
1466 }
1467 else
1468 {
1469 if constexpr (std::is_signed_v<T>)
1470 return static_cast<uint8_t> (clamp (sample, -128, 127) + 128);
1471 else
1472 return static_cast<uint8_t> (clamp (sample, 0, 255));
1473 }
1474}
1475
1476//=============================================================
1477template <class T>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected