51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
|
|
#pragma once
|
|
|
|
#include "miniaudio.h"
|
|
|
|
#include <functional>
|
|
#include <list>
|
|
#include <limits>
|
|
#include <string>
|
|
|
|
class SoundDevice {
|
|
SoundDevice();
|
|
|
|
public:
|
|
~SoundDevice();
|
|
static SoundDevice* createDevice(ma_context* ctx, const std::string& name); // get device with name
|
|
static SoundDevice* createDevice(ma_context* ctx, const ma_device_id* did = NULL);
|
|
|
|
void stop();
|
|
void addPlayback(const std::string& name, float volume = 1.f, uint64_t beginms = 0, uint64_t endms = 0, std::function<void(uint64_t)> callback = {});
|
|
|
|
void startDevice();
|
|
void cleanupDecoders(); //fertige decoder löschen
|
|
|
|
std::string getName() const;
|
|
|
|
// callback
|
|
void sound_callback(void* outbuffer, ma_uint32 frameCount);
|
|
|
|
private:
|
|
struct Playback {
|
|
ma_decoder decoder;
|
|
float volume;
|
|
uint64_t currentFrame = 0;
|
|
uint64_t startFrame = 0;
|
|
uint64_t endFrame = std::numeric_limits<uint64_t>::max();
|
|
bool isDone = false;
|
|
std::function<void(uint64_t)> callback;
|
|
Playback() {}
|
|
};
|
|
|
|
struct SoundData {
|
|
std::list<Playback*> playbacks; //liste der decoder
|
|
unsigned int decoderCount = 0;
|
|
ma_mutex* mutex;
|
|
};
|
|
|
|
bool deviceRunning = false;
|
|
ma_device device;
|
|
SoundData data;
|
|
}; |