diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bee758..e90ebc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,13 +4,11 @@ project(glTest) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -DGLEW_STATIC -O0 -g") set(CMAKE_BUILD_TYPE DEBUG) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") if(APPLE) - find_library(COCOA_FRAMEWORK Cocoa) find_library(OPENGL_FRAMEWORK OpenGL) - find_library(IOKIT_FRAMEWORK IOKit) - find_library(COREVIDEO_FRAMEWORK CoreVideo) - set(REQUIRED_LIBRARIES ${COCOA_FRAMEWORK} ${OPENGL_FRAMEWORK} ${IOKIT_FRAMEWORK} ${COREVIDEO_FRAMEWORK}) + set(OPENGL_LIBRARIES ${OPENGL_FRAMEWORK}) else() find_package(OpenGL REQUIRED) find_library(x11 NAMES X11) @@ -20,113 +18,29 @@ else() find_library(pthread NAMES pthread) find_library(Xinerama NAMES Xinerama) find_library(Xcursor NAMES Xcursor) - set(REQUIRED_LIBRARIES rt asound ${OPENGL_LIBRARIES} ${x11} ${xrandr} ${xi} ${xxf86vm} ${Xinerama} ${Xcursor} ${pthread}) + set(OPENGL_LIBRARIES rt asound ${OPENGL_LIBRARIES} ${x11} ${xrandr} ${xi} ${xxf86vm} ${Xinerama} ${Xcursor} ${pthread}) endif() -INCLUDE(ExternalProject) -SET_DIRECTORY_PROPERTIES(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/ThirdParty) +find_package(PkgConfig REQUIRED) +pkg_search_module(GLFW REQUIRED glfw3) +include_directories(${GLFW_INCLUDE_DIRS}) +link_directories(${GLFW_LIBRARY_DIRS}) -ExternalProject_Add( - glfw - URL http://netcologne.dl.sourceforge.net/project/glfw/glfw/3.1.1/glfw-3.1.1.zip - TIMEOUT 100 - CMAKE_ARGS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=${CMAKE_SOURCE_DIR}/lib - -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=${CMAKE_SOURCE_DIR}/lib - -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - INSTALL_COMMAND "" - LOG_DOWNLOAD ON - LOG_CONFIGURE ON - LOG_BUILD ON) +find_package(GLEW REQUIRED) +include_directories(${GLEW_INCLUDE_DIRS}) -ExternalProject_Get_Property(glfw source_dir) -ExternalProject_Get_Property(glfw binary_dir) -include_directories(${source_dir}/include) +find_package(GLM REQUIRED) +include_directories(${GLM_INCLUDE_DIRS}) -ExternalProject_Add( - glew - URL http://vorboss.dl.sourceforge.net/project/glew/glew/1.12.0/glew-1.12.0.zip - CONFIGURE_COMMAND "" - BUILD_COMMAND "make" - BUILD_IN_SOURCE 1 - INSTALL_COMMAND cp ${CMAKE_BINARY_DIR}/ThirdParty/src/glew/lib/libGLEW.a ${CMAKE_SOURCE_DIR}/lib - LOG_DOWNLOAD ON - LOG_CONFIGURE ON - LOG_BUILD ON -) +find_package(Portaudio REQUIRED) +include_directories(${PORTAUDIO_INCLUDE_DIRS}) -ExternalProject_Get_Property(glew source_dir) -ExternalProject_Get_Property(glew binary_dir) -include_directories(${source_dir}/include) -set(GLEW_SRC_DIR ${source_dir}) +pkg_search_module(SNDFILE REQUIRED sndfile) +include_directories(${SNDFILE_INCLUDE_DIRS}) -ExternalProject_Add( - glm - URL http://vorboss.dl.sourceforge.net/project/ogl-math/glm-0.9.6.3/glm-0.9.6.3.zip - TIMEOUT 100 - CMAKE_ARGS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=${CMAKE_SOURCE_DIR}/lib - -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=${CMAKE_SOURCE_DIR}/lib - -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - INSTALL_COMMAND "" - LOG_DOWNLOAD ON - LOG_CONFIGURE ON - LOG_BUILD ON) +pkg_search_module(FFTW3F REQUIRED fftw3f) +include_directories(${FFTW3F_INCLUDE_DIRS}) -ExternalProject_Get_Property(glm source_dir) -ExternalProject_Get_Property(glm binary_dir) -include_directories(${source_dir}) - -ExternalProject_Add( - portaudio - URL http://www.portaudio.com/archives/pa_stable_v19_20140130.tgz - TIMEOUT 100 - CONFIGURE_COMMAND ${CMAKE_BINARY_DIR}/ThirdParty/src/portaudio/configure --enable-cxx - BUILD_COMMAND "/usr/bin/make" - BUILD_IN_SOURCE 1 - INSTALL_COMMAND cp ${CMAKE_BINARY_DIR}/ThirdParty/src/portaudio/lib/.libs/libportaudio.a ${CMAKE_SOURCE_DIR}/lib - LOG_DOWNLOAD ON - LOG_CONFIGURE ON - LOG_BUILD ON) - -ExternalProject_Get_Property(portaudio source_dir) -ExternalProject_Get_Property(portaudio binary_dir) -include_directories(${source_dir}/include) - -ExternalProject_Add( - libsndfile - URL "http://www.mega-nerd.com/libsndfile/files/libsndfile-1.0.25.tar.gz" - CONFIGURE_COMMAND ${CMAKE_BINARY_DIR}/ThirdParty/src/libsndfile/configure --disable-external-libs - BUILD_COMMAND "/usr/bin/make" - UPDATE_COMMAND "" - INSTALL_COMMAND cp ${CMAKE_BINARY_DIR}/ThirdParty/src/libsndfile/src/.libs/libsndfile.a ${CMAKE_SOURCE_DIR}/lib - BUILD_IN_SOURCE 1 - LOG_DOWNLOAD ON - LOG_CONFIGURE ON - LOG_BUILD ON -) - -ExternalProject_Get_Property(libsndfile source_dir) -ExternalProject_Get_Property(libsndfile binary_dir) -#include_directories(${source_dir}/include) - -ExternalProject_Add( - fftw - URL "http://www.fftw.org/fftw-3.3.4.tar.gz" - CONFIGURE_COMMAND ${CMAKE_BINARY_DIR}/ThirdParty/src/fftw/configure --enable-float - BUILD_COMMAND "/usr/bin/make" - UPDATE_COMMAND "" - INSTALL_COMMAND cp ${CMAKE_BINARY_DIR}/ThirdParty/src/fftw/.libs/libfftw3f.a ${CMAKE_SOURCE_DIR}/lib - BUILD_IN_SOURCE 1 - LOG_DOWNLOAD ON - LOG_CONFIGURE ON - LOG_BUILD ON -) -ExternalProject_Get_Property(fftw source_dir) -include_directories(${source_dir}/api) - -set(SOURCE_FILES src/main.cpp) -add_executable(glTest ${SOURCE_FILES} src/ShaderProgram.cpp src/ShaderProgram.h src/Mesh.cpp src/Mesh.h src/vertex.h src/IGLObject.h src/GLObject.cpp src/GLObject.h src/WaveMesh.cpp src/WaveMesh.h src/AudioPlayer.cpp src/AudioPlayer.h src/ISndSource.h src/WavSource.cpp src/WavSource.h src/SpectralMesh.cpp src/SpectralMesh.h) -add_dependencies(glTest glfw glew glm portaudio libsndfile fftw) -target_link_libraries(glTest ${GLFW_LIBRARIES} ${REQUIRED_LIBRARIES} ${CMAKE_SOURCE_DIR}/lib/libglfw3.a ${CMAKE_SOURCE_DIR}/lib/libGLEW.a - ${CMAKE_SOURCE_DIR}/lib/libportaudio.a ${CMAKE_SOURCE_DIR}/lib/libsndfile.a ${CMAKE_SOURCE_DIR}/lib/libfftw3f.a) +aux_source_directory(src SOURCE_FILES) +add_executable(glTest ${SOURCE_FILES}) +target_link_libraries(glTest ${OPENGL_LIBRARIES} ${GLFW_LIBRARIES} ${GLEW_LIBRARIES} ${PORTAUDIO_LIBRARIES} ${SNDFILE_LIBRARIES} ${FFTW3F_LIBRARIES}) diff --git a/cmake/Modules/FindGLM.cmake b/cmake/Modules/FindGLM.cmake new file mode 100644 index 0000000..28985f3 --- /dev/null +++ b/cmake/Modules/FindGLM.cmake @@ -0,0 +1,63 @@ +# FindGLM - attempts to locate the glm matrix/vector library. +# +# This module defines the following variables (on success): +# GLM_INCLUDE_DIRS - where to find glm/glm.hpp +# GLM_FOUND - if the library was successfully located +# +# It is trying a few standard installation locations, but can be customized +# with the following variables: +# GLM_ROOT_DIR - root directory of a glm installation +# Headers are expected to be found in either: +# /glm/glm.hpp OR +# /include/glm/glm.hpp +# This variable can either be a cmake or environment +# variable. Note however that changing the value +# of the environment varible will NOT result in +# re-running the header search and therefore NOT +# adjust the variables set by this module. + +#============================================================================= +# Copyright 2012 Carsten Neumann +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# default search dirs +SET(_glm_HEADER_SEARCH_DIRS + "/usr/include" + "/usr/local/include") + +# check environment variable +SET(_glm_ENV_ROOT_DIR "$ENV{GLM_ROOT_DIR}") + +IF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR) + SET(GLM_ROOT_DIR "${_glm_ENV_ROOT_DIR}") +ENDIF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR) + +# put user specified location at beginning of search +IF(GLM_ROOT_DIR) + SET(_glm_HEADER_SEARCH_DIRS "${GLM_ROOT_DIR}" + "${GLM_ROOT_DIR}/include" + ${_glm_HEADER_SEARCH_DIRS}) +ENDIF(GLM_ROOT_DIR) + +# locate header +FIND_PATH(GLM_INCLUDE_DIR "glm/glm.hpp" + PATHS ${_glm_HEADER_SEARCH_DIRS}) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLM DEFAULT_MSG + GLM_INCLUDE_DIR) + +IF(GLM_FOUND) + SET(GLM_INCLUDE_DIRS "${GLM_INCLUDE_DIR}") + + MESSAGE(STATUS "GLM_INCLUDE_DIR = ${GLM_INCLUDE_DIR}") +ENDIF(GLM_FOUND) \ No newline at end of file diff --git a/cmake/Modules/FindPortaudio.cmake b/cmake/Modules/FindPortaudio.cmake new file mode 100644 index 0000000..1893255 --- /dev/null +++ b/cmake/Modules/FindPortaudio.cmake @@ -0,0 +1,106 @@ +# - Try to find Portaudio +# Once done this will define +# +# PORTAUDIO_FOUND - system has Portaudio +# PORTAUDIO_INCLUDE_DIRS - the Portaudio include directory +# PORTAUDIO_LIBRARIES - Link these to use Portaudio +# PORTAUDIO_DEFINITIONS - Compiler switches required for using Portaudio +# PORTAUDIO_VERSION - Portaudio version +# +# Copyright (c) 2006 Andreas Schneider +# +# Redistribution and use is allowed according to the terms of the New BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + + +if (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS) + # in cache already + set(PORTAUDIO_FOUND TRUE) +else (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS) + if (NOT WIN32) + include(FindPkgConfig) + pkg_check_modules(PORTAUDIO2 portaudio-2.0) + endif (NOT WIN32) + + if (PORTAUDIO2_FOUND) + set(PORTAUDIO_INCLUDE_DIRS + ${PORTAUDIO2_INCLUDE_DIRS} + ) + if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(PORTAUDIO_LIBRARIES "${PORTAUDIO2_LIBRARY_DIRS}/lib${PORTAUDIO2_LIBRARIES}.dylib") + else (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(PORTAUDIO_LIBRARIES + ${PORTAUDIO2_LIBRARIES} + ) + endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(PORTAUDIO_VERSION + 19 + ) + set(PORTAUDIO_FOUND TRUE) + else (PORTAUDIO2_FOUND) + find_path(PORTAUDIO_INCLUDE_DIR + NAMES + portaudio.h + PATHS + /usr/include + /usr/local/include + /opt/local/include + /sw/include + ) + + find_library(PORTAUDIO_LIBRARY + NAMES + portaudio + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) + + find_path(PORTAUDIO_LIBRARY_DIR + NAMES + portaudio + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) + + set(PORTAUDIO_INCLUDE_DIRS + ${PORTAUDIO_INCLUDE_DIR} + ) + set(PORTAUDIO_LIBRARIES + ${PORTAUDIO_LIBRARY} + ) + + set(PORTAUDIO_LIBRARY_DIRS + ${PORTAUDIO_LIBRARY_DIR} + ) + + set(PORTAUDIO_VERSION + 19 + ) + + if (PORTAUDIO_INCLUDE_DIRS AND PORTAUDIO_LIBRARIES) + set(PORTAUDIO_FOUND TRUE) + endif (PORTAUDIO_INCLUDE_DIRS AND PORTAUDIO_LIBRARIES) + + if (PORTAUDIO_FOUND) + if (NOT Portaudio_FIND_QUIETLY) + message(STATUS "Found Portaudio: ${PORTAUDIO_LIBRARIES}") + endif (NOT Portaudio_FIND_QUIETLY) + else (PORTAUDIO_FOUND) + if (Portaudio_FIND_REQUIRED) + message(FATAL_ERROR "Could not find Portaudio") + endif (Portaudio_FIND_REQUIRED) + endif (PORTAUDIO_FOUND) + endif (PORTAUDIO2_FOUND) + + + # show the PORTAUDIO_INCLUDE_DIRS and PORTAUDIO_LIBRARIES variables only in the advanced view + mark_as_advanced(PORTAUDIO_INCLUDE_DIRS PORTAUDIO_LIBRARIES) + +endif (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS) diff --git a/src/SpectralMesh.cpp b/src/SpectralMesh.cpp index dc760c4..647b8cd 100644 --- a/src/SpectralMesh.cpp +++ b/src/SpectralMesh.cpp @@ -34,7 +34,7 @@ void SpectralMesh::addLine(float *line) { for(std::size_t i = 0; i < _size; ++i) { float real = _spectrLineComplex[i][0], imag = _spectrLineComplex[i][1]; - _spectrLine[i] = 0.1*log10f(sqrtf(real*real + imag*imag)) + 0.1f; + _spectrLine[i] = 0.3*log10f(sqrtf(real*real + imag*imag)) + 0.1f; if(_spectrLine[i] < 0) { _spectrLine[i] = 0; } diff --git a/src/main.cpp b/src/main.cpp index d8be5cd..923102c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -84,7 +84,7 @@ int main() { glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); - AudioPlayer player("/home/selim/dl/euphoria.wav"); + AudioPlayer player("/Users/selim/Dropbox/euphoria.wav"); player.setStreamListener([&mesh](void* data, std::size_t framesCount){ mesh.addLine((float*)data); });