41 lines
830 B
C++
41 lines
830 B
C++
#pragma once
|
|
|
|
#include "miniaudio.h"
|
|
|
|
#include <atomic>
|
|
#include <memory>
|
|
|
|
struct PlaybackState {
|
|
ma_decoder decoder{};
|
|
std::atomic<bool> finished{ false };
|
|
};
|
|
|
|
class PlaybackEngine {
|
|
public:
|
|
PlaybackEngine();
|
|
~PlaybackEngine();
|
|
|
|
static void data_callback( ma_device* pDevice, void* pOutput, const void*, ma_uint32 frameCount );
|
|
void configureDevice();
|
|
void configureDecoder();
|
|
void initDevice();
|
|
void initDecoder( const char* filePath );
|
|
|
|
void startPlayback();
|
|
void stopPlayback();
|
|
void pausePlayback() { stopPlayback(); };
|
|
int isFinished() const;
|
|
|
|
private:
|
|
|
|
ma_device device_;
|
|
ma_format format_;
|
|
unsigned int channels_;
|
|
unsigned int sampleRate_;
|
|
PlaybackState state;
|
|
|
|
//config
|
|
ma_decoder_config decoderConfig;
|
|
ma_device_config deviceConfig;
|
|
};
|