[DEV] add Format get size ...

This commit is contained in:
Edouard DUPIN 2015-02-05 23:00:39 +01:00
parent 7f7a04f636
commit fe61e98059
4 changed files with 48 additions and 26 deletions

View File

@ -6,8 +6,10 @@
#include <audio/channel.h>
#include <audio/debug.h>
#include <etk/stdTools.h>
static const char* listValues[] = {
"unknow",
"front-left",
"front-center",
"front-right",
@ -67,35 +69,21 @@ std::ostream& audio::operator <<(std::ostream& _os, const std::vector<std::vecto
return _os;
}
static std::vector<std::string> split(const std::string& _input, char _val) {
std::vector<std::string> list;
size_t lastStartPos = 0;
for(size_t iii=0; iii<_input.size(); iii++) {
if (_input[iii]==_val) {
list.push_back(std::string(_input, lastStartPos, iii - lastStartPos));
lastStartPos = iii+1;
enum audio::channel audio::getChannelFromString(const std::string& _value) {
for (int32_t iii=0; iii<listValuesSize; ++iii) {
if (_value == listValues[iii]) {
return static_cast<enum audio::channel>(iii);
}
}
if (lastStartPos<_input.size()) {
list.push_back(std::string(_input, lastStartPos));
}
return list;
AUDIO_ERROR("Can not convert : '" << _value << "' ...");
return audio::channel_unknow;
}
std::vector<enum audio::channel> audio::getChannelFromString(const std::string& _value) {
std::vector<enum audio::channel> audio::getListChannelFromString(const std::string& _value) {
std::vector<enum audio::channel> out;
std::vector<std::string> listIO = split(_value, ';');
for (size_t iii=0; iii<listIO.size(); ++iii) {
int32_t tmpCount = out.size();
for (int32_t jjj=0; jjj<listValuesSize; ++jjj) {
if (listIO[iii] == listValues[jjj]) {
out.push_back(static_cast<enum audio::channel>(jjj));
break;
}
}
if (tmpCount == out.size()) {
AUDIO_ERROR("Can not convert : '" << _value << "' ...");
}
std::vector<std::string> list = etk::split(_value, ';');
for (auto &it : list) {
out.push_back(getChannelFromString(it));
}
return out;
}

View File

@ -12,6 +12,7 @@
namespace audio {
enum channel {
channel_unknow, //!< Error channel ...
channel_frontLeft, //!< channel Front Left
channel_frontCenter, //!< channel Front Center
channel_frontRight, //!< channel Front Right
@ -25,7 +26,8 @@ namespace audio {
};
std::string getChannelString(enum audio::channel _obj);
std::string getChannelString(const std::vector<enum audio::channel>& _obj);
std::vector<enum audio::channel> getChannelFromString(const std::string& _value);
enum audio::channel getChannelFromString(const std::string& _value);
std::vector<enum audio::channel> getListChannelFromString(const std::string& _value);
std::ostream& operator <<(std::ostream& _os, enum audio::channel _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<enum audio::channel>& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<std::vector<enum audio::channel>>& _obj);

View File

@ -40,6 +40,7 @@ std::string audio::getFormatString(enum audio::format _value) {
return listValues[_value];
}
enum audio::format audio::getFormatFromString(const std::string& _value) {
for (int32_t iii=0; iii<listValuesSize; ++iii) {
if (_value == listValues[iii]) {
@ -47,4 +48,33 @@ enum audio::format audio::getFormatFromString(const std::string& _value) {
}
}
return format_unknow;
}
std::vector<enum audio::format> audio::getListFormatFromString(const std::string& _value) {
std::vector<enum audio::format> out;
std::vector<std::string> list = etk::split(_value, ';');
for (auto &it : list) {
out.push_back(getFormatFromString(it));
}
return out;
}
uint32_t audio::getFormatBytes(audio::format _format) {
if (_format == audio::format_int8) {
return sizeof(int8_t);
} else if (_format == audio::format_int16) {
return sizeof(int16_t);
} else if (_format == audio::format_int16_on_int32) {
return sizeof(int32_t);
} else if (_format == audio::format_int24) {
return sizeof(int32_t);
} else if (_format == audio::format_int32) {
return sizeof(int32_t);
} else if (_format == audio::format_float) {
return sizeof(float);
} else if (_format == audio::format_double) {
return sizeof(double);
}
AUDIO_ERROR("undefined format : " << _format);
return 0;
}

View File

@ -20,10 +20,12 @@ namespace audio {
format_float, //!< Floating point (single precision)
format_double //!< Floating point (double precision)
};
std::string getFormatString(enum audio::format);
std::string getFormatString(enum audio::format _format);
enum audio::format getFormatFromString(const std::string& _value);
std::vector<enum audio::format> getListFormatFromString(const std::string& _value);
std::ostream& operator <<(std::ostream& _os, enum audio::format _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<enum audio::format>& _obj);
uint32_t getFormatBytes(enum audio::format _format);
};