-
Notifications
You must be signed in to change notification settings - Fork 63
Update audio engine #366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Update audio engine #366
Changes from all commits
aea0e26
f773798
f2d84e4
5979f79
4306e72
cd5e440
7ed92f6
c3e0385
1ab3fbe
ce3042c
d3a0348
dac612d
e10c5aa
6651301
69574b0
e820843
54c13a3
3cbb8d9
c671961
c4b4588
e0f423a
f0691c0
d5f9367
2220b89
0285540
84b22ce
e5e1124
7ec8c7d
f93d45c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,66 +1,177 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <functional> | ||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
| #include <glm/glm.hpp> | ||
|
|
||
| typedef struct ALCdevice_struct ALCdevice; | ||
| #include <math/mathlib.h> | ||
|
|
||
| namespace Audio | ||
| { | ||
| class AudioWorld; | ||
| enum class State { | ||
| Stopped, | ||
| Paused, | ||
| Playing | ||
| }; | ||
|
|
||
| /** The AudioEngine represents the target OS sound system. | ||
| * | ||
| * The engine class matches the OpenAL device level. | ||
| enum class Format { | ||
| Mono, | ||
| Stereo | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Sounds represent audio sources. | ||
| * | ||
| * All of the information about a sound should be re-set before it is played | ||
| * after it had been stopped. | ||
| * | ||
| */ | ||
| class Sound { | ||
| public: | ||
| virtual ~Sound() = default; | ||
|
|
||
| /** | ||
| * @brief Set sound pitch, must be positive | ||
| * | ||
| * 1 means original pitch, values < 1 mean lower, > 1 mean higher. | ||
| * | ||
| * @return float | ||
| */ | ||
| virtual void pitch(float) = 0; | ||
|
|
||
| /** | ||
| * @brief Set sound gain | ||
| * | ||
| * 1 means original volume, <1 means lower gain, >1 means higher. | ||
| * | ||
| * @return float | ||
| */ | ||
| virtual void gain(float) = 0; | ||
|
|
||
| /** | ||
| * @brief Set the maximum distance from which this sound can be heard. | ||
| * Must be positive. | ||
| * | ||
| */ | ||
| virtual void maxDistance(float) = 0; | ||
|
|
||
| /** | ||
| * @brief Set the coordinates of the sound's position. | ||
| * | ||
| */ | ||
| virtual void position(const Math::float3&) = 0; | ||
|
|
||
| /** | ||
| * @brief Set the components of the sound's velocity. | ||
| * | ||
| */ | ||
| virtual void velocity(const Math::float3&) = 0; | ||
|
|
||
| /** | ||
| * @brief Set the componenets of the sound's direction. | ||
| * | ||
| */ | ||
| virtual void direction(const Math::float3&) = 0; | ||
|
|
||
| /** | ||
| * @brief Set whether the sound's position is relative to the listener. | ||
| * | ||
| */ | ||
| virtual void relative(bool) = 0; | ||
|
|
||
| /** | ||
| * @brief Set wheter the sound should loop back to the beginning once it | ||
| * finishes playing. | ||
| * | ||
| * This is ignored in the case of streming sounds | ||
| */ | ||
| virtual void looping(bool) = 0; | ||
|
|
||
| /** | ||
| * @brief Get the playback state of this sound. | ||
| * | ||
| * @return State | ||
| */ | ||
| virtual State state() = 0; | ||
|
|
||
| /** | ||
| * @brief Starts sound playback. | ||
| * | ||
| * This method is idempotent: if the sound was already playing, | ||
| * nothing happens. | ||
| */ | ||
| virtual void play() = 0; | ||
| /** | ||
| * @brief Pauses sound playback. | ||
| * | ||
| * This method is idempotent: if the sound was already paused, | ||
| * nothing happens. | ||
| */ | ||
| virtual void pause() = 0; | ||
| /** | ||
| * @brief Stops sound playback. | ||
| * | ||
| * Playback will resume from the beginning. | ||
| * This method is idempotent: if the sound was already stopped, | ||
| * nothing happens. | ||
| */ | ||
| virtual void stop() = 0; | ||
| }; | ||
|
|
||
| using SoundPtr = std::shared_ptr<Sound>; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: it should be doable with unique_ptr
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't able to do it with a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the destruction order of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering that |
||
| using SoundStream = std::function<int(std::int16_t* buf, std::size_t size)>; | ||
|
|
||
| struct Orientation { | ||
| Math::float3 at; | ||
| Math::float3 up; | ||
| }; | ||
|
|
||
| /** An AudioEngine is the interface to the system's audio driver | ||
| * | ||
| */ | ||
| class AudioEngine final | ||
| class AudioEngine | ||
| { | ||
| public: | ||
| /** Initializes the AudioEngine. | ||
| * | ||
| * The @p device param specifies the device to use and can be determined | ||
| * using enumerateDevices(). | ||
| * | ||
| * @param device_name The name of the device to use. | ||
| * | ||
| * @see AudioEngine::enumerateDevices() | ||
| * | ||
| */ | ||
| AudioEngine(const std::string& device_name = std::string()); | ||
|
|
||
| /** Deinitializes the AudioEngine. | ||
| */ | ||
| ~AudioEngine(); | ||
|
|
||
| /** Returns the OpenAL device used by this engine. | ||
| * | ||
| * @return The OpenAL device or nullptr when initialization has failed. | ||
| */ | ||
| ALCdevice* getDevice() const { return m_Device; } | ||
| /** Enumerates the audio devices available on the current machine. | ||
| * | ||
| * Note that not all OpenAL implementations support enumeration. In this case you'll | ||
| * retrieve a single element list with an empty device name, indicating that it is | ||
| * the default device. | ||
| * | ||
| * @param[out] devices A list of available devices. | ||
| * | ||
| */ | ||
| static void enumerateDevices(std::vector<std::string>& devices); | ||
|
|
||
| /** Returns a text representation of an error code. | ||
| * | ||
| * @param The error code returned by alGetError() or alcGetError(). | ||
| * | ||
| * @return The error text. | ||
| * | ||
| */ | ||
| static const char* getErrorString(size_t errorCode); | ||
|
|
||
| private: | ||
| ALCdevice* m_Device = nullptr; | ||
| /** | ||
| * @brief Set master listener gain, must be positive | ||
| * | ||
| * 1 means original volume, <1 means lower gain, >1 means higher. | ||
| * | ||
| */ | ||
| virtual void gain(float) = 0; | ||
|
|
||
| /** | ||
| * @brief Set coordinates of listener's position | ||
| * | ||
| */ | ||
| virtual void position(const Math::float3&) = 0; | ||
|
|
||
| /** | ||
| * @brief Set components of listener's velocity | ||
| * | ||
| */ | ||
| virtual void velocity(const Math::float3&) = 0; | ||
|
|
||
| /** | ||
| * @brief Set listener's orientation | ||
| * | ||
| */ | ||
| virtual void orientation(const Orientation&) = 0; | ||
|
|
||
| /** | ||
| * @brief Creates a sound object from an audio buffer | ||
| * | ||
| * @return SoundPtr | ||
| */ | ||
| virtual SoundPtr createSound(const std::int16_t* buf, std::size_t len, Format, std::size_t samplingFreq) = 0; | ||
|
|
||
| /** | ||
| * @brief Creates a sound object from an audio stream | ||
| * | ||
| * @return SoundPtr | ||
| */ | ||
| virtual SoundPtr createSound(SoundStream, Format, std::size_t samplingFreq) = 0; | ||
| }; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.