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

Method sampleToSixteenBitInt

AudioFile.h:1441–1455  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1439//=============================================================
1440template <class T>
1441int16_t AudioSampleConverter<T>::sampleToSixteenBitInt (T sample)
1442{
1443 if constexpr (std::is_floating_point<T>::value)
1444 {
1445 sample = clamp (sample, -1., 1.);
1446 return static_cast<int16_t> (sample * static_cast<T> (32767.));
1447 }
1448 else
1449 {
1450 if constexpr (std::is_signed_v<T>)
1451 return static_cast<int16_t> (clamp (sample, SignedInt16_Min, SignedInt16_Max));
1452 else
1453 return static_cast<int16_t> (clamp (sample, UnsignedInt16_Min, UnsignedInt16_Max) + SignedInt16_Min);
1454 }
1455}
1456
1457//=============================================================
1458template <class T>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected