forked from MrBesen/soundboard
56 lines
1.2 KiB
C++
56 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include "miniaudio.h"
|
|
|
|
#include <string>
|
|
#include <list>
|
|
#include <mutex>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
#include "sounddevice.h"
|
|
#include "samplereader.h"
|
|
|
|
#include "sound.h"
|
|
|
|
class Sound {
|
|
public:
|
|
static Sound& instance();
|
|
static void deinitInstance();
|
|
|
|
void addPlayback(const std::string& name, float volume = 1.f, uint64_t beginms = 0, uint64_t endms = 0);
|
|
void addPlayback(const std::string& audioDeviceName, const std::string& name, float volume = 1.f, uint64_t beginms = 0, uint64_t endms = 0);
|
|
bool addDefaultDevice();
|
|
bool addDeviceWithName(const std::string& name);
|
|
void stopAll();
|
|
void reset();
|
|
|
|
SampleReader* openFile(const std::string& name);
|
|
std::vector<std::string> getOutputs();
|
|
|
|
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;
|
|
|
|
static Sound* inst;
|
|
|
|
friend void sound_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount);
|
|
};
|