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

Method sampleToSignedByte

AudioFile.h:1478–1492  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1476//=============================================================
1477template <class T>
1478int8_t AudioSampleConverter<T>::sampleToSignedByte (T sample)
1479{
1480 if constexpr (std::is_floating_point<T>::value)
1481 {
1482 sample = clamp (sample, -1., 1.);
1483 return static_cast<int8_t> (sample * static_cast<T> (0x7F));
1484 }
1485 else
1486 {
1487 if constexpr (std::is_signed_v<T>)
1488 return static_cast<int8_t> (clamp (sample, -128, 127));
1489 else
1490 return static_cast<int8_t> (clamp (sample, 0, 255) - 128);
1491 }
1492}
1493
1494//=============================================================
1495template <class T>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected