[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 audio::Time& _playTime,
|
||||||
const size_t& _nbChunk,
|
const size_t& _nbChunk,
|
||||||
enum audio::format _format,
|
enum audio::format _format,
|
||||||
uint32_t _frequency,
|
uint32_t _sampleRate,
|
||||||
const std::vector<audio::channel>& _map) {
|
const std::vector<audio::channel>& _map) {
|
||||||
if (_format != audio::format_int16) {
|
if (_format != audio::format_int16) {
|
||||||
EWOLSA_ERROR("call wrong type ... (need int16_t)");
|
EWOLSA_ERROR("call wrong type ... (need int16_t)");
|
||||||
@ -79,4 +79,35 @@ void audio::ess::unInit() {
|
|||||||
g_ioInterface.reset();
|
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 {
|
namespace ess {
|
||||||
void init();
|
void init();
|
||||||
void unInit();
|
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 musicCurrentRead = -1;
|
||||||
static int32_t musicNextRead = -1;
|
static int32_t musicNextRead = -1;
|
||||||
|
|
||||||
void audio::ess::music::init() {
|
audio::ess::Music::Music(const std::shared_ptr<audio::river::Manager>& _manager) :
|
||||||
audio::ess::music::volumeSet(0);
|
m_manager(_manager),
|
||||||
audio::ess::music::muteSet(false);
|
m_position(0) {
|
||||||
std::unique_lock<std::mutex> lck(localMutex);
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
musicCurrentRead = -1;
|
//Set stereo output:
|
||||||
musicNextRead = -1;
|
std::vector<audio::channel> channelMap;
|
||||||
musicPositionReading = 0;
|
channelMap.push_back(audio::channel_frontLeft);
|
||||||
for (size_t iii=0; iii<musicListRead.size(); ++iii) {
|
channelMap.push_back(audio::channel_frontRight);
|
||||||
if (musicListRead[iii] == nullptr) {
|
m_interface = m_manager->createOutput(48000,
|
||||||
continue;
|
channelMap,
|
||||||
}
|
audio::format_int16,
|
||||||
delete musicListRead[iii];
|
"speaker");
|
||||||
musicListRead[iii] = nullptr;
|
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::~Music() {
|
||||||
audio::ess::music::volumeSet(-1000);
|
if (m_interface != nullptr) {
|
||||||
audio::ess::music::muteSet(true);
|
m_interface.stop();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
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__
|
#define __EWOLSA_MUSIC_H__
|
||||||
|
|
||||||
#include <etk/types.h>
|
#include <etk/types.h>
|
||||||
|
#include <audio/river/Interface.h>
|
||||||
|
#include <audio/river/Manager.h>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
namespace audio {
|
namespace audio {
|
||||||
namespace ess {
|
namespace ess {
|
||||||
namespace music {
|
class Music {
|
||||||
void init();
|
private:
|
||||||
void unInit();
|
std::mutex m_mutex;
|
||||||
void fading(int32_t _timeMs);
|
std::shared_ptr<audio::river::Manager> m_manager;
|
||||||
|
std::shared_ptr<audio::river::Interface> m_interface;
|
||||||
void preLoad(const std::string& _file);
|
public:
|
||||||
bool play(const std::string& _file);
|
Music(const std::shared_ptr<audio::river::Manager>& _manager);
|
||||||
bool stop();
|
~Music();
|
||||||
|
private:
|
||||||
// in db
|
void onDataNeeded(void* _data,
|
||||||
float volumeGet();
|
const audio::Time& _playTime,
|
||||||
void volumeSet(float _newVolume);
|
const size_t& _nbChunk,
|
||||||
bool muteGet();
|
enum audio::format _format,
|
||||||
void muteSet(bool _newMute);
|
uint32_t _sampleRate,
|
||||||
void getData(int16_t * _bufferInterlace, int32_t _nbSample, int32_t _nbChannels);
|
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