Created
June 28, 2015 04:58
-
-
Save bryancatanzaro/260c133f1b1d428be8e3 to your computer and use it in GitHub Desktop.
Log linear spacing
This file contains 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 <iostream> | |
#include <iterator> | |
#include <algorithm> | |
#include <vector> | |
#include <cmath> | |
std::vector<float> make_log_linear(size_t n, | |
int linear, | |
int subbin) { | |
std::vector<float> result; | |
float inc = std::ldexp(1.0f, linear - subbin); | |
float val = 0.0f; | |
size_t i = 0; | |
size_t subbins = 1 << subbin; | |
while(i < n) { | |
for(int j = 0; j < subbins; j++) { | |
result.push_back(val); | |
val += inc; | |
i++; | |
} | |
inc *= 2.0f; | |
} | |
return result; | |
} | |
int main() { | |
std::vector<float> result = make_log_linear(16, 4, 2); | |
std::ostream_iterator<float> os(std::cout, ", "); | |
std::copy(result.begin(), result.end(), os); | |
std::cout << std::endl; | |
} |
Author
bryancatanzaro
commented
Jun 28, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment