[DEV] Add ros channel compatibility
This commit is contained in:
parent
b4a452d025
commit
a19377860c
@ -103,3 +103,19 @@ namespace etk {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<uint8_t> audio::convertChannel(const std::vector<enum audio::channel>& _obj) {
|
||||
std::vector<uint8_t> out;
|
||||
for (size_t iii=0; iii<_obj.size(); ++iii) {
|
||||
out.push_back(static_cast<uint8_t>(_obj[iii]));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<enum audio::channel> audio::convertChannel(const std::vector<uint8_t>& _obj) {
|
||||
std::vector<enum audio::channel> out;
|
||||
for (size_t iii=0; iii<_obj.size(); ++iii) {
|
||||
out.push_back(static_cast<enum audio::channel>(_obj[iii]));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -9,21 +9,42 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace audio {
|
||||
enum channel {
|
||||
channel_unknow, //!< Error channel ...
|
||||
channel_frontLeft, //!< channel Front Left
|
||||
channel_frontCenter, //!< channel Front Center
|
||||
channel_frontRight, //!< channel Front Right
|
||||
channel_rearLeft, //!< channel rear Left
|
||||
channel_rearCenter, //!< channel rear Center
|
||||
channel_rearRight, //!< channel rear Right
|
||||
channel_surroundLeft, //!< channel surround Left
|
||||
channel_surroundRight, //!< channel surround Right
|
||||
channel_subWoofer, //!< channel Sub-woofer
|
||||
channel_lfe, //!< channel Low frequency
|
||||
#ifdef ETK_EXTERN_FRAMEWORK_ROS
|
||||
#include <ros/ros.h>
|
||||
#include "audio_msg/AudioBuffer.h"
|
||||
namespace audio {
|
||||
enum channel {
|
||||
channel_unknow = audio_msg::AudioBuffer::CHANNEL_UNKNOW,
|
||||
channel_frontLeft = audio_msg::AudioBuffer::CHANNEL_FRONT_LEFT,
|
||||
channel_frontCenter = audio_msg::AudioBuffer::CHANNEL_FRONT_CENTER,
|
||||
channel_frontRight = audio_msg::AudioBuffer::CHANNEL_FRONT_RIGHT,
|
||||
channel_rearLeft = audio_msg::AudioBuffer::CHANNEL_REAR_LEFT,
|
||||
channel_rearCenter = audio_msg::AudioBuffer::CHANNEL_REAR_CENTER,
|
||||
channel_rearRight = audio_msg::AudioBuffer::CHANNEL_REAR_RIGHT,
|
||||
channel_surroundLeft = audio_msg::AudioBuffer::CHANNEL_SURROUND_LEFT,
|
||||
channel_surroundRight = audio_msg::AudioBuffer::CHANNEL_SURROUND_RIGHT,
|
||||
channel_subWoofer = audio_msg::AudioBuffer::CHANNEL_SUBWOOFER,
|
||||
channel_lfe = audio_msg::AudioBuffer::CHANNEL_LFE
|
||||
};
|
||||
};
|
||||
#else
|
||||
namespace audio {
|
||||
enum channel {
|
||||
channel_unknow, //!< Error channel ...
|
||||
channel_frontLeft, //!< channel Front Left
|
||||
channel_frontCenter, //!< channel Front Center
|
||||
channel_frontRight, //!< channel Front Right
|
||||
channel_rearLeft, //!< channel rear Left
|
||||
channel_rearCenter, //!< channel rear Center
|
||||
channel_rearRight, //!< channel rear Right
|
||||
channel_surroundLeft, //!< channel surround Left
|
||||
channel_surroundRight, //!< channel surround Right
|
||||
channel_subWoofer, //!< channel Sub-woofer
|
||||
channel_lfe, //!< channel Low frequency
|
||||
};
|
||||
};
|
||||
#endif
|
||||
namespace audio {
|
||||
std::string getChannelString(enum audio::channel _obj);
|
||||
std::string getChannelString(const std::vector<enum audio::channel>& _obj);
|
||||
enum audio::channel getChannelFromString(const std::string& _value);
|
||||
@ -31,6 +52,9 @@ namespace audio {
|
||||
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);
|
||||
// For ROS Interface:
|
||||
std::vector<uint8_t> convertChannel(const std::vector<enum audio::channel>& _obj);
|
||||
std::vector<enum audio::channel> convertChannel(const std::vector<uint8_t>& _obj);
|
||||
};
|
||||
|
||||
|
||||
|
@ -63,20 +63,23 @@ std::vector<enum audio::format> audio::getListFormatFromString(const std::string
|
||||
}
|
||||
|
||||
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);
|
||||
switch(_format) {
|
||||
case audio::format_int8:
|
||||
return sizeof(int8_t);
|
||||
case audio::format_int8_on_int16:
|
||||
case audio::format_int16:
|
||||
return sizeof(int16_t);
|
||||
case audio::format_int16_on_int32:
|
||||
case audio::format_int24:
|
||||
case audio::format_int32:
|
||||
return sizeof(int32_t);
|
||||
case audio::format_int32_on_int64:
|
||||
case audio::format_int64:
|
||||
return sizeof(int64_t);
|
||||
case audio::format_float:
|
||||
return sizeof(float);
|
||||
case audio::format_double:
|
||||
return sizeof(double);
|
||||
}
|
||||
AUDIO_ERROR("undefined format : " << _format);
|
||||
return 0;
|
||||
@ -97,4 +100,28 @@ namespace etk {
|
||||
_variableRet = audio::format_unknow;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<uint8_t> audio::convertFormat(const std::vector<enum audio::format>& _obj) {
|
||||
std::vector<uint8_t> out;
|
||||
for (size_t iii=0; iii<_obj.size(); ++iii) {
|
||||
out.push_back(static_cast<uint8_t>(_obj[iii]));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<enum audio::format> audio::convertFormat(const std::vector<uint8_t>& _obj) {
|
||||
std::vector<enum audio::format> out;
|
||||
for (size_t iii=0; iii<_obj.size(); ++iii) {
|
||||
out.push_back(static_cast<enum audio::format>(_obj[iii]));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
uint8_t audio::convertFormat(enum audio::format _obj) {
|
||||
return static_cast<uint8_t>(_obj);
|
||||
}
|
||||
|
||||
enum audio::format audio::convertFormat(uint8_t _obj) {
|
||||
return static_cast<enum audio::format>(_obj);
|
||||
}
|
||||
|
@ -9,26 +9,54 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace audio {
|
||||
enum format {
|
||||
format_unknow,
|
||||
format_int8, //!< Signed 8 bits
|
||||
format_int8_on_int16, //!< Signed 8 bits on 16 bits data (8 bit fixpoint value)
|
||||
format_int16, //!< Signed 16 bits
|
||||
format_int16_on_int32, //!< Signed 16 bits on 32 bits data (16 bit fixpoint value)
|
||||
format_int24, //!< Signed 24 bits on 32 bits (lower)
|
||||
format_int32, //!< Signed 32 bits
|
||||
format_int32_on_int64, //!< Signed 32 bits on 64 bits data (32 bit fixpoint value)
|
||||
format_int64, //!< Signed 64 bits
|
||||
format_float, //!< Floating point 32 bits (single precision)
|
||||
format_double //!< Floating point 64 bits (double precision)
|
||||
#ifdef ETK_EXTERN_FRAMEWORK_ROS
|
||||
#include <ros/ros.h>
|
||||
#include "audio_msg/AudioBuffer.h"
|
||||
namespace audio {
|
||||
enum format {
|
||||
format_unknow = audio_msg::AudioBuffer::FORMAT_UNKNOW,
|
||||
format_int8 = audio_msg::AudioBuffer::FORMAT_INT8,
|
||||
format_int8_on_int16 = audio_msg::AudioBuffer::FORMAT_INT8_ON_INT16,
|
||||
format_int16 = audio_msg::AudioBuffer::FORMAT_INT16,
|
||||
format_int16_on_int32 = audio_msg::AudioBuffer::FORMAT_INT16_ON_INT32,
|
||||
format_int24 = audio_msg::AudioBuffer::FORMAT_INT24,
|
||||
format_int32 = audio_msg::AudioBuffer::FORMAT_INT32,
|
||||
format_int32_on_int64 = audio_msg::AudioBuffer::FORMAT_INT32_ON_INT64,
|
||||
format_int64 = audio_msg::AudioBuffer::FORMAT_INT64,
|
||||
format_float = audio_msg::AudioBuffer::FORMAT_FLOAT,
|
||||
format_double = audio_msg::AudioBuffer::FORMAT_DOUBLE
|
||||
};
|
||||
};
|
||||
#else
|
||||
namespace audio {
|
||||
enum format {
|
||||
format_unknow,
|
||||
format_int8, //!< Signed 8 bits
|
||||
format_int8_on_int16, //!< Signed 8 bits on 16 bits data (8 bit fixpoint value)
|
||||
format_int16, //!< Signed 16 bits
|
||||
format_int16_on_int32, //!< Signed 16 bits on 32 bits data (16 bit fixpoint value)
|
||||
format_int24, //!< Signed 24 bits on 32 bits (lower)
|
||||
format_int32, //!< Signed 32 bits
|
||||
format_int32_on_int64, //!< Signed 32 bits on 64 bits data (32 bit fixpoint value)
|
||||
format_int64, //!< Signed 64 bits
|
||||
format_float, //!< Floating point 32 bits (single precision)
|
||||
format_double //!< Floating point 64 bits (double precision)
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace audio {
|
||||
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);
|
||||
// For ROS Interface:
|
||||
std::vector<uint8_t> convertFormat(const std::vector<enum audio::format>& _obj);
|
||||
std::vector<enum audio::format> convertFormat(const std::vector<uint8_t>& _obj);
|
||||
uint8_t convertFormat(enum audio::format _obj);
|
||||
enum audio::format convertFormat(uint8_t _obj);
|
||||
};
|
||||
|
||||
|
||||
|
@ -8,6 +8,7 @@ set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
## is used, also find other catkin packages
|
||||
find_package(catkin REQUIRED COMPONENTS
|
||||
etk
|
||||
audio_msg
|
||||
)
|
||||
|
||||
|
||||
@ -45,7 +46,7 @@ add_library(${PROJECT_NAME}
|
||||
../${PROJECT_NAME}/format.cpp
|
||||
)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-std=c++11 -DDEBUG_LEVEL=3 -DDEBUG=1 -D__CPP_VERSION__=2011")
|
||||
set(CMAKE_CXX_FLAGS "-std=c++11 -DDEBUG_LEVEL=3 -DDEBUG=1 -D__CPP_VERSION__=2011 -DETK_EXTERN_FRAMEWORK_ROS")
|
||||
|
||||
|
||||
## Add cmake target dependencies of the executable/library
|
||||
|
@ -6,6 +6,8 @@
|
||||
<maintainer email="yui.heero@gmail.com">Edouard DUPIN</maintainer>
|
||||
<license>Apache-2.0</license>
|
||||
<build_depend>etk</build_depend>
|
||||
<build_depend>audio_msg</build_depend>
|
||||
<buildtool_depend>catkin</buildtool_depend>
|
||||
<run_depend>etk</run_depend>
|
||||
<run_depend>audio_msg</run_depend>
|
||||
</package>
|
||||
|
Loading…
x
Reference in New Issue
Block a user