Skip to content

Commit

Permalink
added ogg and mp3 bg music support with sdlmixer
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalLumberjack committed Nov 25, 2014
1 parent c48f178 commit f149f34
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 13 deletions.
49 changes: 49 additions & 0 deletions CMake/Packages/FindSDL2MIXER.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# this module look for SDL2_Mixer (http://www.libsdl.org) support
# it will define the following values
#
# SDLMIXER_INCLUDE_DIR = where SDL_mixer.h can be found
# SDLMIXER_LIBRARY = the library to link against SDL2_mixer
# SDLMIXER_FOUND = set to 1 if SDL2_mixer is found
#

IF(SDL2_Mixer_INCLUDE_DIRS)

FIND_PATH(SDLMIXER_INCLUDE_DIR SDL2/SDL_mixer.h ${SDL2_Mixer_INCLUDE_DIRS})
FIND_LIBRARY(SDLMIXER_LIBRARY SDL2_mixer ${SDL2_Mixer_LIBRARY_DIRS})

ELSE(SDL2_Mixer_INCLUDE_DIRS)

SET(TRIAL_LIBRARY_PATHS
$ENV{SDL2_MIXER_HOME}/lib
/usr/lib
/usr/local/lib
/sw/lib
)
SET(TRIAL_INCLUDE_PATHS
$ENV{SDL2_MIXER_HOME}/include/SDL2
/usr/include/SDL2
/usr/local/include/SDL2
/sw/include/SDL2
)

FIND_LIBRARY(SDLMIXER_LIBRARY SDL2_mixer ${TRIAL_LIBRARY_PATHS})
FIND_PATH(SDLMIXER_INCLUDE_DIR SDL_mixer.h ${TRIAL_INCLUDE_PATHS})

ENDIF(SDL2_Mixer_INCLUDE_DIRS)

IF(SDLMIXER_INCLUDE_DIR AND SDLMIXER_LIBRARY)
SET(SDLMIXER_FOUND 1 CACHE BOOL "Found SDL2_Mixer library")
ELSE(SDLMIXER_INCLUDE_DIR AND SDLMIXER_LIBRARY)
SET(SDLMIXER_FOUND 0 CACHE BOOL "Not fount SDL2_Mixer library")
ENDIF(SDLMIXER_INCLUDE_DIR AND SDLMIXER_LIBRARY)

MARK_AS_ADVANCED(
SDLMIXER_INCLUDE_DIR
SDLMIXER_LIBRARY
SDLMIXER_FOUND
)

INCLUDE(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDLMIXER REQUIRED_VARS SDLMIXER_INCLUDE_DIR SDLMIXER_LIBRARY)
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ else()
endif()
find_package(Freetype REQUIRED)
find_package(FreeImage REQUIRED)
find_package(SDL2 REQUIRED)
find_package(SDL2MIXER REQUIRED)
find_package(SDL2 REQUIRED)
find_package(Boost REQUIRED COMPONENTS system filesystem date_time)
find_package(Eigen3 REQUIRED)
find_package(CURL REQUIRED)
Expand Down Expand Up @@ -137,6 +138,7 @@ set(COMMON_LIBRARIES
${FREETYPE_LIBRARIES}
${FreeImage_LIBRARIES}
${SDL2_LIBRARY}
${SDLMIXER_LIBRARY}
${CURL_LIBRARIES}
pugixml
nanosvg
Expand Down
4 changes: 2 additions & 2 deletions es-app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ SET(CPACK_RESOURCE_FILE README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Alec Lofquist <[email protected]>")
SET(CPACK_DEBIAN_PACKAGE_SECTION "misc")
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "extra")
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libsdl2-2.0-0, libboost-system1.54.0, libboost-filesystem1.54.0, libfreeimage3, libfreetype6, libcurl3, libasound2")
SET(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS "debhelper (>= 8.0.0), cmake, g++ (>= 4.8), libsdl2-dev, libboost-system-dev, libboost-filesystem-dev, libboost-date-time-dev, libfreeimage-dev, libfreetype6-dev, libeigen3-dev, libcurl4-openssl-dev, libasound2-dev, libgl1-mesa-dev")
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libsdl2-2.0-0, libsdl2-mixer-2.0-0, libboost-system1.54.0, libboost-filesystem1.54.0, libfreeimage3, libfreetype6, libcurl3, libasound2")
SET(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS "debhelper (>= 8.0.0), cmake, g++ (>= 4.8), libsdl2-dev, libsdl2-mixer-dev, libboost-system-dev, libboost-filesystem-dev, libboost-date-time-dev, libfreeimage-dev, libfreetype6-dev, libeigen3-dev, libcurl4-openssl-dev, libasound2-dev, libgl1-mesa-dev")

SET(CPACK_PACKAGE_VENDOR "emulationstation.org")
SET(CPACK_PACKAGE_VERSION "2.0.0~rc1")
Expand Down
9 changes: 6 additions & 3 deletions es-app/src/SystemData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdlib.h>
#include <SDL_joystick.h>
#include "Renderer.h"
#include "AudioManager.h"
#include "Music.h"
#include "VolumeControl.h"
#include "Log.h"
#include "InputManager.h"
Expand Down Expand Up @@ -100,7 +100,9 @@ void SystemData::launchGame(Window* window, FileData* game)
{
LOG(LogInfo) << "Attempting to launch game...";

AudioManager::getInstance()->deinit();
//AudioManager::getInstance()->deinit();
Music::deinit();

VolumeControl::getInstance()->deinit();
window->deinit();

Expand All @@ -126,7 +128,8 @@ void SystemData::launchGame(Window* window, FileData* game)

window->init();
VolumeControl::getInstance()->init();
AudioManager::getInstance()->init();
//AudioManager::getInstance()->init();
Music::resume();
window->normalizeNextUpdate();

//update number of times the game has been launched
Expand Down
17 changes: 15 additions & 2 deletions es-app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//http://www.aloshi.com

#include <SDL.h>
#include <SDL_mixer.h>

#include <iostream>
#include <iomanip>
#include "Renderer.h"
Expand All @@ -10,13 +12,14 @@
#include <boost/filesystem.hpp>
#include "guis/GuiDetectDevice.h"
#include "guis/GuiMsgBox.h"
#include "AudioManager.h"
//#include "AudioManager.h"
#include "platform.h"
#include "Log.h"
#include "Window.h"
#include "EmulationStation.h"
#include "Settings.h"
#include "ScraperCmdLine.h"
#include "Music.h"
#include <sstream>

namespace fs = boost::filesystem;
Expand Down Expand Up @@ -230,7 +233,17 @@ int main(int argc, char* argv[])

int lastTime = SDL_GetTicks();
bool running = true;


// // START SDLMIXER
// if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 ){
// //if (SDL_OpenAudio(&sAudioFormat, NULL) < 0) {
// LOG(LogError) << "SDL AUDIO Error - Unable to open SDL audio: " << SDL_GetError() << std::endl;
// }else {
// LOG(LogInfo) << "SDL AUDIO OK" << std::endl;
// }
Music::init();
//Sound::get("./bg.mp3")->play();

while(running)
{
SDL_Event event;
Expand Down
11 changes: 11 additions & 0 deletions es-app/src/views/SystemView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "SystemData.h"
#include "Settings.h"
#include "Util.h"
#include "ThemeData.h"
#include "Music.h"

#define SELECTED_SCALE 1.5f
#define LOGO_PADDING ((logoSize().x() * (SELECTED_SCALE - 1)/2) + (mSize.x() * 0.06f))
Expand Down Expand Up @@ -84,6 +86,8 @@ void SystemView::populate()

void SystemView::goToSystem(SystemData* system, bool animate)
{


setCursor(system);

if(!animate)
Expand Down Expand Up @@ -138,6 +142,11 @@ void SystemView::update(int deltaTime)

void SystemView::onCursorChanged(const CursorState& state)
{

if(lastSystem != getSelected()){
lastSystem = getSelected();
Music::startMusic(getSelected()->getTheme());
}
// update help style
updateHelpPrompts();

Expand Down Expand Up @@ -247,6 +256,8 @@ void SystemView::onCursorChanged(const CursorState& state)
}

setAnimation(anim, 0, nullptr, false, 0);


}

void SystemView::render(const Eigen::Affine3f& parentTrans)
Expand Down
1 change: 1 addition & 0 deletions es-app/src/views/SystemView.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ class SystemView : public IList<SystemViewData, SystemData*>
float mCamOffset;
float mExtrasCamOffset;
float mExtrasFadeOpacity;
SystemData * lastSystem;
};
10 changes: 8 additions & 2 deletions es-app/src/views/ViewController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include "animations/MoveCameraAnimation.h"
#include "animations/LambdaAnimation.h"

#include "Music.h"


ViewController* ViewController::sInstance = NULL;

ViewController* ViewController::get()
Expand Down Expand Up @@ -60,10 +63,9 @@ void ViewController::goToSystemView(SystemData* system)

auto systemList = getSystemListView();
systemList->setPosition(getSystemId(system) * (float)Renderer::getScreenWidth(), systemList->getPosition().y());

systemList->goToSystem(system, false);
mCurrentView = systemList;

playViewTransition();
}

Expand All @@ -72,6 +74,8 @@ void ViewController::goToNextGameList()
assert(mState.viewing == GAME_LIST);
SystemData* system = getState().getSystem();
assert(system);
Music::startMusic(system->getNext()->getTheme());

goToGameList(system->getNext());
}

