Exploration of Strongly-typed Units in C++: A Case Study from Digital Audio - Roth Michaels - CppCon

Explore the concept of strongly-typed units in C++ through a case study in digital audio, demonstrating how units can prevent errors and improve code readability, and introducing the MP units library as a solution.

Key takeaways
  • The concept of units is essential in digital audio to ensure accurate measurements and calculations.
  • The ISO 80000 standard provides guidance on units and quantities.
  • In the audio industry, decibels (dB) are used to measure sound pressure level, and there are two types: decibel voltage (dBV) and decibel referenced to full scale (dBFS).
  • Decibels are a logarithmic scale, but the ‘log’ symbol is misleading; it represents a power ratio, not a logarithm.
  • The MP units library provides a more comprehensive approach to physical units in C++.
  • Strongly-typed units can prevent errors and improve code readability.
  • The concept of a ‘quantity kind’ can encompass base units, derived units, and bibliographic units.
  • There are different types of quantities, such as scalar quantities, vector quantities, and tensor quantities.
  • In audio, tempo is typically measured in beats per minute (BPM), and samples are often measured in samples per second (sps).
  • Sample encoding can be done using different methods, such as pulse-code modulation (PCM) and pulse-width modulation (PWM).
  • Converting between units requires understanding the relationships between them, such as decibels and logarithms.
  • The use of strongly-typed units can help prevent common errors, such as adding decibels of different units.
  • The MP units library can be used to create a more robust and maintainable codebase.