add SDLPlayer class

This commit is contained in:
doitux
2007-06-01 21:34:27 +00:00
parent 68a3abdc75
commit e5507dce60
4 changed files with 132 additions and 7 deletions
+6 -2
View File
@@ -13,6 +13,7 @@ INCLUDEPATH += . \
src/engine/network_engine \ src/engine/network_engine \
src/config \ src/config \
src/core/tinyxml \ src/core/tinyxml \
src/sound \
src/gui/qt \ src/gui/qt \
src/gui/qt/connecttoserverdialog \ src/gui/qt/connecttoserverdialog \
src/core \ src/core \
@@ -35,6 +36,7 @@ INCLUDEPATH += . \
DEPENDPATH += . \ DEPENDPATH += . \
src \ src \
src/config \ src/config \
src/sound \
src/core \ src/core \
src/engine \ src/engine \
src/gui \ src/gui \
@@ -133,7 +135,8 @@ HEADERS += src/game.h \
src/gui/qttoolsinterface.h \ src/gui/qttoolsinterface.h \
src/gui/qt/qttools/qttoolswrapper.h \ src/gui/qt/qttools/qttoolswrapper.h \
src/gui/qt/qttools/qthelper/qthelper.h \ src/gui/qt/qttools/qthelper/qthelper.h \
src/gui/generic/serverguiwrapper.h src/gui/generic/serverguiwrapper.h \
src/sound/sdlplayer.h
FORMS += src/gui/qt/mainwindow.ui \ FORMS += src/gui/qt/mainwindow.ui \
src/gui/qt/aboutpokerth.ui \ src/gui/qt/aboutpokerth.ui \
src/gui/qt/connecttoserverdialog.ui \ src/gui/qt/connecttoserverdialog.ui \
@@ -225,7 +228,8 @@ SOURCES += src/game.cpp \
src/gui/qttoolsinterface.cpp \ src/gui/qttoolsinterface.cpp \
src/gui/qt/qttools/qttoolswrapper.cpp \ src/gui/qt/qttools/qttoolswrapper.cpp \
src/gui/qt/qttools/qthelper/qthelper.cpp \ src/gui/qt/qttools/qthelper/qthelper.cpp \
src/gui/generic/serverguiwrapper.cpp src/gui/generic/serverguiwrapper.cpp \
src/sound/sdlplayer.cpp
RESOURCES += src/gui/qt/resources.qrc RESOURCES += src/gui/qt/resources.qrc
TRANSLATIONS = ts/pokerth_de.ts \ TRANSLATIONS = ts/pokerth_de.ts \
ts/pokerth_es.ts \ ts/pokerth_es.ts \
+1 -5
View File
@@ -2647,11 +2647,7 @@ void mainWindowImpl::playSound() {
have it just play once) */ have it just play once) */
Mix_PlayMusic(music, 0); Mix_PlayMusic(music, 0);
} }
/* We want to know when our music has stopped playing so we
can free it up and set 'music' back to NULL. SDL_Mixer
provides us with a callback routine we can use to do
exactly that */
// Mix_HookMusicFinished(mainWindowImpl::musicDone());
} }
+80
View File
@@ -0,0 +1,80 @@
//
// C++ Implementation: sdlplayer
//
// Description:
//
//
// Author: FThauer FHammer <webmaster@pokerth.net>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "sdlplayer.h"
using namespace std;
SDLPlayer::SDLPlayer()
{
initAudio();
}
SDLPlayer::~SDLPlayer()
{
}
void SDLPlayer::initAudio() {
audio_rate = 44100;
audio_format = AUDIO_S16; /* 16-bit stereo */
audio_channels = 2;
audio_buffers = 4096;
music = NULL;
SDL_Init(SDL_INIT_AUDIO);
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
printf("Unable to open audio!\n");
exit(1);
}
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
}
void SDLPlayer::playSound(std::string audioString) {
cout << "play now" << endl;
/* Actually loads up the music */
string oggString = ".ogg";
// music = Mix_LoadMUS( audioString+oggString );
/* This begins playing the music - the first argument is a
pointer to Mix_Music structure, and the second is how many
times you want it to loop (use -1 for infinite, and 0 to
have it just play once) */
Mix_PlayMusic(music, 0);
/* We want to know when our music has stopped playing so we
can free it up and set 'music' back to NULL. SDL_Mixer
provides us with a callback routine we can use to do
exactly that */
// Mix_HookMusicFinished(mainWindowImpl::musicDone());
}
void SDLPlayer::audioDone() {
Mix_HaltMusic();
Mix_FreeMusic(music);
music = NULL;
}
void SDLPlayer::closeAudio() {
Mix_HaltMusic();
Mix_FreeMusic(music);
music = NULL;
Mix_CloseAudio();
SDL_Quit();
}
+45
View File
@@ -0,0 +1,45 @@
//
// C++ Interface: sdlplayer
//
// Description:
//
//
// Author: FThauer FHammer <webmaster@pokerth.net>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef SDLPLAYER_H
#define SDLPLAYER_H
#include <iostream>
#include <string>
#include "SDL/SDL.h"
#include "SDL/SDL_mixer.h"
/**
@author FThauer FHammer <webmaster@pokerth.net>
*/
class SDLPlayer{
public:
SDLPlayer();
~SDLPlayer();
void initAudio();
void playSound(std::string);
void audioDone();
void closeAudio();
private:
int audio_rate;
Uint16 audio_format;
int audio_channels;
int audio_buffers;
Mix_Music *music;
};
#endif