Skip to content

Commit

Permalink
celeron55's sound system initial framework
Browse files Browse the repository at this point in the history
  • Loading branch information
celeron55 committed Mar 24, 2012
1 parent 9dd78a8 commit c301e3c
Show file tree
Hide file tree
Showing 12 changed files with 548 additions and 0 deletions.
45 changes: 45 additions & 0 deletions cmake/Modules/FindVorbis.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# - Find vorbis
# Find the native vorbis includes and libraries
#
# VORBIS_INCLUDE_DIR - where to find vorbis.h, etc.
# VORBIS_LIBRARIES - List of libraries when using vorbis(file).
# VORBIS_FOUND - True if vorbis found.

if(NOT GP2XWIZ)
if(VORBIS_INCLUDE_DIR)
# Already in cache, be silent
set(VORBIS_FIND_QUIETLY TRUE)
endif(VORBIS_INCLUDE_DIR)
find_path(OGG_INCLUDE_DIR ogg/ogg.h)
find_path(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h)
# MSVC built ogg/vorbis may be named ogg_static and vorbis_static
find_library(OGG_LIBRARY NAMES ogg ogg_static)
find_library(VORBIS_LIBRARY NAMES vorbis vorbis_static)
find_library(VORBISFILE_LIBRARY NAMES vorbisfile vorbisfile_static)
# Handle the QUIETLY and REQUIRED arguments and set VORBIS_FOUND
# to TRUE if all listed variables are TRUE.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(VORBIS DEFAULT_MSG
OGG_INCLUDE_DIR VORBIS_INCLUDE_DIR
OGG_LIBRARY VORBIS_LIBRARY VORBISFILE_LIBRARY)
else(NOT GP2XWIZ)
find_path(VORBIS_INCLUDE_DIR tremor/ivorbisfile.h)
find_library(VORBIS_LIBRARY NAMES vorbis_dec)
find_package_handle_standard_args(VORBIS DEFAULT_MSG
VORBIS_INCLUDE_DIR VORBIS_LIBRARY)
endif(NOT GP2XWIZ)

if(VORBIS_FOUND)
if(NOT GP2XWIZ)
set(VORBIS_LIBRARIES ${VORBISFILE_LIBRARY} ${VORBIS_LIBRARY}
${OGG_LIBRARY})
else(NOT GP2XWIZ)
set(VORBIS_LIBRARIES ${VORBIS_LIBRARY})
endif(NOT GP2XWIZ)
else(VORBIS_FOUND)
set(VORBIS_LIBRARIES)
endif(VORBIS_FOUND)

mark_as_advanced(OGG_INCLUDE_DIR VORBIS_INCLUDE_DIR)
mark_as_advanced(OGG_LIBRARY VORBIS_LIBRARY VORBISFILE_LIBRARY)

34 changes: 34 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,37 @@ else(GETTEXT_FOUND AND ENABLE_GETTEXT)
message(STATUS "GetText disabled")
endif(GETTEXT_FOUND AND ENABLE_GETTEXT)

# user visible option to enable/disable audio
OPTION(ENABLE_AUDIO "Enable audio" ON)

# this is only set to 1 if audio is enabled _and_ available
set(USE_AUDIO 0)

if(ENABLE_AUDIO)
# Sound libraries
find_package(OpenAL)
if (OPENAL_FOUND)
find_package(Vorbis)
if (VORBIS_FOUND)
set(USE_AUDIO 1)
set(audio_SRCS sound.cpp sound_openal.cpp)
set(AUDIO_INCLUDE_DIRS
${OPENAL_INCLUDE_DIR}
${VORBIS_INCLUDE_DIR}
)
set(AUDIO_LIBRARIES
${OPENAL_LIBRARY}
${VORBIS_LIBRARIES}
)
message(STATUS "Sound enabled")
else(VORBIS_FOUND)
message(FATAL_ERROR "Sound enabled, but Vorbis libraries not found!")
endif(VORBIS_FOUND)
else(OPENAL_FOUND)
message(FATAL_ERROR "Sound enabled, but OpenAL not found!")
endif(OPENAL_FOUND)
endif(ENABLE_AUDIO)