Expand All @@ -80,6 +84,8 @@ void ViewController::goToPrevGameList()
assert(mState.viewing == GAME_LIST);
SystemData* system = getState().getSystem();
assert(system);
Music::startMusic(system->getPrev()->getTheme());

goToGameList(system->getPrev());
}

Expand Down
2 changes: 1 addition & 1 deletion es-app/src/views/gamelist/IGameListView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bool IGameListView::input(InputConfig* config, Input input)
// select to open GuiGamelistOptions
if(config->isMappedTo("select", input) && input.value)
{
Sound::getFromTheme(mTheme, getName(), "menuOpen")->play();
//Sound::getFromTheme(mTheme, getName(), "menuOpen")->play();
mWindow->pushGui(new GuiGamelistOptions(mWindow, this->mRoot->getSystem()));
return true;

Expand Down
4 changes: 2 additions & 2 deletions es-app/src/views/gamelist/ISimpleGameListView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
FileData* cursor = getCursor();
if(cursor->getType() == GAME)
{
Sound::getFromTheme(getTheme(), getName(), "launch")->play();
//Sound::getFromTheme(getTheme(), getName(), "launch")->play();
launch(cursor);
}else{
// it's a folder
Expand All @@ -79,7 +79,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
populateList(mCursorStack.top()->getParent()->getChildren());
setCursor(mCursorStack.top());
mCursorStack.pop();
Sound::getFromTheme(getTheme(), getName(), "back")->play();
//Sound::getFromTheme(getTheme(), getName(), "back")->play();
}else{
onFocusLost();
ViewController::get()->goToSystemView(getCursor()->getSystem());
Expand Down
2 changes: 2 additions & 0 deletions es-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(CORE_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/InputConfig.h
${CMAKE_CURRENT_SOURCE_DIR}/src/InputManager.h
${CMAKE_CURRENT_SOURCE_DIR}/src/Log.h
${CMAKE_CURRENT_SOURCE_DIR}/src/Music.h
${CMAKE_CURRENT_SOURCE_DIR}/src/platform.h
${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer.h
${CMAKE_CURRENT_SOURCE_DIR}/src/Settings.h
Expand Down Expand Up @@ -68,6 +69,7 @@ set(CORE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/InputConfig.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/InputManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Log.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Music.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/platform.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer_draw_gl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer_init.cpp
Expand Down
Loading

0 comments on commit f149f34

Please sign in to comment.