soundboard/include/sounddevice.h

44 lines
896 B
C++

#pragma once
#include "miniaudio.h"
#include <list>
#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);
void startDevice();
void cleanupDecoders(); //fertige decoder löschen
// callback
void sound_callback(void* outbuffer, ma_uint32 frameCount);
private:
struct Playback {
ma_decoder decoder;
float volume;
bool isDone = false;
Playback() {}
};
struct SoundData {
std::list<Playback*> playbacks; //liste der decoder
unsigned int decoderCount = 0;
unsigned int musicdecoderCount = 0;
ma_mutex* mutex;
};
bool deviceRunning = false;
ma_device device;
SoundData data;
};