soundboard/include/sounddevice.h

51 lines
1.1 KiB
C
Raw Normal View History

2021-12-13 00:28:04 +01:00
#pragma once
#include "miniaudio.h"
2021-12-20 02:13:26 +01:00
#include <functional>
2021-12-13 00:28:04 +01:00
#include <list>
2021-12-13 17:28:32 +01:00
#include <limits>
2021-12-13 00:28:04 +01:00
#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();
2021-12-22 12:52:25 +01:00
void addPlayback(const std::string& name, float volume = 1.f, uint64_t beginms = 0, uint64_t length = 0, std::function<void(uint64_t)> callback = {});
2021-12-13 00:28:04 +01:00
void startDevice();
void cleanupDecoders(); //fertige decoder löschen
2021-12-20 01:30:04 +01:00
std::string getName() const;
2021-12-13 00:28:04 +01:00
// callback
void sound_callback(void* outbuffer, ma_uint32 frameCount);
private:
struct Playback {
ma_decoder decoder;
float volume;
2021-12-13 17:28:32 +01:00
uint64_t currentFrame = 0;
uint64_t startFrame = 0;
uint64_t endFrame = std::numeric_limits<uint64_t>::max();
2021-12-13 00:28:04 +01:00
bool isDone = false;
2021-12-20 02:13:26 +01:00
std::function<void(uint64_t)> callback;
2021-12-13 00:28:04 +01:00
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;
};