[DEV] change basic parsing

This commit is contained in:
Edouard DUPIN 2015-02-04 21:42:14 +01:00
parent 3eb8544eaa
commit 69bfa46ec6
3 changed files with 44 additions and 82 deletions

View File

@ -7,6 +7,20 @@
#include <audio/channel.h>
#include <audio/debug.h>
static const char* listValues[] = {
"front-left",
"front-center",
"front-right",
"rear-left",
"rear-center",
"rear-right",
"surround-left",
"surround-right",
"sub-woofer",
"lfe"
};
static int32_t listValuesSize = sizeof(listValues)/sizeof(char*);
std::ostream& audio::operator <<(std::ostream& _os, enum audio::channel _obj) {
_os << getChannelString(_obj);
@ -14,38 +28,7 @@ std::ostream& audio::operator <<(std::ostream& _os, enum audio::channel _obj) {
}
std::string audio::getChannelString(enum audio::channel _value) {
switch (_value) {
case channel_frontLeft:
return "front-left";
break;
case channel_frontCenter:
return "front-center";
break;
case channel_frontRight:
return "front-right";
break;
case channel_rearLeft:
return "rear-left";
break;
case channel_rearCenter:
return "rear-center";
break;
case channel_rearRight:
return "rear-right";
break;
case channel_surroundLeft:
return "surround-left";
break;
case channel_surroundRight:
return "surround-right";
break;
case channel_subWoofer:
return "sub-woofer";
break;
case channel_lfe:
return "lfe";
break;
};
return listValues[_value];
}
std::string audio::getChannelString(const std::vector<enum audio::channel>& _value) {
@ -103,28 +86,15 @@ std::vector<enum audio::channel> audio::getChannelFromString(const std::string&
std::vector<enum audio::channel> out;
std::vector<std::string> listIO = split(_value, ';');
for (size_t iii=0; iii<listIO.size(); ++iii) {
if (listIO[iii] == "front-left") {
out.push_back(channel_frontLeft);
} else if (listIO[iii] == "front-right") {
out.push_back(channel_frontRight);
} else if (listIO[iii] == "front-center") {
out.push_back(channel_frontCenter);
} else if (listIO[iii] == "rear-left") {
out.push_back(channel_rearLeft);
} else if (listIO[iii] == "rear-right") {
out.push_back(channel_rearRight);
} else if (listIO[iii] == "rear-center") {
out.push_back(channel_rearCenter);
} else if (listIO[iii] == "surround-right") {
out.push_back(channel_surroundLeft);
} else if (listIO[iii] == "surround-left") {
out.push_back(channel_surroundRight);
} else if (listIO[iii] == "lfe") {
out.push_back(channel_lfe);
} else if (listIO[iii] == "sub-woofer") {
out.push_back(channel_subWoofer);
} else {
//ROS_ERROR("Unknow: '%s' in [front-left;front-right;front-center;rear-left;rear-right;rear-center;surround-right;surround-left;lfe;subwoofer]", listIO[iii].c_str());
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 << "' ...");
}
}
return out;

View File

@ -7,6 +7,18 @@
#include <audio/debug.h>
#include <audio/format.h>
static const char* listValues[] = {
"unknow",
"int8",
"int16",
"int16_on_int32",
"int24",
"int32",
"float",
"double"
};
static int32_t listValuesSize = sizeof(listValues)/sizeof(char*);
std::ostream& audio::operator <<(std::ostream& _os, enum audio::format _obj) {
_os << getFormatString(_obj);
return _os;
@ -25,37 +37,14 @@ std::ostream& audio::operator <<(std::ostream& _os, const std::vector<enum audio
}
std::string audio::getFormatString(enum audio::format _value) {
switch (_value) {
case format_unknow:
return "format_unknow";
break;
case format_int16:
return "format_int16";
break;
case format_int16_on_int32:
return "format_int16_on_int32";
break;
case format_int32:
return "format_int32";
break;
case format_float:
return "format_float";
break;
};
return listValues[_value];
}
enum audio::format audio::getFormatFromString(const std::string& _value) {
if (_value == "format_int16") {
return format_int16;
}
if (_value == "format_int16_on_int32") {
return format_int16_on_int32;
}
if (_value == "format_int32") {
return format_int32;
}
if (_value == "format_float") {
return format_float;
for (int32_t iii=0; iii<listValuesSize; ++iii) {
if (_value == listValues[iii]) {
return static_cast<enum audio::format>(iii);
}
}
return format_unknow;
}

View File

@ -12,10 +12,13 @@
namespace audio {
enum format {
format_unknow,
format_int8, //!< Signed 8 bits
format_int16, //!< Signed 16 bits
format_int16_on_int32, //!< Signed 16 bits on 32bits data (16 bit fixpoint value)
format_int24, //!< Signed 24 bits
format_int32, //!< Signed 32 bits
format_float, //!< Floating point (single precision)
format_double //!< Floating point (double precision)
};
std::string getFormatString(enum audio::format);
enum audio::format getFormatFromString(const std::string& _value);