[DEV] rework ESS ==> better interfaces
This commit is contained in:
parent
404fc89275
commit
a729db25e0
@ -58,7 +58,7 @@ class OutputInterface {
|
||||
const audio::Time& _playTime,
|
||||
const size_t& _nbChunk,
|
||||
enum audio::format _format,
|
||||
uint32_t _frequency,
|
||||
uint32_t _sampleRate,
|
||||
const std::vector<audio::channel>& _map) {
|
||||
if (_format != audio::format_int16) {
|
||||
EWOLSA_ERROR("call wrong type ... (need int16_t)");
|
||||
@ -79,4 +79,35 @@ void audio::ess::unInit() {
|
||||
g_ioInterface.reset();
|
||||
}
|
||||
|
||||
void audio::ess::loadSoundSet(const std::string& _data) {
|
||||
|
||||
}
|
||||
|
||||
void audio::ess::loadSoundSet(const etk::FSNode& _file) {
|
||||
|
||||
}
|
||||
|
||||
void audio::ess::musicPlay(const std::string& _name) {
|
||||
|
||||
}
|
||||
|
||||
void audio::ess::musicStop() {
|
||||
|
||||
}
|
||||
|
||||
void audio::ess::musicVolume(float _dB) {
|
||||
|
||||
}
|
||||
|
||||
int32_t audio::ess::effectGetId(const std::string& _name) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void audio::ess::effectPlay(int32_t _name, const vec2& _pos=vec2(0,0)) {
|
||||
|
||||
}
|
||||
|
||||
void audio::ess::effectPlay(const std::string& _name, const vec2& _pos=vec2(0,0)) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,17 @@ namespace audio {
|
||||
namespace ess {
|
||||
void init();
|
||||
void unInit();
|
||||
|
||||
void loadSoundSet(const std::string& _data);
|
||||
void loadSoundSet(const etk::FSNode& _file);
|
||||
|
||||
void musicPlay(const std::string& _name);
|
||||
void musicStop();
|
||||
void musicVolume(float _dB);
|
||||
|
||||
int32_t effectGetId(const std::string& _name);
|
||||
void effectPlay(int32_t _name, const vec2& _pos=vec2(0,0));
|
||||
void effectPlay(const std::string& _name, const vec2& _pos=vec2(0,0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,38 +26,44 @@ static std::vector<audio::ess::LoadedFile*> musicListRead;
|
||||
static int32_t musicCurrentRead = -1;
|
||||
static int32_t musicNextRead = -1;
|
||||
|
||||
void audio::ess::music::init() {
|
||||
audio::ess::music::volumeSet(0);
|
||||
audio::ess::music::muteSet(false);
|
||||
std::unique_lock<std::mutex> lck(localMutex);
|
||||
musicCurrentRead = -1;
|
||||
musicNextRead = -1;
|
||||
musicPositionReading = 0;
|
||||
for (size_t iii=0; iii<musicListRead.size(); ++iii) {
|
||||
if (musicListRead[iii] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
delete musicListRead[iii];
|
||||
musicListRead[iii] = nullptr;
|
||||
audio::ess::Music::Music(const std::shared_ptr<audio::river::Manager>& _manager) :
|
||||
m_manager(_manager),
|
||||
m_position(0) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
//Set stereo output:
|
||||
std::vector<audio::channel> channelMap;
|
||||
channelMap.push_back(audio::channel_frontLeft);
|
||||
channelMap.push_back(audio::channel_frontRight);
|
||||
m_interface = m_manager->createOutput(48000,
|
||||
channelMap,
|
||||
audio::format_int16,
|
||||
"speaker");
|
||||
if (m_interface == nullptr) {
|
||||
EWOLSA_ERROR("can not allocate output interface ... ");
|
||||
return;
|
||||
}
|
||||
musicListRead.clear();
|
||||
m_interface->setName("audio::ess::music");
|
||||
m_interface->addVolumeGroup("MUSIC");
|
||||
// set callback mode ...
|
||||
m_interface->setOutputCallback(std::bind(&audio::ess::Music::onDataNeeded,
|
||||
this,
|
||||
std::placeholders::_1,
|
||||
std::placeholders::_2,
|
||||
std::placeholders::_3,
|
||||
std::placeholders::_4,
|
||||
std::placeholders::_5,
|
||||
std::placeholders::_6));
|
||||
}
|
||||
|
||||
void audio::ess::music::unInit() {
|
||||
audio::ess::music::volumeSet(-1000);
|
||||
audio::ess::music::muteSet(true);
|
||||
std::unique_lock<std::mutex> lck(localMutex);
|
||||
musicCurrentRead = -1;
|
||||
musicNextRead = -1;
|
||||
musicPositionReading = 0;
|
||||
for (size_t iii=0; iii<musicListRead.size(); ++iii) {
|
||||
if (musicListRead[iii] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
delete musicListRead[iii];
|
||||
musicListRead[iii] = nullptr;
|
||||
audio::ess::Music::~Music() {
|
||||
if (m_interface != nullptr) {
|
||||
m_interface.stop();
|
||||
}
|
||||
musicListRead.clear();
|
||||
m_interface.reset();
|
||||
m_manager.reset();
|
||||
m_list.clear();
|
||||
m_current.reset();
|
||||
m_next.reset();
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,24 +11,36 @@
|
||||
#define __EWOLSA_MUSIC_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <audio/river/Interface.h>
|
||||
#include <audio/river/Manager.h>
|
||||
#include <mutex>
|
||||
|
||||
namespace audio {
|
||||
namespace ess {
|
||||
namespace music {
|
||||
void init();
|
||||
void unInit();
|
||||
void fading(int32_t _timeMs);
|
||||
|
||||
void preLoad(const std::string& _file);
|
||||
bool play(const std::string& _file);
|
||||
bool stop();
|
||||
|
||||
// in db
|
||||
float volumeGet();
|
||||
void volumeSet(float _newVolume);
|
||||
bool muteGet();
|
||||
void muteSet(bool _newMute);
|
||||
void getData(int16_t * _bufferInterlace, int32_t _nbSample, int32_t _nbChannels);
|
||||
class Music {
|
||||
private:
|
||||
std::mutex m_mutex;
|
||||
std::shared_ptr<audio::river::Manager> m_manager;
|
||||
std::shared_ptr<audio::river::Interface> m_interface;
|
||||
public:
|
||||
Music(const std::shared_ptr<audio::river::Manager>& _manager);
|
||||
~Music();
|
||||
private:
|
||||
void onDataNeeded(void* _data,
|
||||
const audio::Time& _playTime,
|
||||
const size_t& _nbChunk,
|
||||
enum audio::format _format,
|
||||
uint32_t _sampleRate,
|
||||
const std::vector<audio::channel>& _map);
|
||||
std::shared_ptr<audio::ess::LoadedFile> m_current; //!< current music read
|
||||
int32_t m_position; //!< current position of music read
|
||||
std::vector<std::shared_ptr<audio::ess::LoadedFile>> m_list; //!< list of all music loaded
|
||||
std::shared_ptr<audio::ess::LoadedFile> m_next; //!< next music to read
|
||||
public:
|
||||
void load(const std::string& _file, const std::string& _name);
|
||||
void play(const std::string& _name);
|
||||
void stop();
|
||||
void clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user