Files
pokerth/src/gui/qt/sound/sdlplayer.cpp
T

85 lines
1.7 KiB
C++
Raw Normal View History

2007-06-01 21:34:27 +00:00
//
// C++ Implementation: sdlplayer
//
// Description:
//
//
// Author: FThauer FHammer <webmaster@pokerth.net>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "sdlplayer.h"
#include <iostream>
2007-06-01 21:34:27 +00:00
using namespace std;
2007-06-02 23:23:21 +00:00
SDLPlayer::SDLPlayer():QObject()
2007-06-01 21:34:27 +00:00
{
2007-06-02 23:23:21 +00:00
currentChannel = 0;
2007-06-01 21:34:27 +00:00
initAudio();
}
SDLPlayer::~SDLPlayer()
{
}
void SDLPlayer::initAudio() {
audio_rate = 44100;
2007-06-02 20:02:55 +00:00
audio_format = AUDIO_S16; /* 16-bit stereo */
audio_channels = 2;
audio_buffers = 4096;
2007-06-02 23:23:21 +00:00
sound = NULL;
2007-06-01 21:34:27 +00:00
SDL_Init(SDL_INIT_AUDIO);
2007-06-02 20:02:55 +00:00
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) == 0)
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
2007-06-01 21:34:27 +00:00
}
2007-06-01 22:49:37 +00:00
void SDLPlayer::playSound(string audioString) {
2007-06-03 08:17:33 +00:00
// QFile myFile(":sounds/resources/sounds/"+QString::fromStdString(audioString)+".wav");
// if(myFile.open(QIODevice::ReadOnly)) {
//
// audioDone();
//
// QDataStream in(&myFile);
// Uint8 *myMem = new Uint8[(int)myFile.size()];
// in.readRawData( (char*)myMem, (int)myFile.size() );
//
// sound = Mix_QuickLoad_WAV( myMem );
//
// currentChannel = Mix_PlayChannel(-1, sound,0);
//
// delete[] myMem;
// }
// else cout << "could not load " << audioString << ".wav" << endl;
2007-06-01 21:34:27 +00:00
2007-06-03 08:17:33 +00:00
//test
audioDone();
sound = Mix_LoadWAV( QString(QString::fromStdString(audioString)+QString(".wav")).toStdString().c_str() );
currentChannel = Mix_PlayChannel(-1, sound,0);
2007-06-01 21:34:27 +00:00
}
void SDLPlayer::audioDone() {
2007-06-02 23:23:21 +00:00
Mix_HaltChannel(currentChannel);
Mix_FreeChunk(sound);
sound = NULL;
2007-06-01 21:34:27 +00:00
}
void SDLPlayer::closeAudio() {
2007-06-02 23:23:21 +00:00
Mix_HaltChannel(currentChannel);
Mix_FreeChunk(sound);
sound = NULL;
2007-06-01 21:34:27 +00:00
Mix_CloseAudio();
2007-06-02 20:02:55 +00:00
SDL_Quit();
2007-06-01 21:34:27 +00:00
}