AudioContext.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #include <libavutil/samplefmt.h>
  3. #include <vector>
  4. #include "WallpaperEngine/Application/ApplicationContext.h"
  5. #include "WallpaperEngine/Audio/Drivers/Recorders/PulseAudioPlaybackRecorder.h"
  6. namespace WallpaperEngine {
  7. namespace Application {
  8. class ApplicationContext;
  9. }
  10. namespace Audio {
  11. namespace Drivers {
  12. class AudioDriver;
  13. namespace Recorders {
  14. class PulseAudioPlaybackRecorder;
  15. }
  16. } // namespace Drivers
  17. class AudioStream;
  18. class AudioContext {
  19. public:
  20. explicit AudioContext (Drivers::AudioDriver& driver);
  21. /**
  22. * Registers the given stream in the driver for playing
  23. *
  24. * @param stream
  25. */
  26. int addStream (AudioStream* stream, int volume = -1, float left = 1.0f, float right = 1.0f) const;
  27. /**
  28. * @param streamId The stream to stop playing
  29. */
  30. void removeStream (int streamId) const;
  31. /**
  32. * Overrides the volume used to mix a single stream, instead of the driver's global volume
  33. *
  34. * @param streamId The stream to change
  35. * @param volume 0-128, or a negative value to go back to using the global volume
  36. */
  37. void setStreamVolume (int streamId, int volume) const;
  38. /**
  39. * Scales the left and right channel of a stream on top of its volume
  40. */
  41. void setStreamGains (int streamId, float left, float right) const;
  42. /**
  43. * Pauses or resumes a stream where it is
  44. */
  45. void setStreamPaused (int streamId, bool paused) const;
  46. /**
  47. * TODO: MAYBE THIS SHOULD BE OUR OWN DEFINITIONS INSTEAD OF LIBRARY SPECIFIC ONES?
  48. *
  49. * @return The audio format the driver supports
  50. */
  51. [[nodiscard]] AVSampleFormat getFormat () const;
  52. /**
  53. * @return The sample rate the driver supports
  54. */
  55. [[nodiscard]] int getSampleRate () const;
  56. /**
  57. * @return The channels the driver supports
  58. */
  59. [[nodiscard]] int getChannels () const;
  60. /**
  61. * @return The application context under which the audio driver is initialized
  62. */
  63. Application::ApplicationContext& getApplicationContext () const;
  64. /**
  65. * @return The audio recorder to use to capture stereo mix data
  66. */
  67. [[nodiscard]] Drivers::Recorders::PlaybackRecorder& getRecorder () const;
  68. /**
  69. * @return The audio driver used to playback and record audio
  70. */
  71. [[nodiscard]] Drivers::AudioDriver& getDriver () const;
  72. private:
  73. /** The audio driver in use */
  74. Drivers::AudioDriver& m_driver;
  75. };
  76. } // namespace Audio
  77. } // namespace WallpaperEngine