#include #include "SampleStream.h" #include "SampleBlock.h" using std::string; using std::min; SampleStream::SampleStream(string input_stream) { load(input_stream); // test direct sample editing: // std::transform(_stream.begin(), _stream.end(), _stream.begin(), [](int16_t s) { return s/2; }); } void SampleStream::load(string input) { _stream.clear(); for (size_t i = 0; i < input.size(); i += 2) _stream.push_back(((input[i] & 0xff) << 0) | ((input[i+1] & 0xff) << 8)); } string SampleStream::save() { string out; for (int16_t sample : _stream) { out.push_back((sample >> 0) & 0xff); out.push_back((sample >> 8) & 0xff); } return out; } vector SampleStream::split(size_t block_size) { vector out; size_t stream_size = _stream.size(); for (size_t i = 0; i < stream_size; i += block_size) { size_t begin_offset = i; size_t end_offset = min(i + block_size, stream_size); SampleBlock block(_stream.begin() + begin_offset, end_offset - begin_offset); out.push_back(block); } return out; }