src/Audio/AudioBuffer.hpp

Namespaces

Name
Engine
This namespace contains all of the necessary engine components.
Engine::Audio

Classes

Name
class Engine::Audio::AudioBuffer
A simple audio buffer to hold PCM samples
struct Engine::Audio::AudioBuffer::TypedAudioData
Use this to populate the buffer.

Source code

#pragma once
#include "../Utils/ArrayView.hpp"

namespace Engine {
    namespace Audio {
        class AudioManager;
        class AudioBuffer;

        typedef int (*Callback)(AudioBuffer& buffer, size_t offset);

        using Callback2 = int (*)(AudioBuffer& buffer, size_t offset, void* user);

        extern void doSomething(AudioBuffer& buffer);

        class AudioBuffer {
        public:
            enum class Type {
                UNKNOWN = 0,
                INT_8 = 1 << 1,
                INT_16 = 1 << 2,
                INT_24 = 1 << 3,
                INT_32 = 1 << 4,
                FLOAT_32 = 1 << 5
            };
            template <typename T> using AudioData = Utils::ArrayView<T>;
            typedef AudioData<uint8_t> AudioData8U;
            struct TypedAudioData {
                AudioData8U buffer;
                Type type;
            };
            explicit AudioBuffer(const std::string& filename);
            virtual ~AudioBuffer() = default;
            void play(AudioManager& manager) const;
            void stop(AudioManager& manager) const;
            void loop(AudioManager& manager) const;
            void setData(const TypedAudioData& data);

            template <size_t Size> void setDataMultiple(const TypedAudioData data[Size]) {
            }

            void setData(const TypedAudioData data[], size_t size);

            friend class AudioManager;
            friend void Audio::doSomething(AudioBuffer& buffer);

            void setCallback(Callback callback);

            void setCallback2(Callback2 callback, void* user);

        protected:
            float* getData();
            bool playing{false};
        };
    } // namespace Audio
} // namespace Engine

Updated on 2022-10-19 at 22:22:05 +0000

results matching ""

    No results matching ""