SoundStream.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Container/RefCounted.h"
  5. namespace Urho3D
  6. {
  7. /// Base class for sound streams.
  8. class URHO3D_API SoundStream : public RefCounted
  9. {
  10. public:
  11. /// Construct.
  12. SoundStream();
  13. /// Destruct.
  14. ~SoundStream() override;
  15. /// Seek to sample number. Return true on success. Need not be implemented by all streams.
  16. virtual bool Seek(unsigned sample_number);
  17. /// Produce sound data into destination. Return number of bytes produced. Called by SoundSource from the mixing thread.
  18. virtual unsigned GetData(signed char* dest, unsigned numBytes) = 0;
  19. /// Set sound data format.
  20. void SetFormat(unsigned frequency, bool sixteenBit, bool stereo);
  21. /// Set whether playback should stop when no more data. Default false.
  22. void SetStopAtEnd(bool enable);
  23. /// Return sample size.
  24. unsigned GetSampleSize() const;
  25. /// Return default frequency as a float.
  26. float GetFrequency() const { return (float)frequency_; }
  27. /// Return default frequency as an integer.
  28. unsigned GetIntFrequency() const { return frequency_; }
  29. /// Return whether playback should stop when no more data.
  30. bool GetStopAtEnd() const { return stopAtEnd_; }
  31. /// Return whether data is sixteen bit.
  32. bool IsSixteenBit() const { return sixteenBit_; }
  33. /// Return whether data is stereo.
  34. bool IsStereo() const { return stereo_; }
  35. protected:
  36. /// Default frequency.
  37. unsigned frequency_;
  38. /// Stop when no more data flag.
  39. bool stopAtEnd_;
  40. /// Sixteen bit flag.
  41. bool sixteenBit_;
  42. /// Stereo flag.
  43. bool stereo_;
  44. };
  45. }