soundManagers.h 988 B

12345678910111213141516171819202122232425
  1. 
  2. #ifndef DFPSR_SOUND_API
  3. #define DFPSR_SOUND_API
  4. #include <functional>
  5. inline float sound_convertI16ToF32(int64_t input) {
  6. return input * (1.0f / 32767.0f);
  7. }
  8. inline int sound_convertF32ToI16(float input) {
  9. int64_t result = input * 32767.0f;
  10. if (result > 32767) { result = 32767; }
  11. if (result < -32768) { result = -32768; }
  12. return result;
  13. }
  14. // 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.
  15. // The float array given to soundOutput should be filled with samples from 0 to totalSamples - 1.
  16. // Channels from the same point in time are packed together without any padding in between.
  17. // Returns false if the backend could not be created.
  18. // Returns true iff the backend completed all work and terminated safely.
  19. bool sound_streamToSpeakers(int channels, int sampleRate, std::function<bool(float*, int)> soundOutput);
  20. #endif