Last active
March 13, 2022 13:28
-
-
Save mralfarrakhan/ac033e41bf80eaec7c52a4748ee62c40 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <fmt/core.h> | |
| #include <vector> | |
| using stream_t = std::vector<double>; | |
| using split_t = std::vector<stream_t>; | |
| auto deinterleave(stream_t framesstream, int nchannel){ | |
| auto nframe = framesstream.size(); | |
| split_t res(nchannel); | |
| for(auto& c : res){ | |
| c.reserve(nframe/nchannel); | |
| } | |
| for(size_t i = 0; i < nframe; i++){ | |
| res[i%nchannel].push_back(framesstream[i]); | |
| } | |
| return res; | |
| } | |
| auto interleave(split_t splitstream, int nchannel){ | |
| size_t nframe = 0; | |
| for(const auto& c : splitstream){ | |
| for(const auto& s: c){ | |
| nframe++; | |
| } | |
| } | |
| stream_t res(nframe); | |
| for(size_t i = 0, j = 0; i < nframe; j++){ | |
| for(size_t k = 0; k < nchannel && i < nframe; k++, i++){ | |
| res[i] = splitstream[k][j]; | |
| } | |
| } | |
| return res; | |
| } | |
| int main(){ | |
| stream_t m(64); | |
| double i = 0.0; | |
| for(auto& s : m){ | |
| s = (i += 1.0); | |
| } | |
| int cn = 4; | |
| auto x = deinterleave(m, cn); | |
| for(const auto& c : x){ | |
| fmt::print("[{} in {}] ", c.size(), c.capacity()); | |
| for(const auto& s : c){ | |
| fmt::print("{} ", s); | |
| } | |
| fmt::print("\n"); | |
| } | |
| stream_t n = interleave(x, cn); | |
| fmt::print("[{} in {}] ", n.size(), n.capacity()); | |
| for(const auto& s : n){ | |
| fmt::print("{} ", s); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment