From 6d49e266dd43e0f5452327d91c68c9433a1754db Mon Sep 17 00:00:00 2001 From: andreja6 Date: Thu, 26 Apr 2018 21:41:07 -0700 Subject: [PATCH] Made AudioPlayer's play and init method static --- AudioPlayer.cpp | 19 ++++++++++++------- AudioPlayer.h | 3 ++- main.cpp | 11 +++++------ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/AudioPlayer.cpp b/AudioPlayer.cpp index c7dc53f..6f4010d 100644 --- a/AudioPlayer.cpp +++ b/AudioPlayer.cpp @@ -5,9 +5,19 @@ #include #include #define NUM_SOUNDS 10 -SDL_AudioSpec fmt; +static SDL_AudioSpec fmt; AudioPlayer::AudioPlayer(void) +{ + +} + +AudioPlayer::~AudioPlayer(void) +{ + SDL_CloseAudio(); +} + +void AudioPlayer::init() { extern void mixaudio(void *unused, Uint8 *stream, int len); fmt.freq = 22050; @@ -25,12 +35,7 @@ AudioPlayer::AudioPlayer(void) SDL_PauseAudio(0); } -AudioPlayer::~AudioPlayer(void) -{ - SDL_CloseAudio(); -} - -struct sample { +static struct sample { Uint8 *data; Uint32 dpos; Uint32 dlen; diff --git a/AudioPlayer.h b/AudioPlayer.h index 2821ff4..772accc 100644 --- a/AudioPlayer.h +++ b/AudioPlayer.h @@ -6,5 +6,6 @@ class AudioPlayer public: AudioPlayer(void); ~AudioPlayer(void); - void PlaySound(std::string); + static void PlaySound(std::string); + static void init(); }; diff --git a/main.cpp b/main.cpp index 3893fcd..3f0270f 100644 --- a/main.cpp +++ b/main.cpp @@ -40,7 +40,6 @@ static int index = 2; static std::string cameraSound = ""; static float TIMERVAL = 60.0F; static int SCOREVAL = 0; -static AudioPlayer soundSystem; static G3D::TextureRef go = NULL; static G3D::TextureRef go_ovr = NULL; static G3D::TextureRef go_dn = NULL; @@ -251,7 +250,7 @@ public: void CameraButtonListener::onButton1MouseClick(BaseButtonInstance* button) { - soundSystem.PlaySound(cameraSound); + AudioPlayer::PlaySound(cameraSound); CoordinateFrame frame = usableApp->debugCamera.getCoordinateFrame(); if(button->name == "CenterCam") centerCam = true; @@ -285,7 +284,7 @@ void DeleteListener::onButton1MouseClick(BaseButtonInstance* button) instances.erase(instances.begin() + i); delete deleting; selectedInstance = NULL; - soundSystem.PlaySound(GetFileInPath("/content/sounds/pageturn.wav")); + AudioPlayer::PlaySound(GetFileInPath("/content/sounds/pageturn.wav")); } @@ -880,13 +879,13 @@ void Demo::onUserInput(UserInput* ui) { if(ui->keyPressed(SDL_MOUSE_WHEEL_UP_KEY)) { - soundSystem.PlaySound(cameraSound); + AudioPlayer::PlaySound(cameraSound); CoordinateFrame frame = app->debugCamera.getCoordinateFrame(); cameraPos = cameraPos + frame.lookVector()*2; } if(ui->keyPressed(SDL_MOUSE_WHEEL_DOWN_KEY)) { - soundSystem.PlaySound(cameraSound); + AudioPlayer::PlaySound(cameraSound); CoordinateFrame frame = app->debugCamera.getCoordinateFrame(); cameraPos = cameraPos - frame.lookVector()*2; } @@ -1469,7 +1468,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) int main(int argc, char** argv) { //_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); //_CrtSetBreakAlloc(1279); - + AudioPlayer::init(); GAppSettings settings; settings.window.resizable = true; //settings.window.fsaaSamples = 8;