test case for #141

This commit is contained in:
doitux
2012-11-21 23:07:54 +01:00
parent 7a29cc59e2
commit 1159cbdf4d
2 changed files with 100 additions and 100 deletions
+97 -97
View File
@@ -19,9 +19,9 @@
#ifndef ANDROID #ifndef ANDROID
#if (defined __APPLE__) #if (defined __APPLE__)
#include <SDL.h> //#include <SDL.h>
#else #else
#include <SDL/SDL.h> //#include <SDL/SDL.h>
#endif #endif
#endif #endif
@@ -29,11 +29,11 @@ using namespace std;
SDLPlayer::SDLPlayer(ConfigFile *c) SDLPlayer::SDLPlayer(ConfigFile *c)
#ifndef ANDROID #ifndef ANDROID
: sound(NULL), soundData(NULL), currentChannel(0) , audioEnabled(0), myConfig(c) //: sound(NULL), soundData(NULL), currentChannel(0) , audioEnabled(0), myConfig(c)
#endif #endif
{ {
#ifndef ANDROID #ifndef ANDROID
myAppDataPath = QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str()); // myAppDataPath = QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str());
#endif #endif
} }
@@ -41,127 +41,127 @@ SDLPlayer::SDLPlayer(ConfigFile *c)
SDLPlayer::~SDLPlayer() SDLPlayer::~SDLPlayer()
{ {
#ifndef ANDROID #ifndef ANDROID
closeAudio(); // closeAudio();
#endif #endif
} }
void SDLPlayer::initAudio() void SDLPlayer::initAudio()
{ {
#ifndef ANDROID #ifndef ANDROID
SDL_Init(SDL_INIT_AUDIO); // SDL_Init(SDL_INIT_AUDIO);
if (!audioEnabled && myConfig->readConfigInt("PlaySoundEffects")) { // if (!audioEnabled && myConfig->readConfigInt("PlaySoundEffects")) {
int audio_rate = 44100; // int audio_rate = 44100;
Uint16 audio_format = AUDIO_S16; /* 16-bit stereo */ // Uint16 audio_format = AUDIO_S16; /* 16-bit stereo */
int audio_channels = 2; // int audio_channels = 2;
int audio_buffers = 4096; // int audio_buffers = 4096;
sound = NULL; // sound = NULL;
if( Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) == 0) { // if( Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) == 0) {
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels); // Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
audioEnabled = 1; // audioEnabled = 1;
} // }
else { // else {
qDebug() << "Mix_OpenAudio() was not successfull, no sound possible :("; // qDebug() << "Mix_OpenAudio() was not successfull, no sound possible :(";
} // }
} // }
#endif #endif
} }
void SDLPlayer::playSound(string audioString, int playerID) void SDLPlayer::playSound(string audioString, int playerID)
{ {
#ifndef ANDROID #ifndef ANDROID
initAudio(); // initAudio();
if(audioEnabled && myConfig->readConfigInt("PlaySoundEffects")) { // if(audioEnabled && myConfig->readConfigInt("PlaySoundEffects")) {
QFile myFile(myAppDataPath + "sounds/default/" + QString::fromStdString(audioString)+".wav"); // QFile myFile(myAppDataPath + "sounds/default/" + QString::fromStdString(audioString)+".wav");
if(myFile.open(QIODevice::ReadOnly)) { // if(myFile.open(QIODevice::ReadOnly)) {
//set 3d position for player // //set 3d position for player
int position = 0; // int position = 0;
int distance = 0; // int distance = 0;
switch (playerID) { // switch (playerID) {
case 0: { // case 0: {
position = 180; // position = 180;
distance = 10; // distance = 10;
} // }
break; // break;
case 1: { // case 1: {
position = 281; // position = 281;
distance = 50; // distance = 50;
} // }
break; // break;
case 2: { // case 2: {
position = 315; // position = 315;
distance = 120; // distance = 120;
} // }
break; // break;
case 3: { // case 3: {
position = 338; // position = 338;
distance = 160; // distance = 160;
} // }
break; // break;
case 4: { // case 4: {
position = 23; // position = 23;
distance = 160; // distance = 160;
} // }
break; // break;
case 5: { // case 5: {
position = 45; // position = 45;
distance = 120; // distance = 120;
} // }
break; // break;
case 6: { // case 6: {
position = 79; // position = 79;
distance = 50; // distance = 50;
} // }
break; // break;
default: { // default: {
position = 0; // position = 0;
distance = 0; // distance = 0;
} // }
break; // break;
} // }
QDataStream in(&myFile); // QDataStream in(&myFile);
soundData = new Uint8[(int)myFile.size()]; // soundData = new Uint8[(int)myFile.size()];
in.readRawData( (char*)soundData, (int)myFile.size() ); // in.readRawData( (char*)soundData, (int)myFile.size() );
sound = Mix_QuickLoad_WAV(soundData); // sound = Mix_QuickLoad_WAV(soundData);
// set channel 0 to settings volume // // set channel 0 to settings volume
Mix_Volume(-1,myConfig->readConfigInt("SoundVolume")*10); // Mix_Volume(-1,myConfig->readConfigInt("SoundVolume")*10);
// set 3d effect // // set 3d effect
if(!Mix_SetPosition(0, position, distance)) { // if(!Mix_SetPosition(0, position, distance)) {
printf("Mix_SetPosition: %s\n", Mix_GetError()); // printf("Mix_SetPosition: %s\n", Mix_GetError());
// no position effect, is it ok? // // no position effect, is it ok?
} // }
currentChannel = Mix_PlayChannel(-1, sound,0); // currentChannel = Mix_PlayChannel(-1, sound,0);
} // }
//TESTING: release audio after every sound when there is no other sound currently played // //TESTING: release audio after every sound when there is no other sound currently played
if(SDL_GetAudioStatus() != SDL_AUDIO_PLAYING) { // if(SDL_GetAudioStatus() != SDL_AUDIO_PLAYING) {
closeAudio(); // closeAudio();
} // }
} // }
#endif #endif
} }
void SDLPlayer::closeAudio() void SDLPlayer::closeAudio()
{ {
#ifndef ANDROID #ifndef ANDROID
if(audioEnabled) { // if(audioEnabled) {
Mix_HaltChannel(currentChannel); // Mix_HaltChannel(currentChannel);
Mix_FreeChunk(sound); // Mix_FreeChunk(sound);
sound = NULL; // sound = NULL;
delete[] soundData; // delete[] soundData;
soundData = NULL; // soundData = NULL;
Mix_CloseAudio(); // Mix_CloseAudio();
audioEnabled = false; // audioEnabled = false;
} // }
SDL_Quit(); // SDL_Quit();
#endif #endif
} }
+3 -3
View File
@@ -25,9 +25,9 @@
#ifndef ANDROID #ifndef ANDROID
#ifdef __APPLE__ #ifdef __APPLE__
#include <SDL_mixer.h> //#include <SDL_mixer.h>
#else #else
#include <SDL/SDL_mixer.h> //#include <SDL/SDL_mixer.h>
#endif #endif
#endif #endif
@@ -52,7 +52,7 @@ public:
private: private:
#ifndef ANDROID #ifndef ANDROID
Mix_Chunk *sound; // Mix_Chunk *sound;
unsigned char *soundData; unsigned char *soundData;
int currentChannel; int currentChannel;