Port of Spectral from java.
This code compiles with -std=c++11, but probably doesn't work properly.