[DEV] add Format get size ...
This commit is contained in:
parent
7f7a04f636
commit
fe61e98059
@ -6,8 +6,10 @@
|
|||||||
|
|
||||||
#include <audio/channel.h>
|
#include <audio/channel.h>
|
||||||
#include <audio/debug.h>
|
#include <audio/debug.h>
|
||||||
|
#include <etk/stdTools.h>
|
||||||
|
|
||||||
static const char* listValues[] = {
|
static const char* listValues[] = {
|
||||||
|
"unknow",
|
||||||
"front-left",
|
"front-left",
|
||||||
"front-center",
|
"front-center",
|
||||||
"front-right",
|
"front-right",
|
||||||
@ -67,35 +69,21 @@ std::ostream& audio::operator <<(std::ostream& _os, const std::vector<std::vecto
|
|||||||
return _os;
|
return _os;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::vector<std::string> split(const std::string& _input, char _val) {
|
enum audio::channel audio::getChannelFromString(const std::string& _value) {
|
||||||
std::vector<std::string> list;
|
for (int32_t iii=0; iii<listValuesSize; ++iii) {
|
||||||
size_t lastStartPos = 0;
|
if (_value == listValues[iii]) {
|
||||||
for(size_t iii=0; iii<_input.size(); iii++) {
|
return static_cast<enum audio::channel>(iii);
|
||||||
if (_input[iii]==_val) {
|
|
||||||
list.push_back(std::string(_input, lastStartPos, iii - lastStartPos));
|
|
||||||
lastStartPos = iii+1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lastStartPos<_input.size()) {
|
AUDIO_ERROR("Can not convert : '" << _value << "' ...");
|
||||||
list.push_back(std::string(_input, lastStartPos));
|
return audio::channel_unknow;
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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<enum audio::channel> out;
|
||||||
std::vector<std::string> listIO = split(_value, ';');
|
std::vector<std::string> list = etk::split(_value, ';');
|
||||||
for (size_t iii=0; iii<listIO.size(); ++iii) {
|
for (auto &it : list) {
|
||||||
int32_t tmpCount = out.size();
|
out.push_back(getChannelFromString(it));
|
||||||
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 << "' ...");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
namespace audio {
|
namespace audio {
|
||||||
enum channel {
|
enum channel {
|
||||||
|
channel_unknow, //!< Error channel ...
|
||||||
channel_frontLeft, //!< channel Front Left
|
channel_frontLeft, //!< channel Front Left
|
||||||
channel_frontCenter, //!< channel Front Center
|
channel_frontCenter, //!< channel Front Center
|
||||||
channel_frontRight, //!< channel Front Right
|
channel_frontRight, //!< channel Front Right
|
||||||
@ -25,7 +26,8 @@ namespace audio {
|
|||||||
};
|
};
|
||||||
std::string getChannelString(enum audio::channel _obj);
|
std::string getChannelString(enum audio::channel _obj);
|
||||||
std::string getChannelString(const std::vector<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, 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<enum audio::channel>& _obj);
|
||||||
std::ostream& operator <<(std::ostream& _os, const std::vector<std::vector<enum audio::channel>>& _obj);
|
std::ostream& operator <<(std::ostream& _os, const std::vector<std::vector<enum audio::channel>>& _obj);
|
||||||
|
@ -40,6 +40,7 @@ std::string audio::getFormatString(enum audio::format _value) {
|
|||||||
return listValues[_value];
|
return listValues[_value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum audio::format audio::getFormatFromString(const std::string& _value) {
|
enum audio::format audio::getFormatFromString(const std::string& _value) {
|
||||||
for (int32_t iii=0; iii<listValuesSize; ++iii) {
|
for (int32_t iii=0; iii<listValuesSize; ++iii) {
|
||||||
if (_value == listValues[iii]) {
|
if (_value == listValues[iii]) {
|
||||||
@ -47,4 +48,33 @@ enum audio::format audio::getFormatFromString(const std::string& _value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return format_unknow;
|
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;
|
||||||
}
|
}
|
@ -20,10 +20,12 @@ namespace audio {
|
|||||||
format_float, //!< Floating point (single precision)
|
format_float, //!< Floating point (single precision)
|
||||||
format_double //!< Floating point (double 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);
|
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, enum audio::format _obj);
|
||||||
std::ostream& operator <<(std::ostream& _os, const std::vector<enum audio::format>& _obj);
|
std::ostream& operator <<(std::ostream& _os, const std::vector<enum audio::format>& _obj);
|
||||||
|
uint32_t getFormatBytes(enum audio::format _format);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user