if(NOT MSVC)
set(USE_GPROF 0 CACHE BOOL "Use -pg flag for g++")
endif()
Expand Down Expand Up @@ -159,6 +190,7 @@ endif()
# Client sources
set(minetest_SRCS
${common_SRCS}
${audio_SRCS}
sky.cpp
clientmap.cpp
content_cso.cpp
Expand Down Expand Up @@ -202,6 +234,7 @@ include_directories(
${CMAKE_BUILD_TYPE}
${PNG_INCLUDE_DIR}
${GETTEXT_INCLUDE_DIR}
${AUDIO_INLCUDE_DIR}
${JTHREAD_INCLUDE_DIR}
${SQLITE3_INCLUDE_DIR}
${LUA_INCLUDE_DIR}
Expand All @@ -221,6 +254,7 @@ if(BUILD_CLIENT)
${PNG_LIBRARIES}
${X11_LIBRARIES}
${GETTEXT_LIBRARY}
${AUDIO_LIBRARIES}
${JTHREAD_LIBRARY}
${SQLITE3_LIBRARY}
${LUA_LIBRARY}
Expand Down
5 changes: 5 additions & 0 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "sha1.h"
#include "base64.h"
#include "clientmap.h"
#include "sound.h"

static std::string getTextureCacheDir()
{
Expand Down Expand Up @@ -2323,4 +2324,8 @@ u16 Client::allocateUnknownNodeId(const std::string &name)
assert(0);
return CONTENT_IGNORE;
}
ISoundManager* Client::getSoundManager()
{
return &dummySoundManager;
}

1 change: 1 addition & 0 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
virtual ICraftDefManager* getCraftDefManager();
virtual ITextureSource* getTextureSource();
virtual u16 allocateUnknownNodeId(const std::string &name);
virtual ISoundManager* getSoundManager();

private:

Expand Down
1 change: 1 addition & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "quicktune_shortcutter.h"
#include "clientmap.h"
#include "sky.h"
#include "sound.h"
#include <list>

/*
Expand Down
4 changes: 4 additions & 0 deletions src/gamedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class IItemDefManager;
class INodeDefManager;
class ICraftDefManager;
class ITextureSource;
class ISoundManager;

/*
An interface for fetching game-global definitions like tool and
Expand All @@ -46,6 +47,8 @@ class IGameDef
// pointers in other threads than main thread will make things explode.
virtual ITextureSource* getTextureSource()=0;

virtual ISoundManager* getSoundManager()=0;

// Used for keeping track of names/ids of unknown nodes
virtual u16 allocateUnknownNodeId(const std::string &name)=0;

Expand All @@ -54,6 +57,7 @@ class IGameDef
INodeDefManager* ndef(){return getNodeDefManager();}
ICraftDefManager* cdef(){return getCraftDefManager();}
ITextureSource* tsrc(){return getTextureSource();}
ISoundManager* sound(){return getSoundManager();}
};

#endif
Expand Down
5 changes: 5 additions & 0 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "base64.h"
#include "tool.h"
#include "utility_string.h"
#include "sound.h" // dummySoundManager

#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"

Expand Down Expand Up @@ -4270,6 +4271,10 @@ u16 Server::allocateUnknownNodeId(const std::string &name)
{
return m_nodedef->allocateDummy(name);
}
ISoundManager* Server::getSoundManager()
{
return &dummySoundManager;
}

IWritableItemDefManager* Server::getWritableItemDefManager()
{
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
virtual ICraftDefManager* getCraftDefManager();
virtual ITextureSource* getTextureSource();
virtual u16 allocateUnknownNodeId(const std::string &name);
virtual ISoundManager* getSoundManager();

IWritableItemDefManager* getWritableItemDefManager();
IWritableNodeDefManager* getWritableNodeDefManager();
Expand Down
25 changes: 25 additions & 0 deletions src/sound.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Minetest-c55
Copyright (C) 2012 celeron55, Perttu Ahola <[email protected]>
This program 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 2 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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "sound.h"

// Global DummySoundManager singleton
DummySoundManager dummySoundManager;


77 changes: 77 additions & 0 deletions src/sound.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Minetest-c55
Copyright (C) 2012 celeron55, Perttu Ahola <[email protected]>
This program 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 2 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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef SOUND_HEADER
#define SOUND_HEADER

#include "irrlichttypes.h"
#include <string>
#include <vector>
#include <set>

class OnDemandSoundFetcher
{
public:
virtual void getSoundFilenames(const std::string &name,
std::set<std::string> &dst);
};

class ISoundManager
{
public:
virtual ~ISoundManager(){}

// Multiple sounds can be loaded per name; when played, the sound
// should be chosen randomly from alternatives
// Return value determines success/failure
virtual bool loadSound(const std::string &name,
const std::string &filepath) = 0;
virtual bool loadSound(const std::string &name,
const std::vector<char> &filedata) = 0;

virtual void updateListener(v3f pos, v3f vel, v3f at, v3f up) = 0;
// playSound functions return -1 on failure, otherwise a handle to the
// sound
virtual int playSound(const std::string &name, int loopcount,
float volume) = 0;
virtual int playSoundAt(const std::string &name, int loopcount,
v3f pos, float volume) = 0;
virtual void stopSound(int sound) = 0;
};

class DummySoundManager: public ISoundManager
{
public:
virtual bool loadSound(const std::string &name,
const std::string &filepath) {return true;}
virtual bool loadSound(const std::string &name,
const std::vector<char> &filedata) {return true;}
void updateListener(v3f pos, v3f vel, v3f at, v3f up) {}
int playSound(const std::string &name, int loopcount,
float volume) {return 0;}
int playSoundAt(const std::string &name, int loopcount,
v3f pos, float volume) {return 0;}
void stopSound(int sound) {}
};

// Global DummySoundManager singleton
extern DummySoundManager dummySoundManager;

#endif

Loading

0 comments on commit c301e3c

Please sign in to comment.