[DEV] update sharedPtr

This commit is contained in:
Edouard DUPIN 2016-07-19 21:43:58 +02:00
parent 8b86ac13ec
commit cf2a769087
7 changed files with 29 additions and 28 deletions

View File

@ -53,7 +53,7 @@ audio::ess::LoadedFile::LoadedFile(const std::string& _fileName, int8_t _nbChanR
#if defined(__TARGET_OS__Android) #if defined(__TARGET_OS__Android)
pthread_create(&m_thread, nullptr, &audio::ess::LoadedFile::threadCallback, this); pthread_create(&m_thread, nullptr, &audio::ess::LoadedFile::threadCallback, this);
#else #else
m_thread = std::make_shared<std::thread>(&audio::ess::LoadedFile::threadCall, this); m_thread = ememory::makeShared<std::thread>(&audio::ess::LoadedFile::threadCall, this);
if (m_thread == nullptr) { if (m_thread == nullptr) {
EWOLSA_ERROR("Can not create thread ..."); EWOLSA_ERROR("Can not create thread ...");
return; return;

View File

@ -7,6 +7,7 @@
#include <etk/types.h> #include <etk/types.h>
#include <thread> #include <thread>
#include <ememory/memory.h>
namespace audio { namespace audio {
namespace ess { namespace ess {
@ -21,7 +22,7 @@ namespace audio {
#if defined(__TARGET_OS__Android) #if defined(__TARGET_OS__Android)
pthread_t m_thread; pthread_t m_thread;
#else #else
std::shared_ptr<std::thread> m_thread; ememory::SharedPtr<std::thread> m_thread;
#endif #endif
public: public:
LoadedFile(const std::string& _fileName, int8_t _nbChanRequested=1); LoadedFile(const std::string& _fileName, int8_t _nbChanRequested=1);

View File

@ -12,7 +12,7 @@
#include <audio/ess/decWav.h> #include <audio/ess/decWav.h>
#include <math.h> #include <math.h>
audio::ess::Effects::Effects(const std::shared_ptr<audio::river::Manager>& _manager) : audio::ess::Effects::Effects(const ememory::SharedPtr<audio::river::Manager>& _manager) :
m_manager(_manager) { m_manager(_manager) {
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
//Set stereo output: //Set stereo output:
@ -51,7 +51,7 @@ audio::ess::Effects::~Effects() {
} }
static bool playData(const std::shared_ptr<audio::ess::LoadedFile>& _file, int32_t& _position, int16_t* _bufferInterlace, int32_t _nbSample) { static bool playData(const ememory::SharedPtr<audio::ess::LoadedFile>& _file, int32_t& _position, int16_t* _bufferInterlace, int32_t _nbSample) {
if ( _file == nullptr if ( _file == nullptr
|| _file->m_data.size() == 0) { || _file->m_data.size() == 0) {
return true; return true;
@ -59,7 +59,7 @@ static bool playData(const std::shared_ptr<audio::ess::LoadedFile>& _file, int32
int32_t processTimeMax = std::min(_nbSample, _file->m_nbSamples - _position); int32_t processTimeMax = std::min(_nbSample, _file->m_nbSamples - _position);
processTimeMax = std::max(0, processTimeMax); processTimeMax = std::max(0, processTimeMax);
int16_t * pointer = _bufferInterlace; int16_t * pointer = _bufferInterlace;
int16_t * newData = &_file->m_data[_position]; const int16_t * newData = &_file->m_data[_position];
//EWOLSA_DEBUG("AUDIO : Play slot... nb sample : " << processTimeMax << " playTime=" <<m_playTime << " nbCannels=" << nbChannels); //EWOLSA_DEBUG("AUDIO : Play slot... nb sample : " << processTimeMax << " playTime=" <<m_playTime << " nbCannels=" << nbChannels);
for (int32_t iii=0; iii<processTimeMax; iii++) { for (int32_t iii=0; iii<processTimeMax; iii++) {
int32_t tmppp = int32_t(*_bufferInterlace) + int32_t(*newData); int32_t tmppp = int32_t(*_bufferInterlace) + int32_t(*newData);
@ -99,7 +99,7 @@ void audio::ess::Effects::onDataNeeded(void* _data,
void audio::ess::Effects::load(const std::string& _file, const std::string& _name) { void audio::ess::Effects::load(const std::string& _file, const std::string& _name) {
// load the file: // load the file:
std::shared_ptr<audio::ess::LoadedFile> tmp = std::make_shared<audio::ess::LoadedFile>(_file, 2); ememory::SharedPtr<audio::ess::LoadedFile> tmp = ememory::makeShared<audio::ess::LoadedFile>(_file, 2);
if (tmp == nullptr) { if (tmp == nullptr) {
EWOLSA_ERROR("can not load audio Effects = " << _file); EWOLSA_ERROR("can not load audio Effects = " << _file);
return; return;
@ -113,7 +113,7 @@ void audio::ess::Effects::load(const std::string& _file, const std::string& _nam
} }
} }
if (-1 <= id) { if (-1 <= id) {
m_list.push_back(std::pair<std::string,std::shared_ptr<audio::ess::LoadedFile>>(_name,tmp)); m_list.push_back(std::pair<std::string,ememory::SharedPtr<audio::ess::LoadedFile>>(_name,tmp));
} else { } else {
m_list[id].second = tmp; m_list[id].second = tmp;
} }
@ -126,7 +126,7 @@ int32_t audio::ess::Effects::getId(const std::string& _name) {
return iii; return iii;
} }
} }
m_list.push_back(std::pair<std::string,std::shared_ptr<audio::ess::LoadedFile>>(_name,nullptr)); m_list.push_back(std::pair<std::string,ememory::SharedPtr<audio::ess::LoadedFile>>(_name,nullptr));
EWOLSA_WARNING("Can not find element name : '" << _name << "' added it ... (empty) "); EWOLSA_WARNING("Can not find element name : '" << _name << "' added it ... (empty) ");
return m_list.size()-1; return m_list.size()-1;
} }
@ -138,7 +138,7 @@ void audio::ess::Effects::play(int32_t _id, const vec3& _pos) {
EWOLSA_ERROR(" Can not play element audio with ID=" << _id << " out of [0.." << m_list.size() << "["); EWOLSA_ERROR(" Can not play element audio with ID=" << _id << " out of [0.." << m_list.size() << "[");
return; return;
} }
m_playing.push_back(std::pair<std::shared_ptr<audio::ess::LoadedFile>, int32_t>(m_list[_id].second, 0)); m_playing.push_back(std::pair<ememory::SharedPtr<audio::ess::LoadedFile>, int32_t>(m_list[_id].second, 0));
} }
void audio::ess::Effects::play(const std::string& _name, const vec3& _pos) { void audio::ess::Effects::play(const std::string& _name, const vec3& _pos) {

View File

@ -17,10 +17,10 @@ namespace audio {
class Effects { class Effects {
private: private:
mutable std::mutex m_mutex; mutable std::mutex m_mutex;
std::shared_ptr<audio::river::Manager> m_manager; ememory::SharedPtr<audio::river::Manager> m_manager;
std::shared_ptr<audio::river::Interface> m_interface; ememory::SharedPtr<audio::river::Interface> m_interface;
public: public:
Effects(const std::shared_ptr<audio::river::Manager>& _manager); Effects(const ememory::SharedPtr<audio::river::Manager>& _manager);
~Effects(); ~Effects();
private: private:
void onDataNeeded(void* _data, void onDataNeeded(void* _data,
@ -29,8 +29,8 @@ namespace audio {
enum audio::format _format, enum audio::format _format,
uint32_t _sampleRate, uint32_t _sampleRate,
const std::vector<audio::channel>& _map); const std::vector<audio::channel>& _map);
std::vector<std::pair<std::shared_ptr<audio::ess::LoadedFile>, int32_t>> m_playing; //!< current music read std::vector<std::pair<ememory::SharedPtr<audio::ess::LoadedFile>, int32_t>> m_playing; //!< current music read
std::vector<std::pair<std::string, std::shared_ptr<audio::ess::LoadedFile>>> m_list; //!< list of all effect loaded std::vector<std::pair<std::string, ememory::SharedPtr<audio::ess::LoadedFile>>> m_list; //!< list of all effect loaded
public: public:
void load(const std::string& _file, const std::string& _name); void load(const std::string& _file, const std::string& _name);
int32_t getId(const std::string& _name); int32_t getId(const std::string& _name);

View File

@ -13,14 +13,14 @@
#include <audio/ess/debug.h> #include <audio/ess/debug.h>
#include <ejson/ejson.h> #include <ejson/ejson.h>
std::shared_ptr<audio::river::Manager> g_audioManager; ememory::SharedPtr<audio::river::Manager> g_audioManager;
std::shared_ptr<audio::ess::Effects> g_effects; ememory::SharedPtr<audio::ess::Effects> g_effects;
std::shared_ptr<audio::ess::Music> g_music; ememory::SharedPtr<audio::ess::Music> g_music;
void audio::ess::init() { void audio::ess::init() {
g_audioManager = audio::river::Manager::create("ewol-sound-set"); g_audioManager = audio::river::Manager::create("ewol-sound-set");
g_effects = std::make_shared<audio::ess::Effects>(g_audioManager); g_effects = ememory::makeShared<audio::ess::Effects>(g_audioManager);
g_music = std::make_shared<audio::ess::Music>(g_audioManager); g_music = ememory::makeShared<audio::ess::Music>(g_audioManager);
} }
void audio::ess::unInit() { void audio::ess::unInit() {

View File

@ -12,7 +12,7 @@
#include <audio/ess/LoadedFile.h> #include <audio/ess/LoadedFile.h>
#include <math.h> #include <math.h>
audio::ess::Music::Music(const std::shared_ptr<audio::river::Manager>& _manager) : audio::ess::Music::Music(const ememory::SharedPtr<audio::river::Manager>& _manager) :
m_manager(_manager), m_manager(_manager),
m_position(0) { m_position(0) {
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
@ -97,13 +97,13 @@ void audio::ess::Music::load(const std::string& _file, const std::string& _name)
if (it != m_list.end()) { if (it != m_list.end()) {
return; return;
} }
std::shared_ptr<audio::ess::LoadedFile> tmp = std::make_shared<audio::ess::LoadedFile>(_file, 2); ememory::SharedPtr<audio::ess::LoadedFile> tmp = ememory::makeShared<audio::ess::LoadedFile>(_file, 2);
if (tmp == nullptr) { if (tmp == nullptr) {
EWOLSA_ERROR("can not load audio Music = " << _file); EWOLSA_ERROR("can not load audio Music = " << _file);
return; return;
} }
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
m_list.insert(std::pair<std::string,std::shared_ptr<audio::ess::LoadedFile>>(_name,tmp)); m_list.insert(std::pair<std::string,ememory::SharedPtr<audio::ess::LoadedFile>>(_name,tmp));
} }
void audio::ess::Music::play(const std::string& _name) { void audio::ess::Music::play(const std::string& _name) {

View File

@ -18,10 +18,10 @@ namespace audio {
class Music { class Music {
private: private:
mutable std::mutex m_mutex; mutable std::mutex m_mutex;
std::shared_ptr<audio::river::Manager> m_manager; ememory::SharedPtr<audio::river::Manager> m_manager;
std::shared_ptr<audio::river::Interface> m_interface; ememory::SharedPtr<audio::river::Interface> m_interface;
public: public:
Music(const std::shared_ptr<audio::river::Manager>& _manager); Music(const ememory::SharedPtr<audio::river::Manager>& _manager);
~Music(); ~Music();
private: private:
void onDataNeeded(void* _data, void onDataNeeded(void* _data,
@ -30,10 +30,10 @@ namespace audio {
enum audio::format _format, enum audio::format _format,
uint32_t _sampleRate, uint32_t _sampleRate,
const std::vector<audio::channel>& _map); const std::vector<audio::channel>& _map);
std::shared_ptr<audio::ess::LoadedFile> m_current; //!< current music read ememory::SharedPtr<audio::ess::LoadedFile> m_current; //!< current music read
int32_t m_position; //!< current position of music read int32_t m_position; //!< current position of music read
std::map<std::string, std::shared_ptr<audio::ess::LoadedFile> > m_list; //!< list of all music loaded std::map<std::string, ememory::SharedPtr<audio::ess::LoadedFile> > m_list; //!< list of all music loaded
std::shared_ptr<audio::ess::LoadedFile> m_next; //!< next music to read ememory::SharedPtr<audio::ess::LoadedFile> m_next; //!< next music to read
public: public:
void load(const std::string& _file, const std::string& _name); void load(const std::string& _file, const std::string& _name);
void play(const std::string& _name); void play(const std::string& _name);