Mercurial > aopp
changeset 10:d51a735106c2
All classes have basic functionality and support the full ao api.
Test driver is now lists available sound drivers.
TODO
- AOSystem needs to be made into a singleton.
- Need more fully fleshed out tests.
- Need Doxygen
- Need to consider more abstraction rather than the 1-1 mapping of api calls to methods.
author | Eris Caffee <discordia@eldalin.com> |
---|---|
date | Thu, 26 Mar 2015 16:17:33 -0500 |
parents | cf38ffea8def |
children | 9f0ed655b46c |
files | CMakeLists.txt src/AOSystem.cpp src/aopp.hpp src/aopp_system_info.cpp src/main.cpp |
diffstat | 5 files changed, 116 insertions(+), 351 deletions(-) [+] |
line diff
1.1 --- a/CMakeLists.txt Wed Mar 25 16:25:10 2015 -0500 1.2 +++ b/CMakeLists.txt Thu Mar 26 16:17:33 2015 -0500 1.3 @@ -1,85 +1,10 @@ 1.4 -############################################################################### 1.5 -# 1.6 -# A generalized cmake file for developing cross-platform games. 1.7 -# 1.8 -# Copyright (C) 2010 Sarah Eris Horsley Caffee 1.9 -# 1.10 -# This is free software: you can redistribute it and/or modify 1.11 -# it under the terms of the GNU General Public License as published by 1.12 -# the Free Software Foundation, either version 3 of the License, or 1.13 -# (at your option) any later version. 1.14 -# 1.15 -# This program is distributed in the hope that it will be useful, 1.16 -# but WITHOUT ANY WARRANTY; without even the implied warranty of 1.17 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.18 -# GNU General Public License for more details. 1.19 -# 1.20 -# You should have received a copy of the GNU General Public License 1.21 -# along with this program. If not, see <http://www.gnu.org/licenses/>. 1.22 -# 1.23 -# 1.24 -# Instructions: 1.25 -# This cmake file assumes that your source files are laid in out in the 1.26 -# following manner: 1.27 -# 1.28 -# project_dir\ Top level directory of the project. 1.29 -# |---include\ Header files are here. 1.30 -# |---src\ Source files are here. 1.31 -# |---build\ Binaries/objects go here. Run cmake from here. 1.32 -# !---cmake\ 1.33 -# | |---modules\ Custom cmake include files, if any, go here. 1.34 -# |---CMakeLists.txt This file. 1.35 -# 1.36 -# You may have more directories, of course, but these are assumed. You probably 1.37 -# want more than one build directory. I normally have build-linux\ 1.38 -# and build-windows\ directories. 1.39 -# 1.40 -# Set the App_Name variable, below, to the name of your application and you 1.41 -# are ready to start. Run ccmake, or cmake-gui from within your build 1.42 -# directory, choose the options you need, such as enabling SDL, and you 1.43 -# should be good to go. 1.44 -# 1.45 -# You can uncomment the "SET (CMAKE_VERBOSE_MAKEFILE ON) command if you 1.46 -# need to debug the actual makefile that is generated. 1.47 -# 1.48 -# On windows, you may need to set the SDLDIR environment variable to the location 1.49 -# of your SDL installation before you run cmake-gui. 1.50 -# 1.51 -# When writing path names on Windows, such as when manually specifiying a 1.52 -# file or directory name, either use unix-style forward slashes '/' in the 1.53 -# path names or use double backslashes. If you use a single backslash as the 1.54 -# path name seperator, then cmake will interpret it as an esacpe sequence. 1.55 -# Thus, write "C:/source" or "C:\\source" instead of "C:\source". It's 1.56 -# probably best to use forward slashes in case to ever have a situation 1.57 -# where cmake needs to do recursive processing: each level of cmake will 1.58 -# strip out one of the slashes, so if there are two lev3els of cmake you 1.59 -# need to write \\\, three levels requires \\\\, etc. 1.60 -# 1.61 -# Note that some of the cmake support scripts that find libraries for you 1.62 -# can be controlled by environment variables. For example, you can set the 1.63 -# SDLDIR environment variable before running cmake in order to point to 1.64 -# a different version of SDL than your systems default copy. This is useful 1.65 -# for trying out cutting edge versions of libraries without installing them 1.66 -# system wide. 1.67 - 1.68 cmake_minimum_required (VERSION 2.6 FATAL_ERROR) 1.69 #set (CMAKE_VERBOSE_MAKEFILE ON) 1.70 1.71 -# Name your program! 1.72 set (App_Name "libaocpp") 1.73 -if (App_Name STREQUAL "MYAPPNAME") 1.74 - message (FATAL_ERROR "You must set the App_Name variable!") 1.75 -endif () 1.76 - 1.77 -# Every project must have a name. 1.78 project (${App_Name}) 1.79 1.80 -# You may specify an application description, too. This will be passed to 1.81 -# Doxygen, if you use that. 1.82 -set (App_Description "") 1.83 - 1.84 -################################################################################ 1.85 -# Special options 1.86 +set (App_Description "Object Oriented wrapper around libao.") 1.87 1.88 1.89 ################################################################################ 1.90 @@ -127,6 +52,7 @@ 1.91 ################################################################################ 1.92 1.93 option(Option_Profile_Program "Build for gprof profiling." OFF) 1.94 + 1.95 if (Option_Profile_Program) 1.96 add_definitions(-pg) 1.97 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") 1.98 @@ -136,31 +62,35 @@ 1.99 ################################################################################ 1.100 # The core project files 1.101 1.102 -file (GLOB SRCS src/*.c src/*.cpp) 1.103 -file (GLOB HDRS src/*.h src/*.hpp) 1.104 +set (LIB_SRCS 1.105 +src/AODriver.cpp 1.106 +src/AOSystem.cpp 1.107 +src/AODevice.cpp 1.108 +src/AOOptions.cpp 1.109 +src/aopp.hpp 1.110 +) 1.111 + 1.112 +set ( AOPP_SYSTEM_INFO_SRCS 1.113 +src/aopp_system_info.cpp 1.114 +) 1.115 1.116 # The directories that contain the libraries we will be linking against. 1.117 # This must come before the ADD_EXECUTABLE directive. 1.118 link_directories ( 1.119 ) 1.120 1.121 +set (TEST_APP_NAME "aopp_system_info") 1.122 + 1.123 # Define the executable program file we are creating. We must list all of 1.124 # the source files. 1.125 -if (WIN32) 1.126 - add_executable (${App_Name} WIN32 1.127 - ${SRCS} 1.128 - ${HDRS} 1.129 - ) 1.130 -else () 1.131 - add_executable (${App_Name} 1.132 - ${SRCS} 1.133 - ${HDRS} 1.134 - ) 1.135 -endif () 1.136 +add_executable ( ${TEST_APP_NAME} 1.137 + ${AOPP_SYSTEM_INFO_SRCS} 1.138 + ${LIB_SRCS} 1.139 + ) 1.140 1.141 # Although we listed the library directories above, we also need to list the 1.142 # individual libraries we will be linking against. 1.143 -target_link_libraries (${App_Name} 1.144 +target_link_libraries (${TEST_APP_NAME} 1.145 ) 1.146 1.147 1.148 @@ -256,255 +186,6 @@ 1.149 endif () 1.150 1.151 ################################################################################ 1.152 -# X11 1.153 -# 1.154 -# Note that the FindX11.cmake package does _not_ include most X extensions 1.155 -# in the X11_LIBRARIES variable, although it does pick up their header files 1.156 -# in the X11_INCLUDE_DIR variable. 1.157 -# 1.158 -# To link a program with extensions, such as Xrandr, or Xv, you must manually 1.159 -# update the target_link_libraries to include the appropriate library variable. 1.160 -# ${X11_Xrandr_LIB} is an example. See the FindX11.cmake file for a complete 1.161 -# list of availble variables. 1.162 -# 1.163 - 1.164 -option(Option_X11_Dev "Build an X11 Application." OFF) 1.165 - 1.166 -if (Option_X11_Dev) 1.167 - 1.168 - option(Option_Xrandr "Use Xrandr" OFF) 1.169 - option(Option_Xinerama "Use Xinerama" OFF) 1.170 - 1.171 - 1.172 - ######################################## 1.173 - find_package(X11) 1.174 - if (NOT X11_FOUND) 1.175 - message (FATAL_ERROR "X11 not found!") 1.176 - endif () 1.177 - 1.178 - include_directories( 1.179 - ${X11_INCLUDE_DIR} 1.180 - ${INCLUDE_DIRECTORIES} 1.181 - ) 1.182 - 1.183 - target_link_libraries(${App_Name} 1.184 - ${X11_LIBRARIES} 1.185 - ${TARGET_LINK_LIBRARIES} 1.186 - ) 1.187 - 1.188 - ######################################## 1.189 - if (Option_Xrandr) 1.190 - if (NOT X11_Xrandr_FOUND) 1.191 - message (FATAL_ERROR "Xrandr not found!") 1.192 - endif () 1.193 - target_link_libraries(${App_Name} 1.194 - ${X11_Xrandr_LIB} 1.195 - ${TARGET_LINK_LIBRARIES} 1.196 - ) 1.197 - endif () 1.198 - 1.199 - ######################################## 1.200 - if (Option_Xinerama) 1.201 - if (NOT X11_Xinerama_FOUND) 1.202 - message (FATAL_ERROR "Xinerama not found!") 1.203 - endif () 1.204 - target_link_libraries(${App_Name} 1.205 - ${X11_Xinerama_LIB} 1.206 - ${TARGET_LINK_LIBRARIES} 1.207 - ) 1.208 - endif () 1.209 - 1.210 -endif () 1.211 - 1.212 -################################################################################ 1.213 -# SDL 1.214 -# 1.215 -# Enabling SDL support enables several suboptions to make some common SDL 1.216 -# extension libraries available as well. 1.217 -# 1.218 -# If any of the SDL libraries are not found automatically, you will need 1.219 -# to set the appropriate environment variables and rerun cmake. You will 1.220 -# need to remove the CMake cache before doing so. 1.221 - 1.222 -# If you don't want to set actual environment variables before running 1.223 -# CMake, then uncomment the if block below and put in the actual 1.224 -# locations of your SDL installation. 1.225 - 1.226 -option(Option_SDL_Dev "Build an SDL application." OFF) 1.227 - 1.228 -if (Option_SDL_Dev) 1.229 - 1.230 - # # Force SDL 1.3 only 1.231 - # if (WIN32) 1.232 - # set (ENV{SDLDIR} "c:/gamedev/deps/sdl/SDL-build") 1.233 - # else () 1.234 - # set (ENV{SDLDIR} "/home/eris/gamedev/deps/sdl/SDL-build") 1.235 - # endif () 1.236 - # add_definitions(-DSDL_NO_COMPAT) 1.237 - 1.238 - # SDL base package 1.239 - # To use a version of SDL other than your systems default, set the SDLDIR 1.240 - # environment variable to the installation location of your preferred version. 1.241 - find_package (SDL) 1.242 - if (NOT SDL_FOUND) 1.243 - message (FATAL_ERROR "SDL not found!") 1.244 - endif (NOT SDL_FOUND) 1.245 - include_directories( 1.246 - ${SDL_INCLUDE_DIR} 1.247 - ${INCLUDE_DIRECTORIES} 1.248 - ) 1.249 - target_link_libraries(${App_Name} 1.250 - ${SDL_LIBRARY} 1.251 - ${TARGET_LINK_LIBRARIES} 1.252 - ) 1.253 - 1.254 - # SDL_ttf 1.255 - # Environment variables SDLTTFDIR and SDLDIR will be checked in that order 1.256 - # and if set cmake will try to find SDL_ttf in the specified directory. 1.257 - option(Option_SDL_Dev_SDL_ttf "Use SDL_ttf." OFF) 1.258 - if (Option_SDL_Dev_SDL_ttf) 1.259 - find_package (SDL_ttf) 1.260 - if (NOT SDLTTF_FOUND) 1.261 - message (FATAL_ERROR "SDL_ttf not found!") 1.262 - endif (NOT SDLTTF_FOUND) 1.263 - include_directories( 1.264 - ${SDLTTF_INCLUDE_DIR} 1.265 - ${INCLUDE_DIRECTORIES} 1.266 - ) 1.267 - target_link_libraries(${App_Name} 1.268 - ${SDLTTF_LIBRARY} 1.269 - ${TARGET_LINK_LIBRARIES} 1.270 - ) 1.271 - endif () 1.272 - 1.273 - # SDL_image 1.274 - # Environment variables SDLIMAGEDIR and SDLDIR will be checked in that order 1.275 - # and if set cmake will try to find SDL_image in the specified directory. 1.276 - option(Option_SDL_Dev_SDL_image "Use SDL_image." OFF) 1.277 - if (Option_SDL_Dev_SDL_image) 1.278 - find_package (SDL_image) 1.279 - if (NOT SDLIMAGE_FOUND) 1.280 - message (FATAL_ERROR "SDL_image not found!") 1.281 - endif (NOT SDLIMAGE_FOUND) 1.282 - include_directories( 1.283 - ${SDLIMAGE_INCLUDE_DIR} 1.284 - ${INCLUDE_DIRECTORIES} 1.285 - ) 1.286 - target_link_libraries(${App_Name} 1.287 - ${SDLIMAGE_LIBRARY} 1.288 - ${TARGET_LINK_LIBRARIES} 1.289 - ) 1.290 - endif () 1.291 - 1.292 - # SDL_mixer 1.293 - # Environment variables SDLMIXERDIR and SDLDIR will be checked in that order 1.294 - # and if set cmake will try to find SDL_mixer in the specified directory. 1.295 - option(Option_SDL_Dev_SDL_mixer "Use SDL_mixer." OFF) 1.296 - if (Option_SDL_Dev_SDL_mixer) 1.297 - find_package (SDL_mixer) 1.298 - if (NOT SDLMIXER_FOUND) 1.299 - message (FATAL_ERROR "SDL_mixer not found!") 1.300 - endif (NOT SDLMIXER_FOUND) 1.301 - include_directories( 1.302 - ${SDLMIXER_INCLUDE_DIR} 1.303 - ${INCLUDE_DIRECTORIES} 1.304 - ) 1.305 - target_link_libraries(${App_Name} 1.306 - ${SDLMIXER_LIBRARY} 1.307 - ${TARGET_LINK_LIBRARIES} 1.308 - ) 1.309 - endif () 1.310 - 1.311 - # SDL_net 1.312 - # Environment variables SDLNETDIR and SDLDIR will be checked in that order 1.313 - # and if set cmake will try to find SDL_net in the specified directory. 1.314 - option(Option_SDL_Dev_SDL_net "Use SDL_net." OFF) 1.315 - if (Option_SDL_Dev_SDL_net) 1.316 - find_package (SDL_net) 1.317 - if (NOT SDLNET_FOUND) 1.318 - message (FATAL_ERROR "SDL_net not found!") 1.319 - endif (NOT SDLNET_FOUND) 1.320 - include_directories( 1.321 - ${SDLNET_INCLUDE_DIR} 1.322 - ${INCLUDE_DIRECTORIES} 1.323 - ) 1.324 - target_link_libraries(${App_Name} 1.325 - ${SDLNET_LIBRARY} 1.326 - ${TARGET_LINK_LIBRARIES} 1.327 - ) 1.328 - endif () 1.329 - 1.330 -endif (Option_SDL_Dev) 1.331 - 1.332 - 1.333 -################################################################################ 1.334 - 1.335 -option(Option_OpenGL_Dev "Build an OpenGL Application." OFF) 1.336 - 1.337 -if (Option_OpenGL_Dev) 1.338 - 1.339 - find_package(OpenGL) 1.340 - if (NOT OPENGL_FOUND) 1.341 - message (FATAL_ERROR "OpenGL not found!") 1.342 - endif (NOT OPENGL_FOUND) 1.343 - 1.344 - include_directories( 1.345 - ${OPENGL_INCLUDE_DIR} 1.346 - ${INCLUDE_DIRECTORIES} 1.347 - ) 1.348 - 1.349 - target_link_libraries(${App_Name} 1.350 - ${OPENGL_LIBRARIES} 1.351 - ${TARGET_LINK_LIBRARIES} 1.352 - ) 1.353 - 1.354 - option(Option_GLUT_Dev "Build a GLUT Application." OFF) 1.355 - 1.356 - if (Option_GLUT_Dev) 1.357 - 1.358 - find_package(GLUT) 1.359 - if (NOT GLUT_FOUND) 1.360 - message (FATAL_ERROR "GLUT not found!") 1.361 - endif() 1.362 - 1.363 - include_directories( 1.364 - ${GLUT_INCLUDE_DIR} 1.365 - ${INCLUDE_DIRECTORIES} 1.366 - ) 1.367 - 1.368 - target_link_libraries(${App_Name} 1.369 - ${GLUT_LIBRARIES} 1.370 - ${TARGET_LINK_LIBRARIES} 1.371 - ) 1.372 - 1.373 - endif() 1.374 - 1.375 -endif () 1.376 - 1.377 -################################################################################ 1.378 - 1.379 -option(Option_OpenAL_Dev "Build an OpenAL Application." OFF) 1.380 - 1.381 -if (Option_OpenAL_Dev) 1.382 - 1.383 - find_package(OpenAL) 1.384 - if (NOT OPENAL_FOUND) 1.385 - message (FATAL_ERROR "OpenAL not found!") 1.386 - endif (NOT OPENAL_FOUND) 1.387 - 1.388 - include_directories( 1.389 - ${OPENAL_INCLUDE_DIR} 1.390 - ${INCLUDE_DIRECTORIES} 1.391 - ) 1.392 - 1.393 - target_link_libraries(${App_Name} 1.394 - ${OPENAL_LIBRARY} 1.395 - ${TARGET_LINK_LIBRARIES} 1.396 - ) 1.397 - 1.398 -endif () 1.399 - 1.400 -################################################################################ 1.401 1.402 option(Option_AO_Dev "Build a libao Application." ON) 1.403 1.404 @@ -519,7 +200,7 @@ 1.405 ${INCLUDE_DIRECTORIES} 1.406 ) 1.407 1.408 - target_link_libraries(${App_Name} 1.409 + target_link_libraries(${TEST_APP_NAME} 1.410 ${AO_LIBRARY} 1.411 ${TARGET_LINK_LIBRARIES} 1.412 )
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/src/AOSystem.cpp Thu Mar 26 16:17:33 2015 -0500 2.3 @@ -0,0 +1,32 @@ 2.4 +#include "aopp.hpp" 2.5 + 2.6 +using namespace AOPP; 2.7 + 2.8 +AOSystem::AOSystem() { 2.9 + ao_initialize(); 2.10 + } 2.11 + 2.12 +AOSystem::~AOSystem() { 2.13 + ao_shutdown(); 2.14 + } 2.15 + 2.16 +AOInfo ** AOSystem::driver_info_list( int *driver_count ) { 2.17 + *driver_count = 0; 2.18 + ao_info **list = NULL; 2.19 + 2.20 + list = ao_driver_info_list( driver_count ); 2.21 + 2.22 + return static_cast<AOInfo **>(list); 2.23 + } 2.24 + 2.25 +int AOSystem::default_driver_id( void ) { 2.26 + return ao_default_driver_id(); 2.27 + } 2.28 + 2.29 +int AOSystem::is_big_endian( void ) { 2.30 + return ao_is_big_endian(); 2.31 + } 2.32 + 2.33 +int AOSystem::append_global_option( const char *key, const char *value ) { 2.34 + return append_global_option( key, value ); 2.35 + }
3.1 --- a/src/aopp.hpp Wed Mar 25 16:25:10 2015 -0500 3.2 +++ b/src/aopp.hpp Thu Mar 26 16:17:33 2015 -0500 3.3 @@ -56,6 +56,20 @@ 3.4 int driver_id; 3.5 }; 3.6 3.7 + //////////////////////////////////////////////////////////////////////////// 3.8 + class AOSystem { 3.9 + public: 3.10 + AOSystem(); 3.11 + ~AOSystem(); 3.12 + AOInfo ** driver_info_list( int *driver_count ); 3.13 + int default_driver_id( void ); 3.14 + int is_big_endian( void ); 3.15 + int append_global_option( const char *key, const char *value ); 3.16 + 3.17 + private: 3.18 + }; 3.19 + 3.20 + 3.21 } 3.22 3.23 #endif
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/src/aopp_system_info.cpp Thu Mar 26 16:17:33 2015 -0500 4.3 @@ -0,0 +1,49 @@ 4.4 +#include <iostream> 4.5 + 4.6 +#include "aopp.hpp" 4.7 + 4.8 +using namespace AOPP; 4.9 + 4.10 +int main( int argc, char **argv ) { 4.11 + 4.12 + AOSystem aosys; 4.13 + 4.14 + int driver_count; 4.15 + AOInfo ** driver_list = aosys.driver_info_list( &driver_count ); 4.16 + 4.17 + std::cout << "Endianness: " << ( aosys.is_big_endian() ? "big" : "little" ) << std::endl; 4.18 + 4.19 + int default_driver_id = aosys.default_driver_id(); 4.20 + if ( -1 == default_driver_id ) { 4.21 + std::cout << "No default driver available." << std::endl; 4.22 + } 4.23 + 4.24 + for (int i=0; i < driver_count; ++i ) { 4.25 + std::cout << driver_list[i]->short_name << std::endl; 4.26 + 4.27 + int driver_id = AODriver::get_driver_id( driver_list[i]->short_name ); 4.28 + 4.29 + if ( default_driver_id == driver_id ) { 4.30 + std::cout << "\tDEFAULT DRIVER" << std::endl; 4.31 + } 4.32 + 4.33 + std::cout << "\tID \t" << driver_id << std::endl; 4.34 + std::cout << "\tName \t" << driver_list[i]->name << std::endl; 4.35 + std::cout << "\tType \t" << 4.36 + ( driver_list[i]->type == AO_TYPE_LIVE ? "live" : 4.37 + driver_list[i]->type == AO_TYPE_FILE ? "file" : 4.38 + "unknown" ) 4.39 + << std::endl; 4.40 + std::cout << "\tPriority \t" << driver_list[i]->priority << std::endl; 4.41 + std::cout << "\tPreferred byte format\t" << 4.42 + ( driver_list[i]->preferred_byte_format == AO_FMT_LITTLE ? "little" : 4.43 + driver_list[i]->preferred_byte_format == AO_FMT_BIG ? "big" : 4.44 + "unknown" ) 4.45 + << std::endl; 4.46 + std::cout << "\tcomment \t" << driver_list[i]->comment << std::endl; 4.47 + std::cout << "\toptions" << std::endl; 4.48 + for ( int j = 0; j < driver_list[i]->option_count; ++j ) { 4.49 + std::cout << "\t\t" << driver_list[i]->options[j] << std::endl; 4.50 + } 4.51 + } 4.52 + }
5.1 --- a/src/main.cpp Wed Mar 25 16:25:10 2015 -0500 5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 5.3 @@ -1,11 +0,0 @@ 5.4 -#include "aopp.hpp" 5.5 - 5.6 -int main( int argc, char **argv ) { 5.7 - AOPP::AOOptions opts; 5.8 - 5.9 - opts.append( "a", "1" ); 5.10 - opts.append( "b", "2" ); 5.11 - opts.append( "c", "3" ); 5.12 - 5.13 - opts.print_options(); 5.14 - }