Skip to content

Instantly share code, notes, and snippets.

@bryancatanzaro
Created June 28, 2015 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryancatanzaro/260c133f1b1d428be8e3 to your computer and use it in GitHub Desktop.
Save bryancatanzaro/260c133f1b1d428be8e3 to your computer and use it in GitHub Desktop.
Log linear spacing
#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;
}
@bryancatanzaro
Copy link
Author

$ g++ log_linear.cpp
$ ./a.out
$ 0, 4, 8, 12, 16, 24, 32, 40, 48, 64, 80, 96, 112, 144, 176, 208,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment