soundManagers.h 2.3 KB

1234567891011121314151617181920212223242526
  1. 
  2. #ifndef DFPSR_SOUND_API
  3. #define DFPSR_SOUND_API
  4. #include "../DFPSR/includeFramework.h"
  5. // Call this function from a separate thread in a sound engine to initialize the sound system, call back with sound output requests and terminate when the callback returns false.
  6. // The sound_streamToSpeakers function returns false if the backend could not be created, and true iff the backend completed all work and terminated safely.
  7. // Channels: The number of virtual speakers to send data to.
  8. // How this is mapped to physical speakers depends on the system, because surround speakers may choose to play mono and stereo sound using only the front speakers.
  9. // sampleRate: The number of ticks per second for each channel.
  10. // soundOutput: A callback that requests length number of ticks generated by the sound engine and written in a packed format into the data array.
  11. // The soundOutput function returns true iff the audio backend should keep fetching sound samples, and false iff the engine is done and ready for the call to sound_streamToSpeakers to return.
  12. // data: The data array should be filled with sound samples in the -1.0f to 1.0f range, in indices from 0 to (length * channels) - 1.
  13. // The audio backend is responsible for converting the 32-bit float samples into a bit-depth chosen by the backend.
  14. // The backend is supposed to padd the SafePointer's range to at least be divisible by DSR_FLOAT_ALIGNMENT, which allow using both X vectors and F vectors.
  15. // The F vector can be larger than the X vector if building for a SIMD extension that only supports the widest vector length for floating-point operations.
  16. // Padding elements will not add to the time passed in the sound engine, for only played elements increment time.
  17. // length: The number of ticks per channel. The total number of elements to write into data is channels * length.
  18. // How to use:
  19. // Call sound_streamToSpeakers with desired channels and sampleRate from a separate thread.
  20. // Handle callbacks to soundOutput by feeding the next packed sound samples and letting it return false when done.
  21. // Close the thread and let the sound engine clean up resources.
  22. bool sound_streamToSpeakers(int channels, int sampleRate, std::function<bool(dsr::SafePointer<float> data, int length)> soundOutput);
  23. #endif