sound.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 
  2. #ifndef MODULE_SOUND
  3. #define MODULE_SOUND
  4. #include "../../DFPSR/includeFramework.h"
  5. #include "../../DFPSR/api/soundAPI.h"
  6. namespace dsr {
  7. void sound_initialize();
  8. void sound_terminate();
  9. // Creates a single-channel sound using the generator function
  10. // generator takes the time in seconds as input and returns a value from -1.0 to 1.0
  11. int generateMonoSoundBuffer(const dsr::ReadableString &name, int sampleCount, int sampleRate, std::function<float(double time)> generator);
  12. int getSoundBufferCount();
  13. int loadWaveSoundFromBuffer(const dsr::ReadableString &name, dsr::Buffer bufferconst);
  14. int loadSoundFromFile(const dsr::ReadableString &filename, bool mustExist = true);
  15. struct EnvelopeSettings {
  16. // Basic ADSR
  17. double attack, decay, sustain, release;
  18. // Extended
  19. double hold, rise, sustainedSmooth, releasedSmooth;
  20. EnvelopeSettings();
  21. EnvelopeSettings(double attack, double decay, double sustain, double release, double hold = 0.0, double rise = 0.0, double sustainedSmooth = 0.0, double releasedSmooth = 0.0);
  22. };
  23. int playSound(int soundIndex, bool repeat, double volumeLeft, double volumeRight, double speed);
  24. int playSound(int soundIndex, bool repeat, double volumeLeft, double volumeRight, double speed, const EnvelopeSettings &envelopeSettings);
  25. // Begin to fade out the sound and let it delete itself once done
  26. void releaseSound(int64_t playerID);
  27. // Stop the sound at once
  28. void stopSound(int64_t playerID);
  29. // Stop all sounds at once
  30. void stopAllSounds();
  31. // Visualization
  32. void drawEnvelope(dsr::ImageRgbaU8 target, const dsr::IRect &region, const EnvelopeSettings &envelopeSettings, double releaseTime, double viewTime);
  33. void drawSound(dsr::ImageRgbaU8 target, const dsr::IRect &region, int soundIndex, bool selected);
  34. }
  35. #endif