| 1 | /** |
| 2 | * Copyright (c) 2006-2023 LOVE Development Team |
| 3 | * |
| 4 | * This software is provided 'as-is', without any express or implied |
| 5 | * warranty. In no event will the authors be held liable for any damages |
| 6 | * arising from the use of this software. |
| 7 | * |
| 8 | * Permission is granted to anyone to use this software for any purpose, |
| 9 | * including commercial applications, and to alter it and redistribute it |
| 10 | * freely, subject to the following restrictions: |
| 11 | * |
| 12 | * 1. The origin of this software must not be misrepresented; you must not |
| 13 | * claim that you wrote the original software. If you use this software |
| 14 | * in a product, an acknowledgment in the product documentation would be |
| 15 | * appreciated but is not required. |
| 16 | * 2. Altered source versions must be plainly marked as such, and must not be |
| 17 | * misrepresented as being the original software. |
| 18 | * 3. This notice may not be removed or altered from any source distribution. |
| 19 | **/ |
| 20 | |
| 21 | #ifndef LOVE_AUDIO_SOURCE_H |
| 22 | #define LOVE_AUDIO_SOURCE_H |
| 23 | |
| 24 | // LOVE |
| 25 | #include "common/Object.h" |
| 26 | #include "common/StringMap.h" |
| 27 | #include "Filter.h" |
| 28 | |
| 29 | #include <vector> |
| 30 | |
| 31 | namespace love |
| 32 | { |
| 33 | namespace audio |
| 34 | { |
| 35 | |
| 36 | class Source : public Object |
| 37 | { |
| 38 | public: |
| 39 | |
| 40 | static love::Type type; |
| 41 | |
| 42 | enum Type |
| 43 | { |
| 44 | TYPE_STATIC, |
| 45 | TYPE_STREAM, |
| 46 | TYPE_QUEUE, |
| 47 | TYPE_MAX_ENUM |
| 48 | }; |
| 49 | |
| 50 | enum Unit |
| 51 | { |
| 52 | UNIT_SECONDS, |
| 53 | UNIT_SAMPLES, |
| 54 | UNIT_MAX_ENUM |
| 55 | }; |
| 56 | |
| 57 | Source(Type type); |
| 58 | virtual ~Source(); |
| 59 | |
| 60 | virtual Source *clone() = 0; |
| 61 | |
| 62 | virtual bool play() = 0; |
| 63 | virtual void stop() = 0; |
| 64 | virtual void pause() = 0; |
| 65 | virtual bool isPlaying() const = 0; |
| 66 | virtual bool isFinished() const = 0; |
| 67 | virtual bool update() = 0; |
| 68 | |
| 69 | virtual void setPitch(float pitch) = 0; |
| 70 | virtual float getPitch() const = 0; |
| 71 | |
| 72 | virtual void setVolume(float volume) = 0; |
| 73 | virtual float getVolume() const = 0; |
| 74 | |
| 75 | virtual void seek(double offset, Unit unit) = 0; |
| 76 | virtual double tell(Unit unit) = 0; |
| 77 | virtual double getDuration(Unit unit) = 0; |
| 78 | |
| 79 | // all float * v must be of size 3 |
| 80 | virtual void setPosition(float *v) = 0; |
| 81 | virtual void getPosition(float *v) const = 0; |
| 82 | virtual void setVelocity(float *v) = 0; |
| 83 | virtual void getVelocity(float *v) const = 0; |
| 84 | virtual void setDirection(float *v) = 0; |
| 85 | virtual void getDirection(float *v) const = 0; |
| 86 | |
| 87 | virtual void setCone(float innerAngle, float outerAngle, float outerVolume, float outerHighGain) = 0; |
| 88 | virtual void getCone(float &innerAngle, float &outerAngle, float &outerVolume, float &outerHighGain) const = 0; |
| 89 | |
| 90 | virtual void setRelative(bool enable) = 0; |
| 91 | virtual bool isRelative() const = 0; |
| 92 | |
| 93 | virtual void setLooping(bool looping) = 0; |
| 94 | virtual bool isLooping() const = 0; |
| 95 | |
| 96 | virtual void setMinVolume(float volume) = 0; |
| 97 | virtual float getMinVolume() const = 0; |
| 98 | virtual void setMaxVolume(float volume) = 0; |
| 99 | virtual float getMaxVolume() const = 0; |
| 100 | |
| 101 | virtual void setReferenceDistance(float distance) = 0; |
| 102 | virtual float getReferenceDistance() const = 0; |
| 103 | virtual void setRolloffFactor(float factor) = 0; |
| 104 | virtual float getRolloffFactor() const = 0; |
| 105 | virtual void setMaxDistance(float distance) = 0; |
| 106 | virtual float getMaxDistance() const = 0; |
| 107 | virtual void setAirAbsorptionFactor(float factor) = 0; |
| 108 | virtual float getAirAbsorptionFactor() const = 0; |
| 109 | |
| 110 | virtual int getChannelCount() const = 0; |
| 111 | |
| 112 | virtual bool setFilter(const std::map<Filter::Parameter, float> ¶ms) = 0; |
| 113 | virtual bool setFilter() = 0; |
| 114 | virtual bool getFilter(std::map<Filter::Parameter, float> ¶ms) = 0; |
| 115 | |
| 116 | virtual bool setEffect(const char *effect) = 0; |
| 117 | virtual bool setEffect(const char *effect, const std::map<Filter::Parameter, float> ¶ms) = 0; |
| 118 | virtual bool unsetEffect(const char *effect) = 0; |
| 119 | virtual bool getEffect(const char *effect, std::map<Filter::Parameter, float> ¶ms) = 0; |
| 120 | virtual bool getActiveEffects(std::vector<std::string> &list) const = 0; |
| 121 | |
| 122 | virtual int getFreeBufferCount() const = 0; |
| 123 | virtual bool queue(void *data, size_t length, int dataSampleRate, int dataBitDepth, int dataChannels) = 0; |
| 124 | |
| 125 | virtual Type getType() const; |
| 126 | |
| 127 | static bool getConstant(const char *in, Type &out); |
| 128 | static bool getConstant(Type in, const char *&out); |
| 129 | static std::vector<std::string> getConstants(Type); |
| 130 | static bool getConstant(const char *in, Unit &out); |
| 131 | static bool getConstant(Unit in, const char *&out); |
| 132 | static std::vector<std::string> getConstants(Unit); |
| 133 | |
| 134 | protected: |
| 135 | |
| 136 | Type sourceType; |
| 137 | |
| 138 | private: |
| 139 | |
| 140 | static StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[]; |
| 141 | static StringMap<Type, TYPE_MAX_ENUM> types; |
| 142 | static StringMap<Unit, UNIT_MAX_ENUM>::Entry unitEntries[]; |
| 143 | static StringMap<Unit, UNIT_MAX_ENUM> units; |
| 144 | |
| 145 | }; // Source |
| 146 | |
| 147 | } // audio |
| 148 | } // love |
| 149 | |
| 150 | #endif // LOVE_AUDIO_SOURCE_H |
| 151 | |