1 Refactoring ideas for multiple audio backends
Avery King edited this page 2023-05-31 02:39:20 +00:00

Part 0: Fundamentals

  • Introduce class AudioBackend, an abstract class that provides a common interface around implementing different audio backends.

    • Introduce PortAudioBackend, an implementation of this class using PortAudio.
    • AudioBackend instances handle streams and devices.
    • This class has the following member types:
      • NativeStreamType - The native type for streams (e.g., PaStream for PortAudio)
      • NativeDeviceType - The native type for device handles (e.g., int for PortAudio)
  • Introduce AudioBackendManager, which controls which backend implementation is active.

    • AudioBackendManager owns a shared_ptr to an AudioBackend instance. You can retrieve a pointer to this instance when needed.
    • Only one backend may be active at a time. Backends must free all their resources on destruction (RAII).
  • Maybe introduce some new exceptions?

    • GeneralException - Something happened. All exceptions listed below are derived from this type
    • `UninitializedBackend - The backend was not initialized.
    • BadDevice - The device handle was bad.
    • StreamError - An error opening a stream occured
  • Maybe separate device management functionalities from AudioBackend into its own class?

Part 1: Changes in DeviceManager

  • Move all PortAudio device management functions into PortAudioBackend.
  • Make DeviceManager cooperate with AudioBackendManager to get a weak_ptr to the audio backend.