9#include <boost/date_time.hpp>
10#include <boost/endian/conversion.hpp>
11#include <boost/uuid/uuid.hpp>
12#include <boost/uuid/uuid_generators.hpp>
13#include <boost/uuid/uuid_io.hpp>
16#include "boost/date_time/c_local_time_adjustor.hpp"
27 boost::uuids::uuid uuid = boost::uuids::random_generator()();
28 std::string uuidStr = boost::uuids::to_string(uuid);
41 boost::date_time::c_local_adjustor<boost::posix_time::ptime>;
42 boost::posix_time::time_facet* f =
new boost::posix_time::time_facet();
43 f->time_duration_format(
"%+%H:%M");
46 auto now = boost::posix_time::microsec_clock::universal_time();
47 auto utc_now = local_adj::utc_to_local(now);
48 boost::posix_time::time_duration td = utc_now - now;
51 std::ostringstream oss_offset;
52 oss_offset.imbue(std::locale(oss_offset.getloc(), f));
55 std::string currentTime = to_iso_extended_string(utc_now);
56 currentTime += oss_offset.str();
65inline std::shared_ptr<BaseIO>
createIO(
const std::string& type,
66 const std::string& filename)
69 return std::make_shared<HDF5::HDF5IO>(filename);
71 throw std::invalid_argument(
"Invalid IO type");
90 auto maxVal =
static_cast<double>(0x7fff);
91 auto intData =
static_cast<char*
>(dest);
93 for (
int i = 0; i < numSamples; ++i) {
94 auto clampedValue = std::clamp(maxVal * source[i], -maxVal, maxVal);
96 static_cast<uint16_t
>(
static_cast<int16_t
>(std::round(clampedValue)));
97 intValue = boost::endian::native_to_little(intValue);
98 *
reinterpret_cast<uint16_t*
>(intData) = intValue;
110 float conversion_factor,
113 std::unique_ptr<float[]> scaledData = std::make_unique<float[]>(numSamples);
114 std::unique_ptr<int16_t[]> intData = std::make_unique<int16_t[]>(numSamples);
117 double multFactor = 1 / (32767.0f * conversion_factor);
121 [multFactor](
float value) { return value * multFactor; });
AQNWB::Types::SizeType SizeType
Definition BaseIO.hpp:16
The main namespace for AqNWB.
std::unique_ptr< int16_t[]> transformToInt16(SizeType numSamples, float conversion_factor, const float *data)
Method to scale float values and convert to int16 values.
Definition Utils.hpp:109
std::shared_ptr< BaseIO > createIO(const std::string &type, const std::string &filename)
Factory method to create an IO object.
Definition Utils.hpp:65
std::string generateUuid()
Generates a UUID (Universally Unique Identifier) as a string.
Definition Utils.hpp:25
void convertFloatToInt16LE(const float *source, void *dest, int numSamples)
Method to convert float values to uint16 values. This method was adapted from JUCE AudioDataConverter...
Definition Utils.hpp:83
std::string getCurrentTime()
Get the current time in ISO 8601 format with the UTC offset.
Definition Utils.hpp:37