forked from MrBesen/soundboard
65 lines
1.4 KiB
C++
65 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "miniaudio.h"
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
#include <list>
|
|
#include <mutex>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
#include "sounddevice.h"
|
|
#include "samplereader.h"
|
|
|
|
#include "sound.h"
|
|
|
|
class Sound {
|
|
public:
|
|
using sndcb_func = std::function<void(uint64_t)>;
|
|
|
|
static Sound& instance();
|
|
static void deinitInstance();
|
|
|
|
void addPlayback(const std::string& name, float volume = 1.f, uint64_t beginms = 0, uint64_t length = 0);
|
|
void addPlayback(const std::string& audioDeviceName, const std::string& name, float volume = 1.f, uint64_t beginms = 0, uint64_t length = 0, sndcb_func callback = {});
|
|
bool addDefaultDevice();
|
|
bool addDeviceWithName(const std::string& name);
|
|
void stopAll();
|
|
void reset();
|
|
|
|
SampleReader* openFile(const std::string& name);
|
|
std::vector<std::string> getOutputs();
|
|
|
|
void setMasterVolume(float m);
|
|
float getMasterVolume() const;
|
|
|
|
static std::string FOLDER;
|
|
|
|
private:
|
|
Sound();
|
|
~Sound();
|
|
|
|
void deinit();
|
|
void init();
|
|
|
|
void backgroundThreadLoop();
|
|
void cleanAllDecoders();
|
|
|
|
void startBackgroundThread();
|
|
void stopBackgroundThread();
|
|
|
|
ma_context context;
|
|
bool threadShouldrun = false;
|
|
std::thread backgroundCleanup;
|
|
|
|
std::mutex devicesMutex;
|
|
std::vector<SoundDevice*> devices;
|
|
|
|
float masterVolume = 1.0;
|
|
|
|
static Sound* inst;
|
|
|
|
friend void sound_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount);
|
|
};
|