53 lines
1.4 KiB
C++
53 lines
1.4 KiB
C++
#include "Shaders/ShaderProgram.h"
|
|
#include "Audio/AudioPlayer.h"
|
|
#include "GLObjects/SpectralMesh.h"
|
|
#include "OGL.h"
|
|
#include "Camera.h"
|
|
|
|
#include <iostream>
|
|
|
|
int main(int argc, char** argv) {
|
|
try {
|
|
if(argc != 2) {
|
|
std::cout << "invalid arguments" << std::endl;
|
|
return 0;
|
|
}
|
|
std::string musicFile = argv[1];
|
|
|
|
OGL::instance()->init();
|
|
|
|
ShaderProgram program("../shaders/vertex.glsl", "../shaders/fragment.glsl");
|
|
OGL::instance()->setCurShaderProgram(&program);
|
|
|
|
SpectralMesh mesh(&program, 512);
|
|
mesh.create();
|
|
OGL::instance()->addObject(&mesh);
|
|
|
|
Camera::instance()->init();
|
|
|
|
AudioPlayer player(musicFile);
|
|
float* line = new float[2048];
|
|
memset(line, 0, 2048);
|
|
player.setStreamListener([&mesh, line](float *data, std::size_t framesCount, std::size_t depth, std::size_t channels) {
|
|
memmove(line, line + 1024, 1024);
|
|
if(channels > 1) { // if we have more than one channel, use the first
|
|
for(std::size_t i = 0, j = 0; i < framesCount; i += channels, ++j) {
|
|
line[1024 + j] = data[i];
|
|
}
|
|
} else {
|
|
memcpy(line + 1024, data, 1024);
|
|
}
|
|
|
|
mesh.addLine(line, depth);
|
|
mesh.addLine(line + 256, depth);
|
|
mesh.addLine(line + 512, depth);
|
|
mesh.addLine(line + 768, depth);
|
|
});
|
|
player.play();
|
|
|
|
OGL::instance()->run();
|
|
delete[] line;
|
|
} catch (std::exception& ex) {
|
|
std::cout << "exception: " << ex.what() << std::endl;
|
|
}
|
|
} |