bool Window::initializeInternal(const SignalBank &input) { LOUDNESS_ASSERT(input.getNSamples() == length_[0], name_ << ": Number of input samples does not equal the largest window size!"); //number of windows nWindows_ = (int)length_.size(); LOUDNESS_DEBUG(name_ << ": Number of windows = " << nWindows_); window_.resize(nWindows_); //Largest window should be the first largestWindowSize_ = length_[0]; LOUDNESS_DEBUG(name_ << ": Largest window size = " << largestWindowSize_); //first window (largest) does not require a shift windowOffset_.push_back(0); //check if we are using multi windows on one input channel int nOutputChannels = input.getNChannels(); if((input.getNChannels()==1) && (nWindows_>1)) { LOUDNESS_DEBUG(name_ << ": Using parallel windows"); parallelWindows_ = true; nOutputChannels = nWindows_; //if so, calculate the delay int alignmentSample = largestWindowSize_ / 2; LOUDNESS_DEBUG(name_ << ": Alignment sample = " << alignmentSample); for(int w=1; w<nWindows_; w++) { int thisCentreSample = length_[w] / 2; int thisWindowOffset = alignmentSample - thisCentreSample; windowOffset_.push_back(thisWindowOffset); LOUDNESS_DEBUG(name_ << ": Centre sample for window " << w << " = " << thisCentreSample); LOUDNESS_DEBUG(name_ << ": Offset for window " << w << " = " << thisWindowOffset); } } else { LOUDNESS_ASSERT(input.getNChannels() == nWindows_, "Multiple channels but incorrect window specification."); } //generate the normalised window functions for (int w=0; w<nWindows_; w++) { window_[w].assign(length_[w],0.0); generateWindow(window_[w], windowType_, periodic_); normaliseWindow(window_[w], normalisation_); LOUDNESS_DEBUG(name_ << ": Length of window " << w << " = " << window_[w].size()); } //initialise the output signal output_.initialize(input.getNEars(), nOutputChannels, largestWindowSize_, input.getFs()); output_.setFrameRate(input.getFrameRate()); return 1; }
void MonitorSpectralNode::initialize() { MonitorNode::initialize(); if( mFftSize < mWindowSize ) mFftSize = mWindowSize; if( ! isPowerOf2( mFftSize ) ) mFftSize = nextPowerOf2( static_cast<uint32_t>( mFftSize ) ); mFft = unique_ptr<dsp::Fft>( new dsp::Fft( mFftSize ) ); mFftBuffer = audio::Buffer( mFftSize ); mBufferSpectral = audio::BufferSpectral( mFftSize ); mMagSpectrum.resize( mFftSize / 2 ); mWindowingTable = makeAlignedArray<float>( mWindowSize ); generateWindow( mWindowType, mWindowingTable.get(), mWindowSize ); }
void ofxAudioUnitFftNode::setFftBufferSize(unsigned int bufferSize) { _log2N = (unsigned int) ceilf(log2f(bufferSize)); _N = 1 << _log2N; // if the new buffer size is bigger than what we've allocated for, // free everything and allocate anew (otherwise re-use) if(_log2N > _currentMaxLog2N) { freeBuffers(); _fftData.realp = (float *)calloc(_N / 2, sizeof(float)); _fftData.imagp = (float *)calloc(_N / 2, sizeof(float)); _window = (float *)calloc(_N, sizeof(float)); _fftSetup = vDSP_create_fftsetup(_log2N, kFFTRadix2); _currentMaxLog2N = _log2N; } generateWindow(_outputSettings.window, _window, _N); setBufferSize(_N); }
int main() { DEBUGLOG->setAutoPrint(true); ////////////////////////////////////////////////////////////////////////////// /////////////////////// INIT ////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // create window and opengl context auto window = generateWindow(800,800); ////////////////////////////////////////////////////////////////////////////// /////////////////////////////// RENDERING /////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// ///////////////////// Scene / View Settings ////////////////////////// glm::mat4 model = glm::mat4(1.0f); glm::vec4 eye(0.0f, 0.0f, 3.0f, 1.0f); glm::vec4 center(0.0f,0.0f,0.0f,1.0f); glm::mat4 view = glm::lookAt(glm::vec3(eye), glm::vec3(center), glm::vec3(0,1,0)); // glm::mat4 perspective = glm::ortho(-2.0f, 2.0f, -2.0f, 2.0f, -1.0f, 6.0f); /// perspective projection is experimental; yields weird warping effects due to vertex interpolation of uv-coordinates glm::mat4 perspective = glm::perspective(glm::radians(65.f), getRatio(window), 0.1f, 10.f); // create object // Sphere grid; Grid grid(10,10,0.1f,0.1f,true); // Volume grid; // load grass texture s_texHandle = TextureTools::loadTexture(RESOURCES_PATH + std::string( "/grass.png")); glBindTexture(GL_TEXTURE_2D, s_texHandle); /////////////////////// Renderpass /////////////////////////// DEBUGLOG->log("Shader Compilation: volume uvw coords"); DEBUGLOG->indent(); ShaderProgram shaderProgram("/modelSpace/GBuffer.vert", "/modelSpace/GBuffer.frag"); DEBUGLOG->outdent(); shaderProgram.update("model", model); shaderProgram.update("view", view); shaderProgram.update("projection", perspective); shaderProgram.update("color", glm::vec4(1.0f,0.0f,0.0f,1.0f)); DEBUGLOG->log("FrameBufferObject Creation: volume uvw coords"); DEBUGLOG->indent(); FrameBufferObject fbo(getResolution(window).x, getResolution(window).y); FrameBufferObject::s_internalFormat = GL_RGBA32F; // to allow arbitrary values in G-Buffer fbo.addColorAttachments(4); DEBUGLOG->outdent(); // G-Buffer FrameBufferObject::s_internalFormat = GL_RGBA; // restore default RenderPass renderPass(&shaderProgram, &fbo); renderPass.addEnable(GL_DEPTH_TEST); renderPass.addClearBit(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); renderPass.addRenderable(&grid); ShaderProgram compShader("/screenSpace/fullscreen.vert", "/screenSpace/finalCompositing.frag"); // ShaderProgram compShader("/screenSpace/fullscreen.vert", "/screenSpace/simpleAlphaTexture.frag"); Quad quad; RenderPass compositing(&compShader, 0); compositing.addClearBit(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); compositing.addRenderable(&quad); // Geometry test shader ShaderProgram geomShader("/modelSpace/geometry.vert", "/modelSpace/simpleLighting.frag", "/geometry/simpleGeom.geom"); RenderPass geom(&geomShader, 0); geom.addClearBit(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); geom.addRenderable(&grid); geom.addEnable(GL_DEPTH_TEST); geom.addEnable(GL_ALPHA_TEST); geom.addEnable(GL_BLEND); glAlphaFunc(GL_GREATER, 0); geomShader.update("projection", perspective); ////////////////////////////////////////////////////////////////////////////// /////////////////////// GUI / USER INPUT //////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // Setup ImGui binding ImGui_ImplGlfwGL3_Init(window, true); Turntable turntable; double old_x; double old_y; glfwGetCursorPos(window, &old_x, &old_y); auto cursorPosCB = [&](double x, double y) { ImGuiIO& io = ImGui::GetIO(); if ( io.WantCaptureMouse ) { return; } // ImGUI is handling this double d_x = x - old_x; double d_y = y - old_y; if ( turntable.getDragActive() ) { turntable.dragBy(d_x, d_y, view); } old_x = x; old_y = y; }; auto mouseButtonCB = [&](int b, int a, int m) { if (b == GLFW_MOUSE_BUTTON_LEFT && a == GLFW_PRESS) { turntable.setDragActive(true); } if (b == GLFW_MOUSE_BUTTON_LEFT && a == GLFW_RELEASE) { turntable.setDragActive(false); } ImGui_ImplGlfwGL3_MouseButtonCallback(window, b, a, m); }; auto keyboardCB = [&](int k, int s, int a, int m) { if (a == GLFW_RELEASE) {return;} switch (k) { case GLFW_KEY_W: eye += glm::inverse(view) * glm::vec4(0.0f,0.0f,-0.1f,0.0f); center += glm::inverse(view) * glm::vec4(0.0f,0.0f,-0.1f,0.0f); break; case GLFW_KEY_A: eye += glm::inverse(view) * glm::vec4(-0.1f,0.0f,0.0f,0.0f); center += glm::inverse(view) * glm::vec4(-0.1f,0.0f,0.0f,0.0f); break; case GLFW_KEY_S: eye += glm::inverse(view) * glm::vec4(0.0f,0.0f,0.1f,0.0f); center += glm::inverse(view) * glm::vec4(0.0f,0.0f,0.1f,0.0f); break; case GLFW_KEY_D: eye += glm::inverse(view) * glm::vec4(0.1f,0.0f,0.0f,0.0f); center += glm::inverse(view) * glm::vec4(0.1f,0.0f,0.0f,0.0f); break; default: break; } ImGui_ImplGlfwGL3_KeyCallback(window,k,s,a,m); }; setCursorPosCallback(window, cursorPosCB); setMouseButtonCallback(window, mouseButtonCB); setKeyCallback(window, keyboardCB); ////////////////////////////////////////////////////////////////////////////// //////////////////////////////// RENDER LOOP ///////////////////////////////// ////////////////////////////////////////////////////////////////////////////// double elapsedTime = 0.0; render(window, [&](double dt) { elapsedTime += dt; std::string window_header = "Volume Renderer - " + std::to_string( 1.0 / dt ) + " FPS"; glfwSetWindowTitle(window, window_header.c_str() ); //////////////////////////////// GUI //////////////////////////////// ImGuiIO& io = ImGui::GetIO(); ImGui_ImplGlfwGL3_NewFrame(); // tell ImGui a new frame is being rendered ImGui::PushItemWidth(-100); if (ImGui::CollapsingHeader("Geometry Shader Settings")) { ImGui::ColorEdit4( "color", glm::value_ptr( s_color)); // color mixed at max distance ImGui::SliderFloat("strength", &s_strength, 0.0f, 2.0f); // influence of color shift } ImGui::Checkbox("auto-rotate", &s_isRotating); // enable/disable rotating volume ImGui::PopItemWidth(); ////////////////////////////////////////////////////////////////////////////// ///////////////////////////// MATRIX UPDATING /////////////////////////////// if (s_isRotating) // update view matrix { model = glm::rotate(glm::mat4(1.0f), (float) dt, glm::vec3(0.0f, 1.0f, 0.0f) ) * model; } view = glm::lookAt(glm::vec3(eye), glm::vec3(center), glm::vec3(0.0f, 1.0f, 0.0f)); ////////////////////////////////////////////////////////////////////////////// //////////////////////// SHADER / UNIFORM UPDATING ////////////////////////// // update view related uniforms shaderProgram.update( "view", view); shaderProgram.update( "model", turntable.getRotationMatrix() * model); geomShader.update( "view", view); geomShader.update( "model", turntable.getRotationMatrix() * model); compShader.update( "vLightPos", view * turntable.getRotationMatrix() * s_lightPos); updateVectorTexture(elapsedTime); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, s_vectorTexture); // glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // this is altered by ImGui::Render(), so reset it every frame glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, s_texHandle); geomShader.update("tex", 1); geomShader.update("blendColor", 2.0); geomShader.update("color", s_color); geomShader.update("strength", s_strength); ////////////////////////////////////////////////////////////////////////////// //////////////////////////////// RENDERING //// ///////////////////////////// // glActiveTexture(GL_TEXTURE0); // glBindTexture(GL_TEXTURE_2D, fbo.getColorAttachmentTextureHandle(GL_COLOR_ATTACHMENT0)); // color // glActiveTexture(GL_TEXTURE1); // glBindTexture(GL_TEXTURE_2D, fbo.getColorAttachmeHntTextureHandle(GL_COLOR_ATTACHMENT1)); // normal // glActiveTexture(GL_TEXTURE2); // glBindTexture(GL_TEXTURE_2D, fbo.getColorAttachmentTextureHandle(GL_COLOR_ATTACHMENT2)); // position // glActiveTexture(GL_TEXTURE0); // compShader.update("colorMap", 0); // compShader.update("normalMap", 1); // compShader.update("positionMap", 2); // renderPass.render(); // compositing.render(); geom.render(); ImGui::Render(); glDisable(GL_BLEND); glBlendFunc(GL_ONE, GL_ZERO); // this is altered by ImGui::Render(), so reset it every frame ////////////////////////////////////////////////////////////////////////////// }); destroyWindow(window); return 0; }
void VisibilityExtractionDemo::init() { window = generateWindow(); // load a file std::vector<std::string> paths; //paths.push_back("/home/nlichtenberg/1crn.pdb"); paths.push_back("/home/nlichtenberg/1vis.pdb"); //paths.push_back("/home/nlichtenberg/Develop/Mol_Sandbox/resources/TrajectoryFiles/1aon.pdb"); MdTrajWrapper mdwrap; std::auto_ptr<Protein> prot = mdwrap.load(paths); impSph = new ImpostorSpheres(!useAtomicCounters, false); impSph->setProteinData(prot.get()); impSph->init(); num_balls = impSph->num_balls; if(perspectiveProj) projection = perspective(45.0f, getRatio(window), 0.1f, 100.0f); else projection = ortho(-30.0f, 30.0f, -30.0f, 30.0f, 0.0f, 100.0f); if (useAtomicCounters) { spRenderImpostor = ShaderProgram("/VisibleAtomsDetection/Impostor/impostorSpheres_InstancedUA.vert", "/VisibleAtomsDetection/Detection/solidColorInstanceCount.frag"); spRenderDiscs = ShaderProgram("/VisibleAtomsDetection//Impostor/impostorSpheres_InstancedUA.vert", "/VisibleAtomsDetection//Impostor/impostorSpheres_discardFragments_Instanced.frag"); if(perspectiveProj) spRenderBalls = ShaderProgram("/VisibleAtomsDetection/Base/modelViewProjectionInstancedUA.vert", "/VisibleAtomsDetection/Impostor/Impostor3DSphere.frag"); else spRenderBalls = ShaderProgram("/VisibleAtomsDetection/Base/modelViewProjectionInstancedUA.vert", "/VisibleAtomsDetection/Impostor/Impostor3DSphere_Ortho.frag"); } else { spRenderImpostor = ShaderProgram("/VisibleAtomsDetection/Impostor/impostorSpheres_Instanced.vert", "/VisibleAtomsDetection/Detection/solidColorInstanceCount.frag"); spRenderDiscs = ShaderProgram("/VisibleAtomsDetection/Impostor/impostorSpheres_Instanced.vert", "/VisibleAtomsDetection/Impostor/impostorSpheres_discardFragments_Instanced.frag"); spRenderBalls = ShaderProgram("/VisibleAtomsDetection/Impostor/impostorSpheres_Instanced.vert", "/VisibleAtomsDetection/Impostor/Impostor3DSphere.frag"); } /// Renderpass to render impostors/fake geometry renderBalls = new RenderPass( impSph, &spRenderBalls, getWidth(window), getHeight(window)); renderBalls->update("projection", projection); // define projection matrix for other shader programs renderBalls->setShaderProgram(&spRenderDiscs); renderBalls->update("projection", projection); renderBalls->setShaderProgram(&spRenderImpostor); renderBalls->update("projection", projection); /// Renderpass to detect the visible instances collectSurfaceIDs = new RenderPass( new Quad(), new ShaderProgram("/VisibleAtomsDetection/Base/fullscreen.vert", "/VisibleAtomsDetection/Detection/DetectVisibleInstanceIDs.frag"), getWidth(window), getHeight(window)); // prepare 1D buffer for entries tex_collectedIDsBuffer = new Texture(GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_INT); tex_collectedIDsBuffer->genUimageBuffer(num_balls); collectSurfaceIDs->texture("collectedIDsBuffer", tex_collectedIDsBuffer); collectSurfaceIDs->texture("tex", renderBalls->get("InstanceID")); /// renderpass to display result frame result = new RenderPass( new Quad(), new ShaderProgram("/VisibleAtomsDetection/Base/fullscreen.vert", "/VisibleAtomsDetection/Detection/toneMapperLinearInstanceCount.frag")); result->texture("tex", renderBalls->get("fragColor")); /// compute shader to process a list of visible IDs (with the actual instanceID of the first general draw) computeSortedIDs = new ComputeProgram(new ShaderProgram("/VisibleAtomsDetection/Detection/CreateVisibleIDList.comp")); // 1D buffer for visible IDs tex_sortedVisibleIDsBuffer = new Texture(GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT); tex_sortedVisibleIDsBuffer->genUimageBuffer(num_balls); computeSortedIDs->texture("collectedIDsBuffer", tex_collectedIDsBuffer); computeSortedIDs->texture("sortedVisibleIDsBuffer", tex_sortedVisibleIDsBuffer); // atomic counter buffer for consecutive index access in compute shader glGenBuffers(1, &atomBuff); glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomBuff); glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 3, atomBuff); glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(GLuint), NULL, GL_DYNAMIC_DRAW); glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0); positions_size = sizeof(glm::vec4) * impSph->instance_positions_s.instance_positions.size(); colors_size = sizeof(glm::vec4) * impSph->instance_colors_s.instance_colors.size(); // SSBO setup glGenBuffers(2, SSBO); glBindBuffer(GL_SHADER_STORAGE_BUFFER, SSBO[0]); glBufferData(GL_SHADER_STORAGE_BUFFER, positions_size, &impSph->instance_positions_s.instance_positions[0], GL_DYNAMIC_COPY); glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 0, SSBO[0], 0, positions_size); glBindBuffer(GL_SHADER_STORAGE_BUFFER, SSBO[1]); glBufferData(GL_SHADER_STORAGE_BUFFER, colors_size, &impSph->instance_colors_s.instance_colors[0], GL_DYNAMIC_COPY); glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 1, SSBO[1], 0, colors_size); glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); // SSBO copy data glBindBuffer(GL_SHADER_STORAGE_BUFFER, SSBO[0]); GLvoid* p_ = glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY); memcpy(p_, &impSph->instance_positions_s.instance_positions[0], positions_size); glUnmapBuffer(GL_SHADER_STORAGE_BUFFER); glBindBuffer(GL_SHADER_STORAGE_BUFFER, SSBO[1]); p_ = glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY); memcpy(p_, &impSph->instance_colors_s.instance_colors[0], colors_size); glUnmapBuffer(GL_SHADER_STORAGE_BUFFER); // SSBO bind to shaders glBindBuffer(GL_SHADER_STORAGE_BUFFER, SSBO[0]); GLuint block_index = 0; block_index = glGetProgramResourceIndex(spRenderBalls.getProgramHandle(), GL_SHADER_STORAGE_BLOCK, "instance_positions_t"); glShaderStorageBlockBinding(spRenderBalls.getProgramHandle(), block_index, 0); glBindBuffer(GL_SHADER_STORAGE_BUFFER, SSBO[1]); block_index = glGetProgramResourceIndex(spRenderBalls.getProgramHandle(), GL_SHADER_STORAGE_BLOCK, "instance_colors_t"); glShaderStorageBlockBinding(spRenderBalls.getProgramHandle(), block_index, 1); glBindBuffer(GL_SHADER_STORAGE_BUFFER, SSBO[0]); block_index = glGetProgramResourceIndex(spRenderDiscs.getProgramHandle(), GL_SHADER_STORAGE_BLOCK, "instance_positions_t"); glShaderStorageBlockBinding(spRenderBalls.getProgramHandle(), block_index, 0); glBindBuffer(GL_SHADER_STORAGE_BUFFER, SSBO[1]); block_index = glGetProgramResourceIndex(spRenderDiscs.getProgramHandle(), GL_SHADER_STORAGE_BLOCK, "instance_colors_t"); glShaderStorageBlockBinding(spRenderBalls.getProgramHandle(), block_index, 1); glBindBuffer(GL_SHADER_STORAGE_BUFFER, SSBO[0]); block_index = glGetProgramResourceIndex(spRenderImpostor.getProgramHandle(), GL_SHADER_STORAGE_BLOCK, "instance_positions_t"); glShaderStorageBlockBinding(spRenderBalls.getProgramHandle(), block_index, 0); glBindBuffer(GL_SHADER_STORAGE_BUFFER, SSBO[1]); block_index = glGetProgramResourceIndex(spRenderImpostor.getProgramHandle(), GL_SHADER_STORAGE_BLOCK, "instance_colors_t"); glShaderStorageBlockBinding(spRenderBalls.getProgramHandle(), block_index, 1); // prepare data to reset the buffer that holds the visible instance IDs int byteCount = sizeof(unsigned int)* num_balls; zeros = new unsigned char[byteCount]; unsigned int f = 0; unsigned char const * p = reinterpret_cast<unsigned char const *>(&f); for (int i = 0; i < byteCount; i+=4) { zeros[i] = p[0]; zeros[i+1] = p[1]; zeros[i+2] = p[2]; zeros[i+3] = p[3]; } // prepare buffer with index = value // used to draw all istances identityInstancesMap.clear(); for (GLuint i = 0; i < num_balls; i++) identityInstancesMap.push_back(i); glBindTexture(GL_TEXTURE_1D, tex_sortedVisibleIDsBuffer->getHandle()); glTexImage1D(GL_TEXTURE_1D, 0, GL_R32UI, num_balls, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, &identityInstancesMap[0]); // map to set all instances visible mapAllVisible.resize(num_balls); std::fill(mapAllVisible.begin(), mapAllVisible.end(), 1); // time query GLuint timeQuery; glGenQueries(1, &timeQuery); glEnable(GL_DEPTH_TEST); }
void ofxAudioUnitFftNode::setWindowType(ofxAudioUnitWindowType windowType) { _outputSettings.window = windowType; generateWindow(_outputSettings.window, _window, _N); }
void ofxAudioUnitFftNode::setSettings(const ofxAudioUnitFftNode::Settings &settings) { _outputSettings = settings; generateWindow(_outputSettings.window, _window, _N); }