# HG changeset patch # User Eris Caffee # Date 1427404653 18000 # Node ID d51a735106c2daf4f95ffe92fe7f8c3885ee74c1 # Parent cf38ffea8defb1b3cb9d791abe467ed71b33f7e4 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. diff -r cf38ffea8def -r d51a735106c2 CMakeLists.txt --- a/CMakeLists.txt Wed Mar 25 16:25:10 2015 -0500 +++ b/CMakeLists.txt Thu Mar 26 16:17:33 2015 -0500 @@ -1,85 +1,10 @@ -############################################################################### -# -# A generalized cmake file for developing cross-platform games. -# -# Copyright (C) 2010 Sarah Eris Horsley Caffee -# -# This is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# -# Instructions: -# This cmake file assumes that your source files are laid in out in the -# following manner: -# -# project_dir\ Top level directory of the project. -# |---include\ Header files are here. -# |---src\ Source files are here. -# |---build\ Binaries/objects go here. Run cmake from here. -# !---cmake\ -# | |---modules\ Custom cmake include files, if any, go here. -# |---CMakeLists.txt This file. -# -# You may have more directories, of course, but these are assumed. You probably -# want more than one build directory. I normally have build-linux\ -# and build-windows\ directories. -# -# Set the App_Name variable, below, to the name of your application and you -# are ready to start. Run ccmake, or cmake-gui from within your build -# directory, choose the options you need, such as enabling SDL, and you -# should be good to go. -# -# You can uncomment the "SET (CMAKE_VERBOSE_MAKEFILE ON) command if you -# need to debug the actual makefile that is generated. -# -# On windows, you may need to set the SDLDIR environment variable to the location -# of your SDL installation before you run cmake-gui. -# -# When writing path names on Windows, such as when manually specifiying a -# file or directory name, either use unix-style forward slashes '/' in the -# path names or use double backslashes. If you use a single backslash as the -# path name seperator, then cmake will interpret it as an esacpe sequence. -# Thus, write "C:/source" or "C:\\source" instead of "C:\source". It's -# probably best to use forward slashes in case to ever have a situation -# where cmake needs to do recursive processing: each level of cmake will -# strip out one of the slashes, so if there are two lev3els of cmake you -# need to write \\\, three levels requires \\\\, etc. -# -# Note that some of the cmake support scripts that find libraries for you -# can be controlled by environment variables. For example, you can set the -# SDLDIR environment variable before running cmake in order to point to -# a different version of SDL than your systems default copy. This is useful -# for trying out cutting edge versions of libraries without installing them -# system wide. - cmake_minimum_required (VERSION 2.6 FATAL_ERROR) #set (CMAKE_VERBOSE_MAKEFILE ON) -# Name your program! set (App_Name "libaocpp") -if (App_Name STREQUAL "MYAPPNAME") - message (FATAL_ERROR "You must set the App_Name variable!") -endif () - -# Every project must have a name. project (${App_Name}) -# You may specify an application description, too. This will be passed to -# Doxygen, if you use that. -set (App_Description "") - -################################################################################ -# Special options +set (App_Description "Object Oriented wrapper around libao.") ################################################################################ @@ -127,6 +52,7 @@ ################################################################################ option(Option_Profile_Program "Build for gprof profiling." OFF) + if (Option_Profile_Program) add_definitions(-pg) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") @@ -136,31 +62,35 @@ ################################################################################ # The core project files -file (GLOB SRCS src/*.c src/*.cpp) -file (GLOB HDRS src/*.h src/*.hpp) +set (LIB_SRCS +src/AODriver.cpp +src/AOSystem.cpp +src/AODevice.cpp +src/AOOptions.cpp +src/aopp.hpp +) + +set ( AOPP_SYSTEM_INFO_SRCS +src/aopp_system_info.cpp +) # The directories that contain the libraries we will be linking against. # This must come before the ADD_EXECUTABLE directive. link_directories ( ) +set (TEST_APP_NAME "aopp_system_info") + # Define the executable program file we are creating. We must list all of # the source files. -if (WIN32) - add_executable (${App_Name} WIN32 - ${SRCS} - ${HDRS} - ) -else () - add_executable (${App_Name} - ${SRCS} - ${HDRS} - ) -endif () +add_executable ( ${TEST_APP_NAME} + ${AOPP_SYSTEM_INFO_SRCS} + ${LIB_SRCS} + ) # Although we listed the library directories above, we also need to list the # individual libraries we will be linking against. -target_link_libraries (${App_Name} +target_link_libraries (${TEST_APP_NAME} ) @@ -256,255 +186,6 @@ endif () ################################################################################ -# X11 -# -# Note that the FindX11.cmake package does _not_ include most X extensions -# in the X11_LIBRARIES variable, although it does pick up their header files -# in the X11_INCLUDE_DIR variable. -# -# To link a program with extensions, such as Xrandr, or Xv, you must manually -# update the target_link_libraries to include the appropriate library variable. -# ${X11_Xrandr_LIB} is an example. See the FindX11.cmake file for a complete -# list of availble variables. -# - -option(Option_X11_Dev "Build an X11 Application." OFF) - -if (Option_X11_Dev) - - option(Option_Xrandr "Use Xrandr" OFF) - option(Option_Xinerama "Use Xinerama" OFF) - - - ######################################## - find_package(X11) - if (NOT X11_FOUND) - message (FATAL_ERROR "X11 not found!") - endif () - - include_directories( - ${X11_INCLUDE_DIR} - ${INCLUDE_DIRECTORIES} - ) - - target_link_libraries(${App_Name} - ${X11_LIBRARIES} - ${TARGET_LINK_LIBRARIES} - ) - - ######################################## - if (Option_Xrandr) - if (NOT X11_Xrandr_FOUND) - message (FATAL_ERROR "Xrandr not found!") - endif () - target_link_libraries(${App_Name} - ${X11_Xrandr_LIB} - ${TARGET_LINK_LIBRARIES} - ) - endif () - - ######################################## - if (Option_Xinerama) - if (NOT X11_Xinerama_FOUND) - message (FATAL_ERROR "Xinerama not found!") - endif () - target_link_libraries(${App_Name} - ${X11_Xinerama_LIB} - ${TARGET_LINK_LIBRARIES} - ) - endif () - -endif () - -################################################################################ -# SDL -# -# Enabling SDL support enables several suboptions to make some common SDL -# extension libraries available as well. -# -# If any of the SDL libraries are not found automatically, you will need -# to set the appropriate environment variables and rerun cmake. You will -# need to remove the CMake cache before doing so. - -# If you don't want to set actual environment variables before running -# CMake, then uncomment the if block below and put in the actual -# locations of your SDL installation. - -option(Option_SDL_Dev "Build an SDL application." OFF) - -if (Option_SDL_Dev) - - # # Force SDL 1.3 only - # if (WIN32) - # set (ENV{SDLDIR} "c:/gamedev/deps/sdl/SDL-build") - # else () - # set (ENV{SDLDIR} "/home/eris/gamedev/deps/sdl/SDL-build") - # endif () - # add_definitions(-DSDL_NO_COMPAT) - - # SDL base package - # To use a version of SDL other than your systems default, set the SDLDIR - # environment variable to the installation location of your preferred version. - find_package (SDL) - if (NOT SDL_FOUND) - message (FATAL_ERROR "SDL not found!") - endif (NOT SDL_FOUND) - include_directories( - ${SDL_INCLUDE_DIR} - ${INCLUDE_DIRECTORIES} - ) - target_link_libraries(${App_Name} - ${SDL_LIBRARY} - ${TARGET_LINK_LIBRARIES} - ) - - # SDL_ttf - # Environment variables SDLTTFDIR and SDLDIR will be checked in that order - # and if set cmake will try to find SDL_ttf in the specified directory. - option(Option_SDL_Dev_SDL_ttf "Use SDL_ttf." OFF) - if (Option_SDL_Dev_SDL_ttf) - find_package (SDL_ttf) - if (NOT SDLTTF_FOUND) - message (FATAL_ERROR "SDL_ttf not found!") - endif (NOT SDLTTF_FOUND) - include_directories( - ${SDLTTF_INCLUDE_DIR} - ${INCLUDE_DIRECTORIES} - ) - target_link_libraries(${App_Name} - ${SDLTTF_LIBRARY} - ${TARGET_LINK_LIBRARIES} - ) - endif () - - # SDL_image - # Environment variables SDLIMAGEDIR and SDLDIR will be checked in that order - # and if set cmake will try to find SDL_image in the specified directory. - option(Option_SDL_Dev_SDL_image "Use SDL_image." OFF) - if (Option_SDL_Dev_SDL_image) - find_package (SDL_image) - if (NOT SDLIMAGE_FOUND) - message (FATAL_ERROR "SDL_image not found!") - endif (NOT SDLIMAGE_FOUND) - include_directories( - ${SDLIMAGE_INCLUDE_DIR} - ${INCLUDE_DIRECTORIES} - ) - target_link_libraries(${App_Name} - ${SDLIMAGE_LIBRARY} - ${TARGET_LINK_LIBRARIES} - ) - endif () - - # SDL_mixer - # Environment variables SDLMIXERDIR and SDLDIR will be checked in that order - # and if set cmake will try to find SDL_mixer in the specified directory. - option(Option_SDL_Dev_SDL_mixer "Use SDL_mixer." OFF) - if (Option_SDL_Dev_SDL_mixer) - find_package (SDL_mixer) - if (NOT SDLMIXER_FOUND) - message (FATAL_ERROR "SDL_mixer not found!") - endif (NOT SDLMIXER_FOUND) - include_directories( - ${SDLMIXER_INCLUDE_DIR} - ${INCLUDE_DIRECTORIES} - ) - target_link_libraries(${App_Name} - ${SDLMIXER_LIBRARY} - ${TARGET_LINK_LIBRARIES} - ) - endif () - - # SDL_net - # Environment variables SDLNETDIR and SDLDIR will be checked in that order - # and if set cmake will try to find SDL_net in the specified directory. - option(Option_SDL_Dev_SDL_net "Use SDL_net." OFF) - if (Option_SDL_Dev_SDL_net) - find_package (SDL_net) - if (NOT SDLNET_FOUND) - message (FATAL_ERROR "SDL_net not found!") - endif (NOT SDLNET_FOUND) - include_directories( - ${SDLNET_INCLUDE_DIR} - ${INCLUDE_DIRECTORIES} - ) - target_link_libraries(${App_Name} - ${SDLNET_LIBRARY} - ${TARGET_LINK_LIBRARIES} - ) - endif () - -endif (Option_SDL_Dev) - - -################################################################################ - -option(Option_OpenGL_Dev "Build an OpenGL Application." OFF) - -if (Option_OpenGL_Dev) - - find_package(OpenGL) - if (NOT OPENGL_FOUND) - message (FATAL_ERROR "OpenGL not found!") - endif (NOT OPENGL_FOUND) - - include_directories( - ${OPENGL_INCLUDE_DIR} - ${INCLUDE_DIRECTORIES} - ) - - target_link_libraries(${App_Name} - ${OPENGL_LIBRARIES} - ${TARGET_LINK_LIBRARIES} - ) - - option(Option_GLUT_Dev "Build a GLUT Application." OFF) - - if (Option_GLUT_Dev) - - find_package(GLUT) - if (NOT GLUT_FOUND) - message (FATAL_ERROR "GLUT not found!") - endif() - - include_directories( - ${GLUT_INCLUDE_DIR} - ${INCLUDE_DIRECTORIES} - ) - - target_link_libraries(${App_Name} - ${GLUT_LIBRARIES} - ${TARGET_LINK_LIBRARIES} - ) - - endif() - -endif () - -################################################################################ - -option(Option_OpenAL_Dev "Build an OpenAL Application." OFF) - -if (Option_OpenAL_Dev) - - find_package(OpenAL) - if (NOT OPENAL_FOUND) - message (FATAL_ERROR "OpenAL not found!") - endif (NOT OPENAL_FOUND) - - include_directories( - ${OPENAL_INCLUDE_DIR} - ${INCLUDE_DIRECTORIES} - ) - - target_link_libraries(${App_Name} - ${OPENAL_LIBRARY} - ${TARGET_LINK_LIBRARIES} - ) - -endif () - -################################################################################ option(Option_AO_Dev "Build a libao Application." ON) @@ -519,7 +200,7 @@ ${INCLUDE_DIRECTORIES} ) - target_link_libraries(${App_Name} + target_link_libraries(${TEST_APP_NAME} ${AO_LIBRARY} ${TARGET_LINK_LIBRARIES} ) diff -r cf38ffea8def -r d51a735106c2 src/AOSystem.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/AOSystem.cpp Thu Mar 26 16:17:33 2015 -0500 @@ -0,0 +1,32 @@ +#include "aopp.hpp" + +using namespace AOPP; + +AOSystem::AOSystem() { + ao_initialize(); + } + +AOSystem::~AOSystem() { + ao_shutdown(); + } + +AOInfo ** AOSystem::driver_info_list( int *driver_count ) { + *driver_count = 0; + ao_info **list = NULL; + + list = ao_driver_info_list( driver_count ); + + return static_cast(list); + } + +int AOSystem::default_driver_id( void ) { + return ao_default_driver_id(); + } + +int AOSystem::is_big_endian( void ) { + return ao_is_big_endian(); + } + +int AOSystem::append_global_option( const char *key, const char *value ) { + return append_global_option( key, value ); + } diff -r cf38ffea8def -r d51a735106c2 src/aopp.hpp --- a/src/aopp.hpp Wed Mar 25 16:25:10 2015 -0500 +++ b/src/aopp.hpp Thu Mar 26 16:17:33 2015 -0500 @@ -56,6 +56,20 @@ int driver_id; }; + //////////////////////////////////////////////////////////////////////////// + class AOSystem { + public: + AOSystem(); + ~AOSystem(); + AOInfo ** driver_info_list( int *driver_count ); + int default_driver_id( void ); + int is_big_endian( void ); + int append_global_option( const char *key, const char *value ); + + private: + }; + + } #endif diff -r cf38ffea8def -r d51a735106c2 src/aopp_system_info.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/aopp_system_info.cpp Thu Mar 26 16:17:33 2015 -0500 @@ -0,0 +1,49 @@ +#include + +#include "aopp.hpp" + +using namespace AOPP; + +int main( int argc, char **argv ) { + + AOSystem aosys; + + int driver_count; + AOInfo ** driver_list = aosys.driver_info_list( &driver_count ); + + std::cout << "Endianness: " << ( aosys.is_big_endian() ? "big" : "little" ) << std::endl; + + int default_driver_id = aosys.default_driver_id(); + if ( -1 == default_driver_id ) { + std::cout << "No default driver available." << std::endl; + } + + for (int i=0; i < driver_count; ++i ) { + std::cout << driver_list[i]->short_name << std::endl; + + int driver_id = AODriver::get_driver_id( driver_list[i]->short_name ); + + if ( default_driver_id == driver_id ) { + std::cout << "\tDEFAULT DRIVER" << std::endl; + } + + std::cout << "\tID \t" << driver_id << std::endl; + std::cout << "\tName \t" << driver_list[i]->name << std::endl; + std::cout << "\tType \t" << + ( driver_list[i]->type == AO_TYPE_LIVE ? "live" : + driver_list[i]->type == AO_TYPE_FILE ? "file" : + "unknown" ) + << std::endl; + std::cout << "\tPriority \t" << driver_list[i]->priority << std::endl; + std::cout << "\tPreferred byte format\t" << + ( driver_list[i]->preferred_byte_format == AO_FMT_LITTLE ? "little" : + driver_list[i]->preferred_byte_format == AO_FMT_BIG ? "big" : + "unknown" ) + << std::endl; + std::cout << "\tcomment \t" << driver_list[i]->comment << std::endl; + std::cout << "\toptions" << std::endl; + for ( int j = 0; j < driver_list[i]->option_count; ++j ) { + std::cout << "\t\t" << driver_list[i]->options[j] << std::endl; + } + } + } diff -r cf38ffea8def -r d51a735106c2 src/main.cpp --- a/src/main.cpp Wed Mar 25 16:25:10 2015 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -#include "aopp.hpp" - -int main( int argc, char **argv ) { - AOPP::AOOptions opts; - - opts.append( "a", "1" ); - opts.append( "b", "2" ); - opts.append( "c", "3" ); - - opts.print_options(); - }